From d15981e0f5c46a6005acb16fe2b2ce5571a9e76a Mon Sep 17 00:00:00 2001 From: wwwcg Date: Thu, 10 Oct 2024 15:47:15 +0800 Subject: [PATCH] fix(ios): add nullptr exception protection in rare scenarios --- framework/ios/base/executors/HippyJSExecutor.mm | 13 ++++++++----- renderer/native/ios/renderer/HippyUIManager.mm | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/framework/ios/base/executors/HippyJSExecutor.mm b/framework/ios/base/executors/HippyJSExecutor.mm index 2bc0ab487f7..46c787d4cf3 100644 --- a/framework/ios/base/executors/HippyJSExecutor.mm +++ b/framework/ios/base/executors/HippyJSExecutor.mm @@ -661,7 +661,7 @@ - (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block { return; } } - std::shared_ptr engineRsc = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]; + auto engineRsc = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]; if (!engineRsc) { return; } @@ -670,8 +670,8 @@ - (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block { auto runner = engine->GetJsTaskRunner(); if (footstone::Worker::IsTaskRunning() && runner == footstone::runner::TaskRunner::GetCurrentTaskRunner()) { block(); - } else { - engine->GetJsTaskRunner()->PostTask(block); + } else if (runner) { + runner->PostTask(block); } } } @@ -683,13 +683,16 @@ - (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block { return; } } - std::shared_ptr engineRsc = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]; + auto engineRsc = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]; if (!engineRsc) { return; } auto engine = engineRsc->GetEngine(); if (engine) { - engine->GetJsTaskRunner()->PostTask(block); + auto runner = engine->GetJsTaskRunner(); + if (runner) { + runner->PostTask(block); + } } } diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 5cfd1b514aa..b6750e43e87 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -1173,7 +1173,7 @@ - (void)addEventName:(const std::string &)name if (!bridge) { return; } - [bridge.javaScriptExecutor executeBlockOnJavaScriptQueue:^{ + [bridge.javaScriptExecutor executeAsyncBlockOnJavaScriptQueue:^{ auto strongNode = weakNode.lock(); if (strongNode) { strongNode->HandleEvent(event);