!10336 Set TaskInfo to the ConcurrentFunction

Merge pull request !10336 from huangfeijie/fix_taskInfo_nullptr
This commit is contained in:
openharmony_ci 2024-11-22 06:47:21 +00:00 committed by Gitee
commit 383d69dbd1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 10 additions and 0 deletions

View File

@ -788,6 +788,15 @@ void EcmaVM::TriggerConcurrentCallback(JSTaggedValue result, JSTaggedValue hint)
}
void *taskInfo = reinterpret_cast<void*>(thread_->GetTaskInfo());
if (UNLIKELY(taskInfo == nullptr)) {
JSTaggedValue extraInfoValue = functionInfo->GetFunctionExtraInfo();
if (!extraInfoValue.IsJSNativePointer()) {
LOG_ECMA(INFO) << "FunctionExtraInfo is not JSNativePointer";
return;
}
JSHandle<JSNativePointer> extraInfo(thread_, extraInfoValue);
taskInfo = extraInfo->GetData();
}
// clear the taskInfo when return, which can prevent the callback to get it
thread_->SetTaskInfo(reinterpret_cast<uintptr_t>(nullptr));
auto localResultRef = JSNApiHelper::ToLocal<JSValueRef>(JSHandle<JSTaggedValue>(thread_, result));

View File

@ -4184,6 +4184,7 @@ bool JSNApi::InitForConcurrentFunction(EcmaVM *vm, Local<JSValueRef> function, v
LOG_ECMA(ERROR) << "Function is not concurrent";
return false;
}
JSFunction::SetFunctionExtraInfo(thread, transFunc, nullptr, nullptr, taskInfo);
transFunc->SetTaskConcurrentFuncFlag(1); // 1 : concurrent function flag
thread->SetTaskInfo(reinterpret_cast<uintptr_t>(taskInfo));
thread->SetIsInConcurrentScope(true);