From 83160e471f6c315fa67fc606be4dfb21969a5ab7 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Wed, 17 Aug 2022 09:21:42 +0800 Subject: [PATCH] Modify worning Signed-off-by: hui1975 Change-Id: Ic58668ad1b175a45932e20eac225ff999ba934d1 --- interfaces/plugin/src/sensor_napi_utils.cpp | 30 +++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/interfaces/plugin/src/sensor_napi_utils.cpp b/interfaces/plugin/src/sensor_napi_utils.cpp index ba575d2c..3a886307 100644 --- a/interfaces/plugin/src/sensor_napi_utils.cpp +++ b/interfaces/plugin/src/sensor_napi_utils.cpp @@ -511,16 +511,36 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) * count of the smart pointer is guaranteed to be 1. */ asyncCallbackInfo->DecStrongRef(nullptr); + napi_handle_scope scope = nullptr; + napi_open_handle_scope(asyncCallbackInfo->env, &scope); + if (scope == nullptr) { + SEN_HILOGE("napi_handle_scope is nullptr"); + return; + } napi_env env = asyncCallbackInfo->env; napi_value callback = nullptr; - CHKNRV(env, napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback), - "napi_get_reference_value"); + if (napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback) != napi_ok) { + SEN_HILOGE("napi_get_reference_value fail"); + napi_throw_error(env, nullptr, "napi_get_reference_value fail"); + napi_close_handle_scope(asyncCallbackInfo->env, scope); + return; + } napi_value callResult = nullptr; napi_value result[2] = {0}; - CHKNCV(env, (g_convertfuncList.find(asyncCallbackInfo->type) != g_convertfuncList.end()), - "Asynccallback Type invalid in uv work"); + if (!(g_convertfuncList.find(asyncCallbackInfo->type) != g_convertfuncList.end())) { + SEN_HILOGE("asyncCallbackInfo type is invalid"); + napi_throw_error(env, nullptr, "asyncCallbackInfo type is invalid"); + napi_close_handle_scope(asyncCallbackInfo->env, scope); + return; + } g_convertfuncList[asyncCallbackInfo->type](env, asyncCallbackInfo, result); - CHKNRV(env, napi_call_function(env, nullptr, callback, 1, &result[1], &callResult), "napi_call_function"); + if (napi_call_function(env, nullptr, callback, 1, &result[1], &callResult) != napi_ok) { + SEN_HILOGE("napi_call_function callback fail"); + napi_throw_error(env, nullptr, "napi_call_function callback fail"); + napi_close_handle_scope(asyncCallbackInfo->env, scope); + return; + } + napi_close_handle_scope(asyncCallbackInfo->env, scope); asyncCallbackInfo->work = nullptr; freeWork(work); }); -- Gitee