Fix worker ut crash

Fix worker ut crash

Issue:   https://gitee.com/openharmony/commonlibrary_ets_utils/issues/IB422U
Signed-off-by: xusen <xusen15@huawei.com>
This commit is contained in:
xusen 2024-11-13 15:23:45 +08:00
parent 2a68002f29
commit 4c2c1cf0d6

View File

@ -951,6 +951,11 @@ public:
static void ClearWorkerHandle(Worker* worker)
{
worker->CloseHostHandle();
if (worker->isLimitedWorker_) {
napi_remove_env_cleanup_hook(worker->hostEnv_, Worker::LimitedWorkerHostEnvCleanCallback, worker);
} else {
napi_remove_env_cleanup_hook(worker->hostEnv_, Worker::WorkerHostEnvCleanCallback, worker);
}
}
protected:
static thread_local NativeEngine *engine_;
@ -3469,7 +3474,6 @@ HWTEST_F(WorkersTest, WorkerTest046, testing::ext::TestSize.Level0)
std::string funcName = "GlobalCall";
napi_value cb = nullptr;
napi_value callResult = nullptr;
// ------- workerEnv---------
napi_create_function(workerEnv, funcName.c_str(), funcName.size(),
Worker::GlobalCall, worker, &cb);
UpdateWorkerState(worker, Worker::RunnerState::RUNNING);
@ -3489,6 +3493,7 @@ HWTEST_F(WorkersTest, WorkerTest046, testing::ext::TestSize.Level0)
napi_get_and_clear_last_exception(env, &exception);
ASSERT_TRUE(exception == nullptr);
worker->EraseWorker();
SetLimitedWorker(worker, false);
ClearWorkerHandle(worker);
result = Worker_Terminate(env, global);
ASSERT_TRUE(result != nullptr);