!5005 cherry pick PR4718 to OH4.0

Merge pull request !5005 from yaochaonan/cherry-pick-1697704987
This commit is contained in:
openharmony_ci 2023-10-27 08:48:37 +00:00 committed by Gitee
commit f221b45830
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 21 additions and 8 deletions

View File

@ -63,12 +63,17 @@ std::shared_ptr<JSPandaFile> JSPandaFileManager::LoadJSPandaFile(JSThread *threa
}
EcmaVM *vm = thread->GetEcmaVM();
bool mode = thread->GetCurrentEcmaContext()->GetModuleManager()->GetCurrentMode();
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
std::unique_ptr<const panda_file::File> pf;
if (!vm->IsBundlePack() && mode) {
if (!vm->IsBundlePack() && moduleManager->GetExecuteMode()) {
ResolveBufferCallback resolveBufferCallback = vm->GetResolveBufferCallback();
if (resolveBufferCallback == nullptr) {
LOG_ECMA(ERROR) << "resolveBufferCallback is nullptr";
#if defined(PANDA_TARGET_WINDOWS) || defined(PANDA_TARGET_MACOS)
if (vm->EnableReportModuleResolvingFailure()) {
LOG_NO_TAG(ERROR) << "[ArkRuntime Log] Importing shared package is not supported in the Previewer.";
}
#endif
return nullptr;
}
uint8_t *data = nullptr;

View File

@ -73,7 +73,7 @@ public:
void AddResolveImportedModule(const CString &referencingModule, JSHandle<JSTaggedValue> moduleRecord);
void Iterate(const RootVisitor &v);
bool GetCurrentMode() const
bool GetExecuteMode() const
{
return isExecuteBuffer_;
}

View File

@ -174,18 +174,22 @@ CString ModulePathHelper::ParsePrefixBundle(JSThread *thread, const JSPandaFile
}
#else
CVector<CString> currentVec;
StringHelper::SplitString(recordName, currentVec, 0, SEGMENTS_LIMIT_TWO);
StringHelper::SplitString(moduleRequestName, currentVec, 0, SEGMENTS_LIMIT_TWO);
if (currentVec.size() < SEGMENTS_LIMIT_TWO) {
LOG_ECMA(INFO) << "SplitString filed, please check recordName";
return CString();
}
CString currentModuleName = currentVec[1];
PathHelper::DeleteNamespace(currentModuleName);
if (bundleName != vm->GetBundleName() || moduleName != currentModuleName) {
if (bundleName != vm->GetBundleName()) {
entryPoint = PREVIEW_OF_ACROSS_HAP_FLAG;
if (vm->EnableReportModuleResolvingFailure()) {
LOG_NO_TAG(ERROR) << "[ArkRuntime Log] Importing shared package is not supported in the Previewer.";
CString msg = "[ArkRuntime Log] Cannot preview this HSP module as " \
"it is imported from outside the current application.";
LOG_NO_TAG(ERROR) << msg;
}
} else if (currentModuleName != vm->GetModuleName()) {
baseFileName = BUNDLE_INSTALL_PATH + moduleName + MERGE_ABC_ETS_MODULES;
}
#endif
} else {

View File

@ -3698,8 +3698,12 @@ void JSNApi::SynchronizVMInfo(EcmaVM *vm, const EcmaVM *hostVM)
vm->SetModuleName(hostVM->GetModuleName());
vm->SetAssetPath(hostVM->GetAssetPath());
vm->SetIsBundlePack(hostVM->IsBundlePack());
vm->GetAssociatedJSThread()->GetCurrentEcmaContext()->GetModuleManager()->SetExecuteMode(
hostVM->GetAssociatedJSThread()->GetCurrentEcmaContext()->GetModuleManager()->GetCurrentMode());
ecmascript::ModuleManager *vmModuleManager =
vm->GetAssociatedJSThread()->GetCurrentEcmaContext()->GetModuleManager();
ecmascript::ModuleManager *hostVMModuleManager =
hostVM->GetAssociatedJSThread()->GetCurrentEcmaContext()->GetModuleManager();
vmModuleManager->SetExecuteMode(hostVMModuleManager->GetExecuteMode());
vm->SetResolveBufferCallback(hostVM->GetResolveBufferCallback());
}