diff --git a/interfaces/kits/js/src/dm_native_event.cpp b/interfaces/kits/js/src/dm_native_event.cpp index dc76ab0798475dc8aa66722c09b8b9757d71b23d..e7a02abbd830b8f60bb3f588452aca87149beb88 100644 --- a/interfaces/kits/js/src/dm_native_event.cpp +++ b/interfaces/kits/js/src/dm_native_event.cpp @@ -52,9 +52,9 @@ void DmNativeEvent::Off(std::string &eventType) { LOGI("DmNativeEvent Off in for event: %{public}s", eventType.c_str()); napi_handle_scope scope = nullptr; - napi_open_handle_scope(env_, &scope); - if (scope == nullptr) { - LOGE("scope is nullptr"); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); return; } @@ -75,9 +75,9 @@ void DmNativeEvent::OnEvent(const std::string &eventType, size_t argc, const nap { LOGI("OnEvent for %{public}s", eventType.c_str()); napi_handle_scope scope = nullptr; - napi_open_handle_scope(env_, &scope); - if (scope == nullptr) { - LOGE("scope is nullptr"); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); return; } @@ -90,7 +90,7 @@ void DmNativeEvent::OnEvent(const std::string &eventType, size_t argc, const nap } auto listener = iter->second; napi_value thisVar = nullptr; - napi_status status = napi_get_reference_value(env_, thisVarRef_, &thisVar); + status = napi_get_reference_value(env_, thisVarRef_, &thisVar); if (status != napi_ok) { LOGE("napi_get_reference_value thisVar for %{public}s failed, status = %{public}d", eventType.c_str(), status); napi_close_handle_scope(env_, scope); diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 2eb015b6cdba0c84f6eab4d9e98b36cf28105ac7..b222ba066cb821bb3cf460a887c49bfc66f08269 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -755,7 +755,11 @@ void DeviceManagerNapi::OnDeviceStateChange(DmNapiDevStateChangeAction action, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) { napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result = nullptr; napi_create_object(env_, &result); SetValueInt32(env_, "action", (int)action, result); @@ -777,7 +781,11 @@ void DeviceManagerNapi::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo & { LOGI("OnDeviceFound for subscribeId %{public}d, range : %{public}d", (int32_t)subscribeId, deviceInfo.range); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result = nullptr; napi_create_object(env_, &result); SetValueInt32(env_, "subscribeId", (int)subscribeId, result); @@ -800,7 +808,11 @@ void DeviceManagerNapi::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedRe { LOGI("OnDiscoveryFailed for subscribeId %{public}d", (int32_t)subscribeId); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result = nullptr; napi_create_object(env_, &result); SetValueInt32(env_, "subscribeId", (int)subscribeId, result); @@ -815,7 +827,11 @@ void DeviceManagerNapi::OnPublishResult(int32_t publishId, int32_t publishResult { LOGI("OnPublishResult for publishId %{public}d, publishResult %{public}d", publishId, publishResult); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result = nullptr; napi_create_object(env_, &result); SetValueInt32(env_, "publishId", publishId, result); @@ -834,9 +850,9 @@ void DeviceManagerNapi::OnCredentialResult(int32_t &action, const std::string &c { LOGI("OnCredentialResult for action: %{public}d", action); napi_handle_scope scope = nullptr; - napi_open_handle_scope(env_, &scope); - if (scope == nullptr) { - LOGE("scope is nullptr"); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); return; } napi_value result = nullptr; @@ -866,7 +882,11 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str { LOGI("OnAuthResult for status: %{public}d, reason: %{public}d", status, reason); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status openHandleStatus = napi_open_handle_scope(env_, &scope); + if (openHandleStatus != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value thisVar = nullptr; napi_get_reference_value(env_, thisVarRef_, &thisVar); napi_value result[DM_NAPI_ARGS_TWO] = {0}; @@ -1616,7 +1636,11 @@ void DeviceManagerNapi::OnDmUiCall(const std::string ¶mJson) { LOGI("OnCall for paramJson"); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result; napi_create_object(env_, &result); SetValueUtf8String(env_, "param", paramJson, result); diff --git a/interfaces/kits/js4.0/src/dm_native_event.cpp b/interfaces/kits/js4.0/src/dm_native_event.cpp index 10d7dd77e5ada44c6e76d9ce973419ff7eec8878..d60a6f090165d2e531c47f4c7b8fb2437cd98350 100644 --- a/interfaces/kits/js4.0/src/dm_native_event.cpp +++ b/interfaces/kits/js4.0/src/dm_native_event.cpp @@ -51,9 +51,9 @@ void DmNativeEvent::Off(std::string &eventType) { LOGI("DmNativeEvent Off in for event: %{public}s", eventType.c_str()); napi_handle_scope scope = nullptr; - napi_open_handle_scope(env_, &scope); - if (scope == nullptr) { - LOGE("scope is nullptr"); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); return; } @@ -74,9 +74,9 @@ void DmNativeEvent::OnEvent(const std::string &eventType, size_t argc, const nap { LOGI("OnEvent for %{public}s", eventType.c_str()); napi_handle_scope scope = nullptr; - napi_open_handle_scope(env_, &scope); - if (scope == nullptr) { - LOGE("scope is nullptr"); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); return; } @@ -89,7 +89,7 @@ void DmNativeEvent::OnEvent(const std::string &eventType, size_t argc, const nap } auto listener = iter->second; napi_value thisVar = nullptr; - napi_status status = napi_get_reference_value(env_, thisVarRef_, &thisVar); + status = napi_get_reference_value(env_, thisVarRef_, &thisVar); if (status != napi_ok) { LOGE("napi_get_reference_value thisVar for %{public}s failed, status = %{public}d", eventType.c_str(), status); napi_close_handle_scope(env_, scope); diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 2aa78c1ab4f9de5c2bbabfbc4e20d61cdf2e8158..e202c8fb032c2b061c95fee3fa93f0e3bcc84bc2 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -624,7 +624,11 @@ void DeviceManagerNapi::OnDeviceStatusChange(DmNapiDevStatusChange action, const OHOS::DistributedHardware::DmDeviceBasicInfo &deviceBasicInfo) { napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result = nullptr; napi_create_object(env_, &result); SetValueInt32(env_, "action", (int)action, result); @@ -642,7 +646,11 @@ void DeviceManagerNapi::OnDeviceFound(uint16_t subscribeId, const DmDeviceBasicI { LOGI("OnDeviceFound DmDeviceBasicInfo for subscribeId %{public}d", (int32_t)subscribeId); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result = nullptr; napi_create_object(env_, &result); @@ -659,7 +667,11 @@ void DeviceManagerNapi::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedRe { LOGI("OnDiscoveryFailed for subscribeId %{public}d", (int32_t)subscribeId); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result = nullptr; napi_create_object(env_, &result); SetValueInt32(env_, "reason", (int)failedReason, result); @@ -673,7 +685,11 @@ void DeviceManagerNapi::OnPublishResult(int32_t publishId, int32_t publishResult { LOGI("OnPublishResult for publishId %{public}d, publishResult %{public}d", publishId, publishResult); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result = nullptr; napi_create_object(env_, &result); SetValueInt32(env_, "publishId", publishId, result); @@ -693,7 +709,11 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str { LOGI("OnAuthResult for status: %{public}d, reason: %{public}d", status, reason); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status openHandleStatus = napi_open_handle_scope(env_, &scope); + if (openHandleStatus != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value thisVar = nullptr; napi_get_reference_value(env_, thisVarRef_, &thisVar); napi_value result[DM_NAPI_ARGS_TWO] = {0}; @@ -739,7 +759,11 @@ void DeviceManagerNapi::OnGetDeviceProfileInfoListCallbackResult(DeviceProfileIn LOGI("In"); CHECK_NULL_VOID_RET_LOG(jsCallback, "jsCallback is nullptr"); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } if (jsCallback->code != DM_OK) { napi_value error = CreateBusinessError(env_, jsCallback->code, false); napi_reject_deferred(env_, jsCallback->deferred, error); @@ -768,7 +792,11 @@ void DeviceManagerNapi::OnGetDeviceIconInfoCallbackResult(DeviceIconInfoAsyncCal LOGI("In"); CHECK_NULL_VOID_RET_LOG(jsCallback, "jsCallback is nullptr"); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } if (jsCallback->code != DM_OK) { napi_value error = CreateBusinessError(env_, jsCallback->code, false); napi_reject_deferred(env_, jsCallback->deferred, error); @@ -788,7 +816,11 @@ void DeviceManagerNapi::OnSetLocalDeviceNameCallbackResult(SetLocalDeviceNameAsy LOGI("In"); CHECK_NULL_VOID_RET_LOG(jsCallback, "jsCallback is nullptr"); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } if (jsCallback->code != DM_OK) { napi_value error = CreateBusinessError(env_, jsCallback->code, false); napi_reject_deferred(env_, jsCallback->deferred, error); @@ -807,7 +839,11 @@ void DeviceManagerNapi::OnSetRemoteDeviceNameCallbackResult(SetRemoteDeviceNameA LOGI("In"); CHECK_NULL_VOID_RET_LOG(jsCallback, "jsCallback is nullptr"); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } if (jsCallback->code != DM_OK) { napi_value error = CreateBusinessError(env_, jsCallback->code, false); napi_reject_deferred(env_, jsCallback->deferred, error); @@ -1086,7 +1122,11 @@ void DeviceManagerNapi::OnDmUiCall(const std::string ¶mJson) { LOGI("OnCall for paramJson"); napi_handle_scope scope; - napi_open_handle_scope(env_, &scope); + napi_status status = napi_open_handle_scope(env_, &scope); + if (status != napi_ok || scope == nullptr) { + LOGE("open handle scope failed"); + return; + } napi_value result; napi_create_object(env_, &result); SetValueUtf8String(env_, "param", paramJson, result);