!1645 fix taskpool ut napi_value memleak

Merge pull request !1645 from xusen/task_20241114_ut
This commit is contained in:
openharmony_ci 2024-11-14 07:42:29 +00:00 committed by Gitee
commit 0098269848
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -82,6 +82,7 @@ napi_value CreateTaskObject(napi_env env, TaskType taskType = TaskType::TASK,
napi_value func = nullptr;
napi_create_string_utf8(env, "testFunc", NAPI_AUTO_LENGTH, &func);
napi_value* args = new napi_value[1];
ObjectScope<napi_value> objScope(args, true);
napi_value taskName = NapiHelper::CreateEmptyString(env);
Task* task = Task::GenerateTask(env, thisValue, func, taskName, args, argc);
task->UpdateTaskType(taskType);
@ -372,6 +373,7 @@ HWTEST_F(NativeEngineTest, TaskpoolTest021, testing::ext::TestSize.Level0)
uint32_t number = 10;
napi_value value = NapiHelper::CreateUint32(env, number);
napi_value* args = new napi_value[argc];
ObjectScope<napi_value> objScope(args, true);
napi_value taskName = NapiHelper::CreateEmptyString(env);
Task::GenerateTask(env, value, func, taskName, args, argc);
ASSERT_TRUE(args != nullptr);
@ -2183,6 +2185,7 @@ HWTEST_F(NativeEngineTest, TaskpoolTest135, testing::ext::TestSize.Level0)
napi_value func = nullptr;
napi_create_string_utf8(env, "testLongFunc", NAPI_AUTO_LENGTH, &func);
napi_value* args = new napi_value[1];
ObjectScope<napi_value> objScope(args, true);
napi_value taskName = NapiHelper::CreateEmptyString(env);
Task* task = Task::GenerateTask(env, thisValue, func, taskName, args, argc);
task->isLongTask_ = true;
@ -2367,6 +2370,7 @@ HWTEST_F(NativeEngineTest, TaskpoolTest140, testing::ext::TestSize.Level0)
napi_value funcValue = nullptr;
napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH, func, nullptr, &funcValue);
napi_value* args = new napi_value[argc];
ObjectScope<napi_value> objScope(args, true);
napi_value taskName = NapiHelper::CreateEmptyString(env);
napi_value obj = NapiHelper::CreateObject(env);
Task* task = Task::GenerateTask(env, obj, funcValue, taskName, args, argc);