!1641 fix worker ut crash

Merge pull request !1641 from xusen/worker_20241111_ut
This commit is contained in:
openharmony_ci 2024-11-13 09:13:37 +00:00 committed by Gitee
commit 767774ba21
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

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);