From 81d2056d986722002f56e8dbfeebcd75a041cd92 Mon Sep 17 00:00:00 2001 From: chensihan Date: Fri, 8 Nov 2024 03:58:36 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chensihan --- frameworks/native/backup_ext/src/ext_backup_js.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index fee000ebf..8df524290 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -437,13 +437,18 @@ napi_value AttachBackupExtensionContext(napi_env env, void *value, void *) HILOGE("Failed to get backup extension context"); return nullptr; } - napi_wrap( + napi_status status = napi_wrap( env, contextObj, workContext, [](napi_env, void *data, void *) { HILOG_DEBUG("Finalizer for weak_ptr base context is called"); delete static_cast *>(data); }, nullptr, nullptr); + if (status != napi_ok) { + HILOG_DEBUG("Failed to wrap js instance"); + delete workContext; + workContext = nullptr; + } return contextObj; } @@ -500,13 +505,18 @@ void ExtBackupJs::ExportJsContext(void) napi_coerce_to_native_binding_object(env, contextObj, AbilityRuntime::DetachCallbackFunc, AttachBackupExtensionContext, workContext, nullptr); HILOGI("Set backup extension ability context pointer is nullptr: %{public}d", context.get() == nullptr); - napi_wrap( + napi_status status = napi_wrap( env, contextObj, workContext, [](napi_env, void *data, void *) { HILOG_DEBUG("Finalizer for weak_ptr base context is called"); delete static_cast *>(data); }, nullptr, nullptr); + if (status != napi_ok) { + HILOG_DEBUG("Failed to wrap js instance"); + delete workContext; + workContext = nullptr; + } } [[maybe_unused]] tuple ExtBackupJs::CallObjectMethod(string_view name, -- Gitee