From 9eae669b5ad2fe378efe76af064b05ceb7e4ac7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=A0=91=E5=B1=B1?= Date: Fri, 12 Sep 2025 10:59:35 +0800 Subject: [PATCH] =?UTF-8?q?scope=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=88=A4=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈树山 --- .../window_napi/js_window_listener.cpp | 12 ++++++++++-- .../napi/scene_session_manager/js_scene_utils.cpp | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index a0cfa068a2..70c3f344f2 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -196,7 +196,11 @@ void JsWindowListener::LifeCycleCallBack(LifeCycleEventType eventType) return; } napi_handle_scope scope = nullptr; - napi_open_handle_scope(eng, &scope); + napi_status status = napi_open_handle_scope(eng, &scope); + if (status != napi_ok || scope == nullptr) { + TLOGNE(WmsLogTag::WMS_LIFE, "open handle scope failed."); + return; + } napi_value argv[] = {CreateJsValue(eng, static_cast(eventType))}; thisListener->CallJsMethod(LIFECYCLE_EVENT_CB.c_str(), argv, ArraySize(argv)); napi_close_handle_scope(eng, scope); @@ -220,7 +224,11 @@ void JsWindowListener::WindowStageLifecycleCallback(WindowStageLifeCycleEventTyp return; } napi_handle_scope scope = nullptr; - napi_open_handle_scope(eng, &scope); + napi_status status = napi_open_handle_scope(eng, &scope); + if (status != napi_ok || scope == nullptr) { + TLOGNE(WmsLogTag::WMS_LIFE, "open handle scope failed."); + return; + } napi_value argv[] = {CreateJsValue(eng, static_cast(eventType))}; thisListener->CallJsMethod(WINDOW_STAGE_LIFECYCLE_EVENT_CB.c_str(), argv, ArraySize(argv)); napi_close_handle_scope(eng, scope); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp index dc96cb8767..b9f483dd4a 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp @@ -2613,7 +2613,11 @@ void MainThreadScheduler::PostMainThreadTask(Task&& localTask, std::string trace return; } napi_handle_scope scope = nullptr; - napi_open_handle_scope(env, &scope); + napi_status status = napi_open_handle_scope(env, &scope); + if (status != napi_ok || scope == nullptr) { + TLOGNE(WmsLogTag::WMS_MAIN, "open handle scope failed."); + return; + } localTask(); napi_close_handle_scope(env, scope); }; -- Gitee