From bd3182124579c3866c49cd87b408cd10472ed9d9 Mon Sep 17 00:00:00 2001 From: yqhan Date: Thu, 28 Apr 2022 15:40:39 +0800 Subject: [PATCH] Modify structure member variable initialization operations Describe:Add the initialization of timeReq_ to the constructor. issue:https://gitee.com/openharmony/js_worker_module/issues/I556KJ?from=project-issue Signed-off-by: yqhan --- plugin/timer.cpp | 4 ---- plugin/timer.h | 8 +++++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugin/timer.cpp b/plugin/timer.cpp index 9ab72dc..4cd59ad 100644 --- a/plugin/timer.cpp +++ b/plugin/timer.cpp @@ -15,8 +15,6 @@ #include "base/compileruntime/js_worker_module/plugin/timer.h" -#include "base/compileruntime/js_worker_module/helper/napi_helper.h" -#include "base/compileruntime/js_worker_module/helper/object_helper.h" #include "utils/log.h" namespace CompilerRuntime::WorkerModule::Plugin { @@ -165,8 +163,6 @@ napi_value Timer::SetTimeoutInner(napi_env env, napi_callback_info cbinfo, bool napi_ref callbackRef = Helper::NapiHelper::CreateReference(env, argv[0], 1); TimerCallbackInfo* callbackInfo = new TimerCallbackInfo(env, tId, timeout, callbackRef, repeat, callbackArgc, callbackArgv); - uv_loop_t* loop = Helper::NapiHelper::GetLibUV(env); - uv_timer_init(loop, &callbackInfo->timeReq_); // 5. push callback info into timerTable timerTable[tId] = callbackInfo; diff --git a/plugin/timer.h b/plugin/timer.h index f30433a..08a2cb5 100644 --- a/plugin/timer.h +++ b/plugin/timer.h @@ -18,6 +18,9 @@ #include #include + +#include "base/compileruntime/js_worker_module/helper/napi_helper.h" +#include "base/compileruntime/js_worker_module/helper/object_helper.h" #include "napi/native_api.h" #include "napi/native_node_api.h" @@ -36,7 +39,10 @@ struct TimerCallbackInfo { bool repeat, size_t argc, napi_ref* argv) : env_(env), tId_(tId), timeout_(timeout), callback_(callback), repeat_(repeat), argc_(argc), argv_(argv) - {} + { + uv_loop_t* loop = Helper::NapiHelper::GetLibUV(env_); + uv_timer_init(loop, &timeReq_); + } ~TimerCallbackInfo(); }; -- Gitee