From 9c3b5b002be5f01e0b662252a93e338ad40899c5 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 30 Mar 2023 06:09:10 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=80=E8=A1=8C?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I8184590bc91dfe90acbc9afdf667ab0329606ece --- interfaces/plugin/src/sensor_js.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 4c479aa3..c80df7c0 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -106,7 +106,6 @@ static void EmitSubscribeCallback(SensorEvent *event) return; } std::lock_guard subscribeLock(mutex_); - auto callback = g_subscribeCallbacks[sensorTypeId]; auto callbacks = g_subscribeCallbacks[sensorTypeId]; for (auto &callback : callbacks) { if (!copySensorData(callback, event)) { -- Gitee From 61ea68ebaba5cc6c09e63bd7f253c36c8190b1d0 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 30 Mar 2023 09:04:51 +0000 Subject: [PATCH 2/2] scope Signed-off-by: hui1975 Change-Id: I4d0c34f98dd88cac1ce42e0ea5425347c34bd150 --- interfaces/plugin/src/sensor_js.cpp | 39 ++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index c80df7c0..e3df0852 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -213,12 +213,23 @@ static bool IsOnceSubscribed(napi_env env, int32_t sensorTypeId, napi_value call if (callbackInfo->env != env) { continue; } + napi_handle_scope scope = nullptr; + napi_open_handle_scope(env, &scope); + if (scope == nullptr) { + SEN_HILOGE("Scope is nullptr"); + continue; + } napi_value sensorCallback = nullptr; - CHKNRF(env, napi_get_reference_value(env, callbackInfo->callback[0], &sensorCallback), - "napi_get_reference_value"); + if (napi_get_reference_value(env, callbackInfo->callback[0], &sensorCallback) != napi_ok) { + SEN_HILOGE("napi_get_reference_value fail"); + napi_close_handle_scope(env, scope); + return false; + } if (IsSameValue(env, callback, sensorCallback)) { + napi_close_handle_scope(env, scope); return true; } + napi_close_handle_scope(env, scope); } return false; } @@ -285,12 +296,23 @@ static bool IsSubscribed(napi_env env, int32_t sensorTypeId, napi_value callback if (callbackInfo->env != env) { continue; } + napi_handle_scope scope = nullptr; + napi_open_handle_scope(env, &scope); + if (scope == nullptr) { + SEN_HILOGE("Scope is nullptr"); + continue; + } napi_value sensorCallback = nullptr; - CHKNRF(env, napi_get_reference_value(env, callbackInfo->callback[0], &sensorCallback), - "napi_get_reference_value"); + if (napi_get_reference_value(env, callbackInfo->callback[0], &sensorCallback) != napi_ok) { + SEN_HILOGE("napi_get_reference_value fail"); + napi_close_handle_scope(env, scope); + return false; + } if (IsSameValue(env, callback, sensorCallback)) { + napi_close_handle_scope(env, scope); return true; } + napi_close_handle_scope(env, scope); } return false; } @@ -390,16 +412,25 @@ static int32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value cal if ((*iter)->env != env) { continue; } + napi_handle_scope scope = nullptr; + napi_open_handle_scope(env, &scope); + if (scope == nullptr) { + SEN_HILOGE("Scope is nullptr"); + continue; + } napi_value sensorCallback = nullptr; if (napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback) != napi_ok) { SEN_HILOGE("napi_get_reference_value fail"); + napi_close_handle_scope(env, scope); continue; } if (IsSameValue(env, callback, sensorCallback)) { callbackInfos.erase(iter++); SEN_HILOGD("Remove callback success"); + napi_close_handle_scope(env, scope); break; } + napi_close_handle_scope(env, scope); } if (callbackInfos.empty()) { SEN_HILOGD("No subscription to change sensor data"); -- Gitee