diff --git a/jsapi/worker/worker.cpp b/jsapi/worker/worker.cpp index ecef654d2c6153ca7379be7133da284243780bd7..67cd1b5d2e486daa5c5c2bcf812ea41ad3b708d0 100644 --- a/jsapi/worker/worker.cpp +++ b/jsapi/worker/worker.cpp @@ -719,9 +719,13 @@ napi_value Worker::WorkerConstructor(napi_env env, napi_callback_info cbinfo) return nullptr; } worker->StartExecuteInThread(env, script); - napi_wrap( - env, thisVar, worker, - [](napi_env env, void* data, void* hint) { + napi_wrap(env, thisVar, worker, [](napi_env env, void* data, void* hint) {}, nullptr, nullptr); + + auto hostEngine = reinterpret_cast(env); + auto thisNativeValue = reinterpret_cast(thisVar); + auto thisReference = hostEngine->CreateReference(thisNativeValue, 1, true, + [](NativeEngine* engine, void* data, void* hint) { + HILOG_ERROR("worker:: thisReference destroy"); Worker* worker = (Worker*)data; { std::lock_guard lock(worker->liveStatusLock_); @@ -740,9 +744,8 @@ napi_value Worker::WorkerConstructor(napi_env env, napi_callback_info cbinfo) } worker->TerminateInner(); } - }, - nullptr, nullptr); - napi_create_reference(env, thisVar, 1, &worker->workerWrapper_); + }, worker, nullptr); + worker->workerWrapper_ = reinterpret_cast(thisReference); return thisVar; }