diff --git a/driver/js/include/driver/scope.h b/driver/js/include/driver/scope.h index fb67ae06533..e967390c497 100644 --- a/driver/js/include/driver/scope.h +++ b/driver/js/include/driver/scope.h @@ -353,14 +353,14 @@ class Scope : public std::enable_shared_from_this { auto class_template = reinterpret_cast*>(data); auto len = info.Length(); - std::shared_ptr argv[len]; + std::vector> argv(len); for (size_t i = 0; i < len; i++) { argv[i] = info[i]; } auto receiver = info.GetReceiver(); auto external = info.GetData(); std::shared_ptr exception = nullptr; - auto ret = class_template->constructor(receiver, static_cast(len), argv, external, exception); + auto ret = class_template->constructor(receiver, static_cast(len), argv.data(), external, exception); if (exception) { info.GetExceptionValue()->Set(exception); return; @@ -430,7 +430,7 @@ class Scope : public std::enable_shared_from_this { auto function = std::make_unique([](CallbackInfo& info, void* data) { auto function_define = reinterpret_cast*>(data); auto len = info.Length(); - std::shared_ptr param[len]; + std::vector> param(len); for (size_t i = 0; i < len; i++) { param[i] = info[i]; } @@ -440,7 +440,7 @@ class Scope : public std::enable_shared_from_this { } auto t = reinterpret_cast(info_data); std::shared_ptr exception = nullptr; - auto ret = (function_define->callback)(t, static_cast(len), param, exception); + auto ret = (function_define->callback)(t, static_cast(len), param.data(), exception); if (exception) { info.GetReturnValue()->Set(exception); return; diff --git a/driver/js/src/base/js_convert_utils.cc b/driver/js/src/base/js_convert_utils.cc index 9235d68375c..40fbc92e6f5 100644 --- a/driver/js/src/base/js_convert_utils.cc +++ b/driver/js/src/base/js_convert_utils.cc @@ -205,11 +205,11 @@ std::shared_ptr CreateCtxValue(const std::shared_ptr& ctx, } else if (value->IsArray()) { auto array = value->ToArrayChecked(); auto len = array.size(); - std::shared_ptr argv[len]; + std::vector> argv(len); for (size_t i = 0; i < len; ++i) { argv[i] = CreateCtxValue(ctx, std::make_shared(array[i])); } - return ctx->CreateArray(array.size(), argv); + return ctx->CreateArray(array.size(), argv.data()); } else if (value->IsObject()) { auto obj = ctx->CreateObject(); auto object = value->ToObjectChecked(); diff --git a/driver/js/src/modules/performance/performance_module.cc b/driver/js/src/modules/performance/performance_module.cc index c86e05761c0..0dd432d2f0c 100644 --- a/driver/js/src/modules/performance/performance_module.cc +++ b/driver/js/src/modules/performance/performance_module.cc @@ -255,7 +255,7 @@ std::shared_ptr> RegisterPerformance(const std::weak_ } if (argument_count == 1) { auto entries = performance->GetEntriesByName(name); - std::shared_ptr instances[entries.size()]; + std::vector> instances(entries.size()); for (size_t i = 0; i < entries.size(); ++i) { auto entry = entries[i]; auto javascript_class = scope->GetJavascriptClass(PerformanceEntry::GetSubTypeString(entry->GetSubType())); @@ -263,7 +263,7 @@ std::shared_ptr> RegisterPerformance(const std::weak_ context->CreateNumber(static_cast(entry->GetType())) }; instances[i] = context->NewInstance(javascript_class, 2, argv, entry.get()); } - return context->CreateArray(entries.size(), instances); + return context->CreateArray(entries.size(), instances.data()); } string_view type; flag = context->GetValueString(arguments[1], &type); @@ -277,7 +277,7 @@ std::shared_ptr> RegisterPerformance(const std::weak_ return nullptr; } auto entries = performance->GetEntriesByName(name, entry_type); - std::shared_ptr instances[entries.size()]; + std::vector> instances(entries.size()); for (size_t i = 0; i < entries.size(); ++i) { auto entry = entries[i]; auto javascript_class = scope->GetJavascriptClass(PerformanceEntry::GetSubTypeString(entry->GetSubType())); @@ -285,7 +285,7 @@ std::shared_ptr> RegisterPerformance(const std::weak_ context->CreateNumber(static_cast(entry->GetType())) }; instances[i] = context->NewInstance(javascript_class, 2, argv, entry.get()); } - return context->CreateArray(entries.size(), instances); + return context->CreateArray(entries.size(), instances.data()); }; class_template.functions.emplace_back(std::move(get_entries_by_name_function_define)); @@ -317,7 +317,7 @@ std::shared_ptr> RegisterPerformance(const std::weak_ return nullptr; } auto entries = performance->GetEntriesByType(entry_type); - std::shared_ptr instances[entries.size()]; + std::vector> instances(entries.size()); for (size_t i = 0; i < entries.size(); ++i) { auto entry = entries[i]; auto javascript_class = scope->GetJavascriptClass(PerformanceEntry::GetSubTypeString(entry->GetSubType())); @@ -325,7 +325,7 @@ std::shared_ptr> RegisterPerformance(const std::weak_ context->CreateNumber(static_cast(entry->GetType())) }; instances[i] = context->NewInstance(javascript_class, 2, argv, entry.get()); } - return context->CreateArray(entries.size(), instances); + return context->CreateArray(entries.size(), instances.data()); }; class_template.functions.emplace_back(std::move(get_entries_by_type_function_define)); @@ -390,7 +390,7 @@ std::shared_ptr> RegisterPerformance(const std::weak_ } auto context = scope->GetContext(); auto entries = performance->GetEntries(); - std::shared_ptr instances[entries.size()]; + std::vector> instances(entries.size()); for (size_t i = 0; i < entries.size(); ++i) { auto entry = entries[i]; auto javascript_class = scope->GetJavascriptClass(PerformanceEntry::GetSubTypeString(entry->GetSubType())); @@ -398,7 +398,7 @@ std::shared_ptr> RegisterPerformance(const std::weak_ context->CreateNumber(static_cast(entry->GetType())) }; instances[i] = context->NewInstance(javascript_class, 2, argv, entry.get()); } - return context->CreateArray(entries.size(), instances); + return context->CreateArray(entries.size(), instances.data()); }; class_template.functions.emplace_back(std::move(get_entries_function_define)); diff --git a/driver/js/src/modules/performance/performance_navigation_timing_module.cc b/driver/js/src/modules/performance/performance_navigation_timing_module.cc index 5b5cade5cb1..71e18ff3008 100644 --- a/driver/js/src/modules/performance/performance_navigation_timing_module.cc +++ b/driver/js/src/modules/performance/performance_navigation_timing_module.cc @@ -112,7 +112,7 @@ std::shared_ptr> RegisterPerformanceN } auto context = scope->GetContext(); auto bundle_info_array = thiz->GetBundleInfoArray(); - std::shared_ptr array[bundle_info_array.size()]; + std::vector> array(bundle_info_array.size()); for (size_t i = 0; i < bundle_info_array.size(); ++i) { auto& info = bundle_info_array[i]; auto object = context->CreateObject(); @@ -124,7 +124,7 @@ std::shared_ptr> RegisterPerformanceN context->CreateNumber(info.execute_source_end_.ToEpochDelta().ToMillisecondsF())); array[i] = object; } - return context->CreateArray(bundle_info_array.size(), array); + return context->CreateArray(bundle_info_array.size(), array.data()); }; class_template.properties.push_back(std::move(bundle_info)); diff --git a/driver/js/src/scope.cc b/driver/js/src/scope.cc index 084187de472..db0a3ed014b 100644 --- a/driver/js/src/scope.cc +++ b/driver/js/src/scope.cc @@ -111,11 +111,11 @@ static void InternalBindingCallback(hippy::napi::CallbackInfo& info, void* data) } auto len = info.Length(); auto argc = len > 1 ? (len - 1) : 0; - std::shared_ptr rest_args[argc]; + std::vector> rest_args(argc); for (size_t i = 0; i < argc; ++i) { rest_args[i] = info[i + 1]; } - auto js_object = module_object->BindFunction(scope, rest_args); + auto js_object = module_object->BindFunction(scope, rest_args.data()); info.GetReturnValue()->Set(js_object); } diff --git a/framework/ios/base/executors/HippyJSExecutor.mm b/framework/ios/base/executors/HippyJSExecutor.mm index ccc97a60707..01e9b020fbd 100644 --- a/framework/ios/base/executors/HippyJSExecutor.mm +++ b/framework/ios/base/executors/HippyJSExecutor.mm @@ -568,13 +568,13 @@ - (void)_executeJSCall:(NSString *)method SharedCtxValuePtr method_value = context->GetProperty(batchedbridge_value, methodName); if (method_value) { if (context->IsFunction(method_value)) { - SharedCtxValuePtr function_params[arguments.count]; + std::vector function_params(arguments.count); for (NSUInteger i = 0; i < arguments.count; i++) { id obj = arguments[i]; function_params[i] = [obj convertToCtxValue:context]; } auto tryCatch = hippy::CreateTryCatchScope(true, context); - resultValue = context->CallFunction(method_value, context->GetGlobalObject(), arguments.count, function_params); + resultValue = context->CallFunction(method_value, context->GetGlobalObject(), arguments.count, function_params.data()); if (tryCatch->HasCaught()) { exception = tryCatch->GetExceptionMessage(); } diff --git a/framework/ios/module/turbo/HippyOCTurboModule.mm b/framework/ios/module/turbo/HippyOCTurboModule.mm index 84077e48ee5..fbe610798d0 100644 --- a/framework/ios/module/turbo/HippyOCTurboModule.mm +++ b/framework/ios/module/turbo/HippyOCTurboModule.mm @@ -187,11 +187,11 @@ - (id)invokeObjCMethodWithName:(NSString *)methodName } size_t size = static_cast(array.count); - std::shared_ptr buffer[size]; + std::vector> buffer(size); for (size_t idx = 0; idx < array.count; idx++) { buffer[idx] = convertObjcObjectToCtxValue(context, array[idx], module); } - return context->CreateArray(size, buffer); + return context->CreateArray(size, buffer.data()); } static std::shared_ptr convertNSObjectToCtxValue(const std::shared_ptr &context,