diff --git a/frameworks/napi/input_consumer/include/js_register_module.h b/frameworks/napi/input_consumer/include/js_register_module.h index 6db68fa27446c055421a5052c13fbeeb77423b2e..94f1215a457cde66d46d6d2c279f45e78674305e 100644 --- a/frameworks/napi/input_consumer/include/js_register_module.h +++ b/frameworks/napi/input_consumer/include/js_register_module.h @@ -20,7 +20,6 @@ #include #include #include -#include #include "napi/native_api.h" #include "napi/native_node_api.h" @@ -54,21 +53,9 @@ struct KeyEventMonitorInfo { napi_ref callback[1] { nullptr }; int32_t subscribeId { 0 }; std::shared_ptr keyOption { nullptr }; - bool valid { true }; - std::mutex refLock; - void SetValid(bool flag) - { - std::lock_guard lock(refLock); - valid = flag; - } - bool IsValid() - { - std::lock_guard lock(refLock); - return valid; - } }; static std::mutex sCallBacksMutex_; typedef std::map> Callbacks; } // namespace MMI } // namespace OHOS -#endif // JS_REGISTER_MODULE_H \ No newline at end of file +#endif // JS_REGISTER_MODULE_H diff --git a/frameworks/napi/input_consumer/src/js_register_module.cpp b/frameworks/napi/input_consumer/src/js_register_module.cpp index 6283929165c67eefa68681a6e5b563b8d5661166..803ad89a129bf77493df1744b01aec061913c1b5 100644 --- a/frameworks/napi/input_consumer/src/js_register_module.cpp +++ b/frameworks/napi/input_consumer/src/js_register_module.cpp @@ -236,22 +236,11 @@ static napi_value JsOn(napi_env env, napi_callback_info info) CALL_DEBUG_ENTER; size_t argc = 3; napi_value argv[3] = { 0 }; - napi_value thisArg = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, &thisArg, nullptr), GET_CB_INFO); + CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 3) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "parameter number error"); return nullptr; } - if (thisArg == nullptr) { - MMI_HILOGE("%{public}s, This argument is nullptr.", __func__); - return nullptr; - } - napi_valuetype valueOfThis = napi_undefined; - CHKRP(env, napi_typeof(env, thisArg, &valueOfThis), TYPEOF); - if (valueOfThis == napi_undefined) { - MMI_HILOGE("%{public}s, Wrong value of this.", __func__); - return nullptr; - } KeyEventMonitorInfo *event = new (std::nothrow) KeyEventMonitorInfo { .env = env, .asyncWork = nullptr, @@ -291,14 +280,6 @@ static napi_value JsOn(napi_env env, napi_callback_info info) MMI_HILOGE("AddEventCallback failed"); return nullptr; } - std::shared_ptr* cbInfo = new std::shared_ptr(event); - napi_wrap(env, thisArg, static_cast(cbInfo), [](napi_env env, void* data, void* hint) { - std::shared_ptr* cbInfo = static_cast*>(data); - if (cbInfo != nullptr && *cbInfo != nullptr) { - (*cbInfo)->SetValid(false); - delete cbInfo; - } - }, nullptr, nullptr); return nullptr; } @@ -374,4 +355,4 @@ extern "C" __attribute__((constructor)) void RegisterModule(void) napi_module_register(&mmiModule); } } // namespace MMI -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/frameworks/napi/input_consumer/src/js_register_util.cpp b/frameworks/napi/input_consumer/src/js_register_util.cpp index efd960a199a243d1bb65d27e6efbef98f7830ebe..2d5899cb9d76978635a455dffa5bb175f7e7eceb 100644 --- a/frameworks/napi/input_consumer/src/js_register_util.cpp +++ b/frameworks/napi/input_consumer/src/js_register_util.cpp @@ -313,10 +313,6 @@ void EmitAsyncCallbackWork(KeyEventMonitorInfo *reportEvent) { CALL_DEBUG_ENTER; CHKPV(reportEvent); - if (!reportEvent->IsValid()) { - MMI_HILOGE("%{public}s, module exported object is invalid.", __func__); - return; - } uv_loop_s *loop = nullptr; CHKRV(reportEvent->env, napi_get_uv_event_loop(reportEvent->env, &loop), GET_UV_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; @@ -335,4 +331,4 @@ void EmitAsyncCallbackWork(KeyEventMonitorInfo *reportEvent) } } } // namespace MMI -} // namespace OHOS \ No newline at end of file +} // namespace OHOS