From 0d12b759d6d9a31d964d0c101cca962443ab8ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E6=B4=AA=E6=96=8C?= Date: Thu, 7 Nov 2024 21:20:17 +0800 Subject: [PATCH] =?UTF-8?q?js=5Fwindow=5Fextension=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=B3=84=E6=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 崔洪斌 --- .../src/js_window_extension.cpp | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/extension/window_extension/src/js_window_extension.cpp b/extension/window_extension/src/js_window_extension.cpp index 78c9615523..78899886b6 100644 --- a/extension/window_extension/src/js_window_extension.cpp +++ b/extension/window_extension/src/js_window_extension.cpp @@ -81,11 +81,16 @@ napi_value AttachWindowExtensionContext(napi_env env, void* value, void *) WLOGFE("Failed to get window extension context"); return nullptr; } - napi_wrap(env, contextObj, workContext, - [](napi_env, void* data, void *) { - WLOGI("Finalizer for weak_ptr service extension context is called"); - delete static_cast *>(data); - }, nullptr, nullptr); + napi_status status = napi_wrap(env, contextObj, workContext, + [](napi_env, void* data, void *) { + WLOGI("Finalizer for weak_ptr service extension context is called"); + delete static_cast *>(data); + }, nullptr, nullptr); + if (status != napi_ok) { + WLOGFE("Failed to call napi_wrap"); + delete workContext; + return nullptr; + } return contextObj; } @@ -173,11 +178,16 @@ void JsWindowExtension::BindContext(napi_env env, napi_value obj) WLOGI("JsWindowExtension::SetProperty."); napi_set_named_property(env, obj, "context", contextObj); - napi_wrap(env, contextObj, workContext, - [](napi_env, void* data, void *) { - WLOGI("Finalizer for weak_ptr extension context is called"); - delete static_cast*>(data); - }, nullptr, nullptr); + napi_status status = napi_wrap(env, contextObj, workContext, + [](napi_env, void* data, void *) { + WLOGI("Finalizer for weak_ptr extension context is called"); + delete static_cast*>(data); + }, nullptr, nullptr); + if (status != napi_ok) { + WLOGFE("Failed to call napi_wrap"); + delete workContext; + return; + } WLOGI("JsWindowExtension::Init end."); }