diff --git a/driver/js/include/driver/modules/module_register.h b/driver/js/include/driver/modules/module_register.h index 72484b8cae3..7ffa99afc79 100644 --- a/driver/js/include/driver/modules/module_register.h +++ b/driver/js/include/driver/modules/module_register.h @@ -26,13 +26,16 @@ #include "driver/napi/callback_info.h" #include "driver/scope.h" -#define GEN_INVOKE_CB_INTERNAL(Module, Function, Name) \ - static void Name(hippy::napi::CallbackInfo& info, void* data) { \ - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); \ - auto scope = scope_wrapper->scope.lock(); \ - FOOTSTONE_CHECK(scope); \ - auto target = std::static_pointer_cast(scope->GetModuleObject(#Module)); \ - target->Function(info, data); \ + +#define GEN_INVOKE_CB_INTERNAL(Module, Function, Name) \ + static void Name(hippy::napi::CallbackInfo& info, void* data) { \ + std::any slot_any = info.GetSlot(); \ + auto any_pointer = std::any_cast(&slot_any); \ + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); \ + auto scope = scope_wrapper->scope.lock(); \ + FOOTSTONE_CHECK(scope); \ + auto target = std::static_pointer_cast(scope->GetModuleObject(#Module)); \ + target->Function(info, data); \ } #ifndef REGISTER_EXTERNAL_REFERENCES diff --git a/driver/js/include/driver/scope.h b/driver/js/include/driver/scope.h index bfed62e896b..173118441e2 100644 --- a/driver/js/include/driver/scope.h +++ b/driver/js/include/driver/scope.h @@ -336,7 +336,9 @@ class Scope : public std::enable_shared_from_this { template std::shared_ptr DefineClass(const std::shared_ptr>& class_template) { class_template->constructor_wrapper = std::make_unique([](CallbackInfo& info, void* data) { - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); diff --git a/driver/js/src/engine.cc b/driver/js/src/engine.cc index b79528673fe..dd9ee7a193e 100644 --- a/driver/js/src/engine.cc +++ b/driver/js/src/engine.cc @@ -45,9 +45,13 @@ Engine::Engine() Engine::~Engine() { FOOTSTONE_DLOG(INFO) << "~Engine"; for(auto& [key, template_map] : class_template_holder_map_) { - auto animation_template = std::any_cast>>(template_map["Animation"]); + std::any animation_any = template_map["Animation"]; + auto animation_any_pointer = std::any_cast>>(&animation_any); + auto animation_template = static_cast>>(*animation_any_pointer); animation_template->holder_ctx_values.clear(); - auto animation_set_template = std::any_cast>>(template_map["AnimationSet"]); + std::any animation_set_any = template_map["AnimationSet"]; + auto animation_set_any_pointer = std::any_cast>>(&animation_set_any); + auto animation_set_template = static_cast>>(*animation_set_any_pointer); animation_set_template->holder_ctx_values.clear(); } } diff --git a/driver/js/src/js_driver_utils.cc b/driver/js/src/js_driver_utils.cc index 80011ea5e99..2fb4d60a52b 100644 --- a/driver/js/src/js_driver_utils.cc +++ b/driver/js/src/js_driver_utils.cc @@ -551,7 +551,9 @@ void JsDriverUtils::CallNative(hippy::napi::CallbackInfo& info, const std::funct bool, byte_string)>& callback) { FOOTSTONE_DLOG(INFO) << "CallHost"; - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); diff --git a/driver/js/src/modules/animation_frame_module.cc b/driver/js/src/modules/animation_frame_module.cc index 8f92b82144e..4c6baa390d4 100644 --- a/driver/js/src/modules/animation_frame_module.cc +++ b/driver/js/src/modules/animation_frame_module.cc @@ -45,7 +45,9 @@ GEN_INVOKE_CB(AnimationFrameModule, RequestAnimationFrame) // NOLINT(cert-err58- GEN_INVOKE_CB(AnimationFrameModule, CancelAnimationFrame) // NOLINT(cert-err58-cpp) void AnimationFrameModule::RequestAnimationFrame(hippy::napi::CallbackInfo &info, void* data) { // NOLINT(readability-convert-member-functions-to-static) - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); @@ -96,7 +98,9 @@ void AnimationFrameModule::RequestAnimationFrame(hippy::napi::CallbackInfo &info } void AnimationFrameModule::CancelAnimationFrame(hippy::napi::CallbackInfo &info, void* data) { // NOLINT(readability-convert-member-functions-to-static) - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); diff --git a/driver/js/src/modules/animation_module.cc b/driver/js/src/modules/animation_module.cc index 9c26a60f154..88ae50f9e23 100644 --- a/driver/js/src/modules/animation_module.cc +++ b/driver/js/src/modules/animation_module.cc @@ -554,7 +554,9 @@ RegisterAnimation(const std::weak_ptr& weak_scope) { }; animation->AddEventListener(StringViewUtils::ToStdString(StringViewUtils::ConvertEncoding( event_name, string_view::Encoding::Utf8).utf8_value()), std::move(cb)); - auto class_template_ptr = std::any_cast>>(scope->GetClassTemplate("Animation")); + std::any animation_any = scope->GetClassTemplate("Animation"); + auto any_pointer = std::any_cast>>(&animation_any); + auto class_template_ptr = static_cast>>(*any_pointer); class_template_ptr->holder_ctx_values.emplace_back(func); return nullptr; }; @@ -835,7 +837,9 @@ RegisterAnimationSet(const std::weak_ptr& weak_scope) { }; animation_set->AddEventListener(StringViewUtils::ToStdString(StringViewUtils::ConvertEncoding( event_name, string_view::Encoding::Utf8).utf8_value()), std::move(cb)); - auto class_template_ptr = std::any_cast>>(scope->GetClassTemplate("AnimationSet")); + std::any animation_set_any = scope->GetClassTemplate("AnimationSet"); + auto any_pointer = std::any_cast>>(&animation_set_any); + auto class_template_ptr = static_cast>>(*any_pointer); class_template_ptr->holder_ctx_values.emplace_back(func); return nullptr; }; diff --git a/driver/js/src/modules/console_module.cc b/driver/js/src/modules/console_module.cc index f406831a57a..05bea98c4ad 100644 --- a/driver/js/src/modules/console_module.cc +++ b/driver/js/src/modules/console_module.cc @@ -63,7 +63,9 @@ inline namespace module { GEN_INVOKE_CB(ConsoleModule, Log) // NOLINT(cert-err58-cpp) void ConsoleModule::Log(hippy::napi::CallbackInfo &info, void* data) { // NOLINT(readability-convert-member-functions-to-static) - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); diff --git a/driver/js/src/modules/contextify_module.cc b/driver/js/src/modules/contextify_module.cc index 6ba8f4408fa..c51fa3e7ad4 100644 --- a/driver/js/src/modules/contextify_module.cc +++ b/driver/js/src/modules/contextify_module.cc @@ -67,7 +67,9 @@ GEN_INVOKE_CB(ContextifyModule, RunInThisContext) // NOLINT(cert-err58-cpp) GEN_INVOKE_CB(ContextifyModule, LoadUntrustedContent) // NOLINT(cert-err58-cpp) void ContextifyModule::RunInThisContext(hippy::napi::CallbackInfo& info, void* data) { // NOLINT(readability-convert-member-functions-to-static) - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); #ifdef JS_V8 @@ -118,7 +120,9 @@ void ContextifyModule::RunInThisContext(hippy::napi::CallbackInfo& info, void* d void ContextifyModule::RemoveCBFunc(const string_view& uri) { cb_func_map_.erase(uri); } void ContextifyModule::LoadUntrustedContent(CallbackInfo& info, void* data) { - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); diff --git a/driver/js/src/modules/event_module.cc b/driver/js/src/modules/event_module.cc index 7ccf2aea6e6..6534c4cfc2f 100644 --- a/driver/js/src/modules/event_module.cc +++ b/driver/js/src/modules/event_module.cc @@ -61,7 +61,9 @@ std::shared_ptr> MakeEventClassTemplate( if (!scope) { return nullptr; } - auto current_event =std::any_cast>(scope->GetCurrentEvent()); + std::any event_any = scope->GetCurrentEvent(); + auto any_pointer = std::any_cast>(&event_any); + auto current_event = static_cast>(*any_pointer); return current_event; }; diff --git a/driver/js/src/modules/performance/performance_mark_module.cc b/driver/js/src/modules/performance/performance_mark_module.cc index 0b41c9fe377..4c0dbd7b4ea 100644 --- a/driver/js/src/modules/performance/performance_mark_module.cc +++ b/driver/js/src/modules/performance/performance_mark_module.cc @@ -88,7 +88,9 @@ std::shared_ptr> RegisterPerformanceMark(const st if (!detail.has_value()) { return context->CreateNull(); } - return std::any_cast>(detail); + auto any_pointer = std::any_cast>(&detail); + auto detail_ctx = static_cast>(*any_pointer); + return detail_ctx; }; class_template.properties.push_back(std::move(name_property_define)); diff --git a/driver/js/src/modules/performance/performance_measure_module.cc b/driver/js/src/modules/performance/performance_measure_module.cc index 1d7293a2271..8ffe9a57de4 100644 --- a/driver/js/src/modules/performance/performance_measure_module.cc +++ b/driver/js/src/modules/performance/performance_measure_module.cc @@ -85,7 +85,9 @@ std::shared_ptr> RegisterPerformanceMeasure(co if (!detail.has_value()) { return context->CreateNull(); } - return std::any_cast>(detail); + auto any_pointer = std::any_cast>(&detail); + auto detail_ctx = static_cast>(*any_pointer); + return detail_ctx; }; class_template.properties.push_back(std::move(name_property_define)); diff --git a/driver/js/src/modules/timer_module.cc b/driver/js/src/modules/timer_module.cc index 771fe2b737e..025dc694797 100644 --- a/driver/js/src/modules/timer_module.cc +++ b/driver/js/src/modules/timer_module.cc @@ -82,7 +82,9 @@ void TimerModule::SetInterval(CallbackInfo& info, void* data) { } void TimerModule::ClearInterval(CallbackInfo& info, void* data) { - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); @@ -100,7 +102,9 @@ void TimerModule::ClearInterval(CallbackInfo& info, void* data) { } void TimerModule::RequestIdleCallback(CallbackInfo& info, void* data) { - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); @@ -173,10 +177,10 @@ void TimerModule::CancelIdleCallback(CallbackInfo& info, void* data) { } -std::shared_ptr TimerModule::Start( - CallbackInfo& info, - bool repeat) { - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); +std::shared_ptr TimerModule::Start(CallbackInfo& info, bool repeat) { + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); diff --git a/driver/js/src/modules/ui_manager_module.cc b/driver/js/src/modules/ui_manager_module.cc index 5b98f742464..f1973738ae4 100644 --- a/driver/js/src/modules/ui_manager_module.cc +++ b/driver/js/src/modules/ui_manager_module.cc @@ -49,7 +49,9 @@ inline namespace module { GEN_INVOKE_CB(UIManagerModule, CallUIFunction) void UIManagerModule::CallUIFunction(CallbackInfo& info, void* data) { - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); diff --git a/driver/js/src/napi/hermes/hermes_ctx.cc b/driver/js/src/napi/hermes/hermes_ctx.cc index 28fe2e66cab..22596a901d1 100644 --- a/driver/js/src/napi/hermes/hermes_ctx.cc +++ b/driver/js/src/napi/hermes/hermes_ctx.cc @@ -93,7 +93,8 @@ static Value InvokePropertyCallback(Runtime& runtime, const Value& this_value, c if (!global_native_state->Get(kScopeWrapperIndex, scope_any)) { return facebook::jsi::Value::undefined(); } - auto scope_wrapper = reinterpret_cast(std::any_cast(scope_any)); + auto any_pointer = std::any_cast(&scope_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); if (scope == nullptr) return facebook::jsi::Value::undefined(); auto hermes_ctx = std::static_pointer_cast(scope->GetContext()); @@ -127,7 +128,8 @@ static Value InvokeConstructorJsCallback(Runtime& runtime, const Value& this_val if (!global_native_state->Get(kScopeWrapperIndex, scope_any)) { return Value::undefined(); } - auto scope_wrapper = reinterpret_cast(std::any_cast(scope_any)); + auto any_pointer = std::any_cast(&scope_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); if (scope == nullptr) return facebook::jsi::Value::undefined(); auto hermes_ctx = std::static_pointer_cast(scope->GetContext()); @@ -204,7 +206,8 @@ static Value InvokeJsCallback(Runtime& runtime, const Value& this_value, const V if (!global_native_state->Get(kScopeWrapperIndex, scope_any)) { return Value::undefined(); } - auto scope_wrapper = reinterpret_cast(std::any_cast(scope_any)); + auto any_pointer = std::any_cast(&scope_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); if (scope == nullptr) return facebook::jsi::Value::undefined(); auto hermes_ctx = std::static_pointer_cast(scope->GetContext()); diff --git a/driver/js/src/scope.cc b/driver/js/src/scope.cc index 41e161c8019..c608971d67f 100644 --- a/driver/js/src/scope.cc +++ b/driver/js/src/scope.cc @@ -97,7 +97,9 @@ inline namespace driver { static void InternalBindingCallback(hippy::napi::CallbackInfo& info, void* data) { - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto context = scope->GetContext(); diff --git a/framework/ios/base/executors/HippyJSExecutor.mm b/framework/ios/base/executors/HippyJSExecutor.mm index 16bf2075ca4..ea1ca58ef2e 100644 --- a/framework/ios/base/executors/HippyJSExecutor.mm +++ b/framework/ios/base/executors/HippyJSExecutor.mm @@ -310,7 +310,9 @@ - (SharedCtxValuePtr)JSTurboObjectWithName:(NSString *)name { for (size_t i = 0; i < info.Length(); ++i) { argv.push_back(info[i]); } - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto turbo_wrapper = reinterpret_cast(data); @@ -320,7 +322,9 @@ - (SharedCtxValuePtr)JSTurboObjectWithName:(NSString *)name { info.GetReturnValue()->Set(result); }, turbo_wrapper.get()); [turbo saveTurboWrapper:name turbo:std::move(turbo_wrapper)]; - auto scope_wrapper = reinterpret_cast(std::any_cast(info.GetSlot())); + std::any slot_any = info.GetSlot(); + auto any_pointer = std::any_cast(&slot_any); + auto scope_wrapper = reinterpret_cast(static_cast(*any_pointer)); auto scope = scope_wrapper->scope.lock(); FOOTSTONE_CHECK(scope); auto func = scope->GetContext()->CreateFunction(func_wrapper);