From 389fad4bae2e56ef8185846a7ede4c0fec93da2a Mon Sep 17 00:00:00 2001 From: huangfeijie Date: Wed, 20 Nov 2024 21:12:10 +0800 Subject: [PATCH] Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IB5UPC Set TaskInfo to the ConcurrentFunction Set TaskInfo to the ConcurrentFunction Signed-off-by: huangfeijie --- ecmascript/ecma_vm.cpp | 9 +++++++++ ecmascript/napi/jsnapi_expo.cpp | 1 + 2 files changed, 10 insertions(+) diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index 087701ab09..dae63d8979 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -790,6 +790,15 @@ void EcmaVM::TriggerConcurrentCallback(JSTaggedValue result, JSTaggedValue hint) } void *taskInfo = reinterpret_cast(thread_->GetTaskInfo()); + if (UNLIKELY(taskInfo == nullptr)) { + JSTaggedValue extraInfoValue = functionInfo->GetFunctionExtraInfo(); + if (!extraInfoValue.IsJSNativePointer()) { + LOG_ECMA(INFO) << "FunctionExtraInfo is not JSNativePointer"; + return; + } + JSHandle extraInfo(thread_, extraInfoValue); + taskInfo = extraInfo->GetData(); + } // clear the taskInfo when return, which can prevent the callback to get it thread_->SetTaskInfo(reinterpret_cast(nullptr)); auto localResultRef = JSNApiHelper::ToLocal(JSHandle(thread_, result)); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 373281060e..54dcd79a8c 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -4185,6 +4185,7 @@ bool JSNApi::InitForConcurrentFunction(EcmaVM *vm, Local 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(taskInfo)); thread->SetIsInConcurrentScope(true);