!5402 initConcurrentFunction when deserialize

Merge pull request !5402 from wangzhaoyong/concurrent
This commit is contained in:
openharmony_ci 2023-12-01 13:35:57 +00:00 committed by Gitee
commit cef4e11d78
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 46 additions and 39 deletions

View File

@ -842,4 +842,47 @@ JSTaggedValue JSFunction::GetNativeFunctionExtraInfo() const
}
return JSTaggedValue::Undefined();
}
void JSFunction::InitializeForConcurrentFunction(JSThread *thread)
{
JSHandle<Method> method(thread, this->GetMethod());
const JSPandaFile *jsPandaFile = method->GetJSPandaFile();
if (jsPandaFile == nullptr) {
LOG_ECMA(ERROR) << "JSPandaFile is nullptr";
return;
}
ecmascript::CString moduleName = jsPandaFile->GetJSPandaFileDesc();
ecmascript::CString recordName = method->GetRecordNameStr();
// for debugger, to notify the script loaded and parsed which the concurrent function is in
auto *notificationMgr = thread->GetEcmaVM()->GetJsDebuggerManager()->GetNotificationManager();
notificationMgr->LoadModuleEvent(moduleName, recordName);
// check ESM or CJS
ecmascript::JSRecordInfo recordInfo;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(recordName, recordInfo);
if (!hasRecord) {
LOG_ECMA(ERROR) << "cannot find record '" << recordName << "', please check the request path.";
return;
}
if (!jsPandaFile->IsModule(recordInfo)) {
LOG_ECMA(DEBUG) << "Current function is not from ES Module's file.";
return;
}
ecmascript::ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<ecmascript::JSTaggedValue> moduleRecord;
// check compileMode
if (jsPandaFile->IsBundlePack()) {
LOG_ECMA(DEBUG) << "CompileMode is jsbundle";
moduleRecord = moduleManager->HostResolveImportedModule(moduleName);
} else {
LOG_ECMA(DEBUG) << "CompileMode is esmodule";
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(moduleName, recordName);
}
ecmascript::SourceTextModule::InstantiateForConcurrent(thread, moduleRecord, method);
JSHandle<ecmascript::SourceTextModule> module = JSHandle<ecmascript::SourceTextModule>::Cast(moduleRecord);
module->SetStatus(ecmascript::ModuleStatus::INSTANTIATED);
ecmascript::SourceTextModule::EvaluateForConcurrent(thread, module, method);
method->SetModule(thread, module);
}
} // namespace panda::ecmascript

View File

@ -224,6 +224,8 @@ public:
JSTaggedValue GetNativeFunctionExtraInfo() const;
JSTaggedValue GetRecordName() const;
void InitializeForConcurrentFunction(JSThread *thread);
static void InitializeJSFunction(JSThread *thread, const JSHandle<JSFunction> &func,
FunctionKind kind = FunctionKind::NORMAL_FUNCTION);
static JSHClass *GetOrCreateInitialJSHClass(JSThread *thread, const JSHandle<JSFunction> &fun);

View File

@ -1384,6 +1384,7 @@ JSHandle<JSTaggedValue> JSDeserializer::ReadJSFunction()
JSHandle<JSTaggedValue> methodVal = DeserializeJSTaggedValue();
JSHandle<Method> method = JSHandle<Method>::Cast(methodVal);
func->SetMethod(thread_, method);
func->InitializeForConcurrentFunction(thread_);
return funcTag;
}

View File

@ -3985,45 +3985,6 @@ bool JSNApi::InitForConcurrentFunction(EcmaVM *vm, Local<JSValueRef> function, v
}
ecmascript::JSThread *thread = vm->GetJSThread();
transFunc->SetFunctionExtraInfo(thread, nullptr, nullptr, taskInfo);
JSHandle<Method> method(thread, transFunc->GetMethod());
const JSPandaFile *jsPandaFile = method->GetJSPandaFile();
if (jsPandaFile == nullptr) {
LOG_ECMA(ERROR) << "JSPandaFile is nullptr";
return false;
}
ecmascript::CString moduleName = jsPandaFile->GetJSPandaFileDesc();
ecmascript::CString recordName = method->GetRecordNameStr();
// for debugger, to notify the script loaded and parsed which the concurrent function is in
auto *notificationMgr = vm->GetJsDebuggerManager()->GetNotificationManager();
notificationMgr->LoadModuleEvent(moduleName, recordName);
// check ESM or CJS
ecmascript::JSRecordInfo recordInfo;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(recordName, recordInfo);
if (!hasRecord) {
LOG_ECMA(ERROR) << "cannot find record '" << recordName << "', please check the request path.";
return false;
}
if (!jsPandaFile->IsModule(recordInfo)) {
LOG_ECMA(DEBUG) << "Current function is not from ES Module's file.";
return true;
}
ecmascript::ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<ecmascript::JSTaggedValue> moduleRecord;
// check compileMode
if (jsPandaFile->IsBundlePack()) {
LOG_ECMA(DEBUG) << "CompileMode is jsbundle";
moduleRecord = moduleManager->HostResolveImportedModule(moduleName);
} else {
LOG_ECMA(DEBUG) << "CompileMode is esmodule";
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(moduleName, recordName);
}
ecmascript::SourceTextModule::InstantiateForConcurrent(thread, moduleRecord, method);
JSHandle<ecmascript::SourceTextModule> module = JSHandle<ecmascript::SourceTextModule>::Cast(moduleRecord);
module->SetStatus(ecmascript::ModuleStatus::INSTANTIATED);
ecmascript::SourceTextModule::EvaluateForConcurrent(thread, module, method);
method->SetModule(thread, module);
return true;
}