!10061 模块化重构Step2:将ShareModuleManager和ModuleManager中的Resolve函数搬移至ModuleResolver中

Merge pull request !10061 from wangchen/module_resolver
This commit is contained in:
openharmony_ci 2024-11-02 03:47:47 +00:00 committed by Gitee
commit 8e15568cff
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 348 additions and 303 deletions

View File

@ -19,7 +19,7 @@
#include "ecmascript/compiler/pass_manager.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/js_runtime_options.h"
#include "ecmascript/module/js_shared_module_manager.h"
#include "ecmascript/module/module_resolver.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/ohos/ohos_pgo_processor.h"
#include "ecmascript/ohos/ohos_pkg_args.h"
@ -334,12 +334,11 @@ void AotCompilerPreprocessor::ResolveModule(const JSPandaFile *jsPandaFile, cons
{
const auto &recordInfo = jsPandaFile->GetJSRecordInfo();
JSThread *thread = vm_->GetJSThread();
SharedModuleManager *sharedModuleManager = SharedModuleManager::GetInstance();
[[maybe_unused]] EcmaHandleScope scope(thread);
for (auto info: recordInfo) {
if (jsPandaFile->IsModule(info.second)) {
auto recordName = info.first;
sharedModuleManager->ResolveImportedModuleWithMerge(thread, fileName.c_str(), recordName, false);
ModuleResolver::ResolveImportedModuleWithMerge(thread, fileName.c_str(), recordName, false);
SharedModuleManager::GetInstance()->TransferSModule(thread);
}
}

View File

@ -21,6 +21,7 @@
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/module_resolver.h"
#include "ecmascript/object_factory-inl.h"
#include "ecmascript/pgo_profiler/pgo_profiler.h"
#include "ecmascript/require/js_require_manager.h"
@ -1147,10 +1148,10 @@ void JSFunction::InitializeForConcurrentFunction(JSThread *thread, JSHandle<JSFu
// check compileMode
if (jsPandaFile->IsBundlePack()) {
LOG_ECMA(DEBUG) << "CompileMode is jsbundle";
moduleRecord = moduleManager->HostResolveImportedModule(moduleName);
moduleRecord = ModuleResolver::HostResolveImportedModuleBundlePack(thread, moduleName);
} else {
LOG_ECMA(DEBUG) << "CompileMode is esmodule";
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(moduleName, recordName);
moduleRecord = ModuleResolver::HostResolveImportedModuleWithMerge(thread, moduleName, recordName);
}
RETURN_IF_ABRUPT_COMPLETION(thread);
ecmascript::SourceTextModule::Instantiate(thread, moduleRecord);

View File

@ -19,6 +19,7 @@
#include "ecmascript/jspandafile/abc_buffer_cache.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/module/module_path_helper.h"
#include "ecmascript/module/module_resolver.h"
#include "ecmascript/checkpoint/thread_state_transition.h"
namespace panda::ecmascript {
@ -83,12 +84,11 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromFile(JSThread *thr
}
if (jsPandaFile->IsModule(recordInfo)) {
ThreadManagedScope managedScope(thread);
SharedModuleManager* sharedModuleManager = SharedModuleManager::GetInstance();
JSHandle<JSTaggedValue> moduleRecord(thread->GlobalConstants()->GetHandledUndefined());
if (jsPandaFile->IsBundlePack()) {
moduleRecord = sharedModuleManager->ResolveImportedModule(thread, name, executeFromJob);
moduleRecord = ModuleResolver::ResolveImportedModuleBundlePack(thread, name, executeFromJob);
} else {
moduleRecord = sharedModuleManager->ResolveImportedModuleWithMerge(thread, name, entry, executeFromJob);
moduleRecord = ModuleResolver::ResolveImportedModuleWithMerge(thread, name, entry, executeFromJob);
}
SourceTextModule::Instantiate(thread, moduleRecord, executeFromJob);
@ -241,9 +241,10 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::CommonExecuteBuffer(JSThread
moduleManager->SetExecuteMode(ModuleExecuteMode::ExecuteBufferMode);
JSMutableHandle<JSTaggedValue> moduleRecord(thread, thread->GlobalConstants()->GetUndefined());
if (isBundle) {
moduleRecord.Update(moduleManager->HostResolveImportedModule(buffer, size, filename));
moduleRecord.Update(ModuleResolver::HostResolveImportedModuleBundlePack(thread, buffer, size, filename));
} else {
moduleRecord.Update(moduleManager->HostResolveImportedModuleWithMerge(filename, entry, executeFromJob));
moduleRecord.Update(
ModuleResolver::HostResolveImportedModuleWithMerge(thread, filename, entry, executeFromJob));
}
SourceTextModule::Instantiate(thread, moduleRecord, executeFromJob);
@ -361,9 +362,9 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::CommonExecuteBuffer(JSThread
moduleManager->SetExecuteMode(ModuleExecuteMode::ExecuteBufferMode);
JSMutableHandle<JSTaggedValue> moduleRecord(thread, thread->GlobalConstants()->GetUndefined());
if (jsPandaFile->IsBundlePack()) {
moduleRecord.Update(moduleManager->HostResolveImportedModule(jsPandaFile, filename));
moduleRecord.Update(ModuleResolver::HostResolveImportedModuleBundlePack(thread, jsPandaFile, filename));
} else {
moduleRecord.Update(moduleManager->HostResolveImportedModuleWithMerge(filename, entry));
moduleRecord.Update(ModuleResolver::HostResolveImportedModuleWithMerge(thread, filename, entry));
}
SourceTextModule::Instantiate(thread, moduleRecord);
@ -534,9 +535,9 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::LazyExecuteModule(
// The first js file should execute at current vm.
JSHandle<JSTaggedValue> moduleRecord(thread->GlobalConstants()->GetHandledUndefined());
if (isMergedAbc) {
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(newFileName, recordName);
moduleRecord = ModuleResolver::HostResolveImportedModuleWithMerge(thread, newFileName, recordName);
} else {
moduleRecord = moduleManager->HostResolveImportedModule(newFileName);
moduleRecord = ModuleResolver::HostResolveImportedModuleBundlePack(thread, newFileName);
}
SourceTextModule::Instantiate(thread, moduleRecord);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, Unexpected(false));
@ -566,10 +567,9 @@ int JSPandaFileExecutor::ExecuteAbcFileWithSingletonPatternFlag(JSThread *thread
}
ASSERT(jsPandaFile->IsModule(recordInfo));
[[maybe_unused]] EcmaHandleScope scope(thread);
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<JSTaggedValue> moduleRecord(thread->GlobalConstants()->GetHandledUndefined());
ASSERT(!jsPandaFile->IsBundlePack());
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(abcFilePath, entryPoint);
JSHandle<JSTaggedValue> moduleRecord =
ModuleResolver::HostResolveImportedModuleWithMerge(thread, abcFilePath, entryPoint);
SourceTextModule::Instantiate(thread, moduleRecord);
if (thread->HasPendingException()) {
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ROUTE_INTERNAL_ERROR);

View File

@ -22,6 +22,7 @@
#include "ecmascript/napi/include/jsnapi.h"
#include "ecmascript/patch/quick_fix_manager.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/module/module_resolver.h"
using namespace panda::ecmascript;
using namespace panda::panda_file;
@ -180,9 +181,8 @@ HWTEST_F_L0(QuickFixTest, HotReload_Instantiate)
EcmaContext *context = thread->GetCurrentEcmaContext();
context->SetStageOfHotReload(StageOfHotReload::BEGIN_EXECUTE_PATCHMAIN);
ModuleManager *moduleManager = context->GetModuleManager();
JSHandle<JSTaggedValue> module =
moduleManager->HostResolveImportedModuleWithMergeForHotReload(patchFileName, replacedRecordName, false);
JSHandle<JSTaggedValue> module = ModuleResolver::HostResolveImportedModuleWithMergeForHotReload(thread,
patchFileName, replacedRecordName, false);
EXPECT_FALSE(module->IsHole());
JSHandle<Program> program =

View File

@ -22,7 +22,7 @@
#include "ecmascript/module/js_module_deregister.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/module_data_extractor.h"
#include "ecmascript/module/module_path_helper.h"
#include "ecmascript/module/module_resolver.h"
namespace panda::ecmascript {
using PathHelper = base::PathHelper;
@ -48,7 +48,7 @@ JSTaggedValue DynamicImport::ExecuteNativeOrJsonModule(JSThread *thread, const C
if (moduleType != ModuleTypes::JSON_MODULE) {
// nativeModule
JSHandle<JSTaggedValue> nativeModuleHld =
moduleManager->ResolveNativeModule(specifierString, "", moduleType);
ModuleResolver::ResolveNativeModule(thread, specifierString, "", moduleType);
moduleRecord = JSHandle<SourceTextModule>::Cast(nativeModuleHld);
if (!SourceTextModule::LoadNativeModule(thread, moduleRecord, moduleType)) {
LOG_FULL(ERROR) << " dynamically loading native module" << specifierString << " failed";

View File

@ -428,152 +428,6 @@ bool ModuleManager::IsLocalModuleInstantiated(const CString &referencing)
return module->GetStatus() == ModuleStatus::INSTANTIATED;
}
JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModuleWithMerge(const CString &moduleFileName,
const CString &recordName, bool executeFromJob)
{
auto entry = resolvedModules_.find(recordName);
if (entry != resolvedModules_.end()) {
return JSHandle<JSTaggedValue>(vm_->GetJSThread(), entry->second);
}
return CommonResolveImportedModuleWithMerge(moduleFileName, recordName, executeFromJob);
}
JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModuleWithMergeForHotReload(const CString &moduleFileName,
const CString &recordName, bool executeFromJob)
{
JSThread *thread = vm_->GetJSThread();
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, recordName, false);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << moduleFileName;
}
JSHandle<JSTaggedValue> moduleRecord = ResolveModuleWithMerge(thread,
jsPandaFile.get(), recordName, executeFromJob);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
UpdateResolveImportedModule(recordName, moduleRecord.GetTaggedValue());
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleManager::CommonResolveImportedModuleWithMerge(const CString &moduleFileName,
const CString &recordName, bool executeFromJob)
{
JSThread *thread = vm_->GetJSThread();
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, recordName, false);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << moduleFileName;
}
JSHandle<JSTaggedValue> moduleRecord = ResolveModuleWithMerge(thread,
jsPandaFile.get(), recordName, executeFromJob);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
AddResolveImportedModule(recordName, moduleRecord.GetTaggedValue());
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModule(const CString &referencingModule, bool executeFromJob)
{
JSThread *thread = vm_->GetJSThread();
CString moduleFileName = referencingModule;
if (vm_->IsBundlePack()) {
if (!AOTFileManager::GetAbsolutePath(referencingModule, moduleFileName)) {
CString msg = "Parse absolute " + referencingModule + " path failed";
THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str());
}
}
auto entry = resolvedModules_.find(moduleFileName);
if (entry != resolvedModules_.end()) {
return JSHandle<JSTaggedValue>(thread, entry->second);
}
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, JSPandaFile::ENTRY_MAIN_FUNCTION);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << moduleFileName;
}
return ResolveModule(thread, jsPandaFile.get(), executeFromJob);
}
// The security interface needs to be modified accordingly.
JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModule(const void *buffer, size_t size,
const CString &filename)
{
JSThread *thread = vm_->GetJSThread();
auto entry = resolvedModules_.find(filename);
if (entry != resolvedModules_.end()) {
return JSHandle<JSTaggedValue>(thread, entry->second);
}
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, filename,
JSPandaFile::ENTRY_MAIN_FUNCTION, buffer, size);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << filename;
}
return ResolveModule(thread, jsPandaFile.get());
}
JSHandle<JSTaggedValue> ModuleManager::ResolveModule(JSThread *thread, const JSPandaFile *jsPandaFile,
bool executeFromJob)
{
CString moduleFileName = jsPandaFile->GetJSPandaFileDesc();
JSHandle<JSTaggedValue> moduleRecord = thread->GlobalConstants()->GetHandledUndefined();
JSRecordInfo recordInfo = const_cast<JSPandaFile *>(jsPandaFile)->FindRecordInfo(JSPandaFile::ENTRY_FUNCTION_NAME);
if (jsPandaFile->IsModule(&recordInfo)) {
moduleRecord = ModuleDataExtractor::ParseModule(
thread, jsPandaFile, moduleFileName, moduleFileName, &recordInfo);
} else {
ASSERT(jsPandaFile->IsCjs(&recordInfo));
moduleRecord = ModuleDataExtractor::ParseCjsModule(thread, jsPandaFile);
}
// json file can not be compiled into isolate abc.
ASSERT(!jsPandaFile->IsJson(&recordInfo));
ModuleDeregister::InitForDeregisterModule(moduleRecord, executeFromJob);
AddResolveImportedModule(moduleFileName, moduleRecord.GetTaggedValue());
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleManager::ResolveNativeModule(const CString &moduleRequest,
const CString &baseFileName, ModuleTypes moduleType)
{
JSThread *thread = vm_->GetJSThread();
JSHandle<JSTaggedValue> moduleRecord = ModuleDataExtractor::ParseNativeModule(thread,
moduleRequest, baseFileName, moduleType);
AddResolveImportedModule(moduleRequest, moduleRecord.GetTaggedValue());
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleManager::ResolveModuleWithMerge(
JSThread *thread, const JSPandaFile *jsPandaFile, const CString &recordName, bool executeFromJob)
{
CString moduleFileName = jsPandaFile->GetJSPandaFileDesc();
JSHandle<JSTaggedValue> moduleRecord = thread->GlobalConstants()->GetHandledUndefined();
JSRecordInfo *recordInfo = nullptr;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(recordName, &recordInfo);
if (!hasRecord) {
JSHandle<JSTaggedValue> exp(thread, JSTaggedValue::Exception());
THROW_MODULE_NOT_FOUND_ERROR_WITH_RETURN_VALUE(thread, recordName, moduleFileName, exp);
}
if (jsPandaFile->IsModule(recordInfo)) {
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
moduleRecord = ModuleDataExtractor::ParseModule(thread, jsPandaFile, recordName, moduleFileName, recordInfo);
} else if (jsPandaFile->IsJson(recordInfo)) {
moduleRecord = ModuleDataExtractor::ParseJsonModule(thread, jsPandaFile, moduleFileName, recordName);
} else {
ASSERT(jsPandaFile->IsCjs(recordInfo));
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
moduleRecord = ModuleDataExtractor::ParseCjsModule(thread, jsPandaFile);
}
JSHandle<SourceTextModule>::Cast(moduleRecord)->SetEcmaModuleRecordNameString(recordName);
ModuleDeregister::InitForDeregisterModule(moduleRecord, executeFromJob);
return moduleRecord;
}
void ModuleManager::AddToInstantiatingSModuleList(const CString &record)
{
InstantiatingSModuleList_.push_back(record);
@ -729,20 +583,6 @@ int ModuleManager::GetExportObjectIndex(EcmaVM *vm, JSHandle<SourceTextModule> e
return index;
}
JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModule(const JSPandaFile *jsPandaFile,
const CString &filename)
{
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << filename;
}
JSThread *thread = vm_->GetJSThread();
auto entry = resolvedModules_.find(filename);
if (entry == resolvedModules_.end()) {
return ResolveModule(thread, jsPandaFile);
}
return JSHandle<JSTaggedValue>(thread, entry->second);
}
JSHandle<JSTaggedValue> ModuleManager::LoadNativeModule(JSThread *thread, const CString &key)
{
JSHandle<SourceTextModule> ecmaModule = JSHandle<SourceTextModule>::Cast(ExecuteNativeModule(thread, key));
@ -792,7 +632,7 @@ JSHandle<JSTaggedValue> ModuleManager::ExecuteNativeModule(JSThread *thread, con
} else {
auto [isNative, moduleType] = SourceTextModule::CheckNativeModule(recordName);
JSHandle<JSTaggedValue> nativeModuleHandle =
ResolveNativeModule(recordName, "", moduleType);
ModuleResolver::ResolveNativeModule(thread, recordName, "", moduleType);
JSHandle<SourceTextModule> nativeModule =
JSHandle<SourceTextModule>::Cast(nativeModuleHandle);
if (!SourceTextModule::LoadNativeModule(thread, nativeModule, moduleType)) {

View File

@ -72,17 +72,6 @@ public:
bool IsInstantiatedModule(const CString &referencing);
bool IsLocalModuleInstantiated(const CString &referencing);
JSHandle<JSTaggedValue> ResolveNativeModule(const CString &moduleRequest, const CString &baseFileName,
ModuleTypes moduleType);
JSHandle<JSTaggedValue> HostResolveImportedModule(const void *buffer, size_t size, const CString &filename);
JSHandle<JSTaggedValue> HostResolveImportedModule(const CString &referencingModule,
bool executeFromJob = false);
JSHandle<JSTaggedValue> PUBLIC_API HostResolveImportedModuleWithMerge(const CString &referencingModule,
const CString &recordName, bool executeFromJob = false);
JSHandle<JSTaggedValue> PUBLIC_API HostResolveImportedModuleWithMergeForHotReload(const CString &referencingModule,
const CString &recordName, bool executeFromJob = false);
JSHandle<JSTaggedValue> HostResolveImportedModule(const JSPandaFile *jsPandaFile, const CString &filename);
JSHandle<JSTaggedValue> LoadNativeModule(JSThread *thread, const CString &key);
JSHandle<JSTaggedValue> ExecuteNativeModuleMayThrowError(JSThread *thread, const CString &recordName);
@ -101,7 +90,7 @@ public:
JSHandle<JSTaggedValue> TryGetImportedModule(const CString& referencing);
void Iterate(const RootVisitor &v);
void AddToInstantiatingSModuleList(const CString &record);
ModuleExecuteMode GetExecuteMode() const
{
return isExecuteBuffer_.load(std::memory_order_acquire);
@ -140,6 +129,10 @@ public:
SourceTextModule::Cast(module)->DestoryEcmaModuleRecordNameString();
}
}
inline bool IsVMBundlePack()
{
return vm_->IsBundlePack();
}
private:
NO_COPY_SEMANTIC(ModuleManager);
@ -157,17 +150,6 @@ private:
JSTaggedValue key, JSTaggedValue value);
// deprecated end
JSHandle<JSTaggedValue> ResolveModule(JSThread *thread, const JSPandaFile *jsPandaFile,
bool executeFromJob = false);
JSHandle<JSTaggedValue> ResolveModuleWithMerge(JSThread *thread, const JSPandaFile *jsPandaFile,
const CString &recordName, bool executeFromJob = false);
JSHandle<JSTaggedValue> CommonResolveImportedModuleWithMerge(const CString &moduleFileName,
const CString &recordName, bool executeFromJob = false);
void AddToInstantiatingSModuleList(const CString &record);
CVector<CString> GetInstantiatingSModuleList();
void ClearInstantiatingSModuleList();

View File

@ -1988,7 +1988,7 @@ void SourceTextModule::CheckCircularImportTool(JSThread *thread, const CString &
if (moduleManager->IsLocalModuleLoaded(circularModuleRecordName)) {
moduleRecord.Update(moduleManager->HostGetImportedModule(circularModuleRecordName));
} else {
moduleRecord.Update(moduleManager->HostResolveImportedModule(circularModuleRecordName));
moduleRecord.Update(ModuleResolver::HostResolveImportedModuleBundlePack(thread, circularModuleRecordName));
RETURN_IF_ABRUPT_COMPLETION(thread);
}
CString requiredModuleName;

View File

@ -110,72 +110,6 @@ JSTaggedValue SharedModuleManager::GetLazySendableModuleValueImpl(
UNREACHABLE();
}
JSHandle<JSTaggedValue> SharedModuleManager::ResolveImportedModule(JSThread *thread, const CString &fileName,
bool executeFromJob)
{
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, JSPandaFile::ENTRY_MAIN_FUNCTION);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << fileName;
}
JSRecordInfo *recordInfo = nullptr;
[[maybe_unused]] bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(fileName, &recordInfo);
ASSERT(hasRecord && !jsPandaFile->IsSharedModule(recordInfo));
// loading unshared module though current context's module manager
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
return moduleManager->HostResolveImportedModule(fileName, executeFromJob);
}
JSHandle<JSTaggedValue> SharedModuleManager::ResolveImportedModuleWithMerge(JSThread *thread,
const CString &fileName, const CString &recordName, bool executeFromJob)
{
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, recordName, false);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
if (jsPandaFile == nullptr) {
CString msg = "Load file with filename '" + fileName + "' failed, recordName '" + recordName + "'";
THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str());
}
JSRecordInfo *recordInfo = nullptr;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(recordName, &recordInfo);
if (!hasRecord) {
CString msg = "cannot find record '" + recordName + "', please check the request path.'"
+ fileName + "'.";
THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str());
}
if (jsPandaFile->IsSharedModule(recordInfo)) {
return ResolveSharedImportedModuleWithMerge(thread, fileName, recordName, jsPandaFile.get(),
recordInfo);
}
// loading unshared module though current context's module manager
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
return moduleManager->HostResolveImportedModuleWithMerge(fileName, recordName, executeFromJob);
}
JSHandle<JSTaggedValue> SharedModuleManager::ResolveSharedImportedModuleWithMerge(JSThread *thread,
const CString &fileName, const CString &recordName, const JSPandaFile *jsPandaFile,
[[maybe_unused]] JSRecordInfo *recordInfo)
{
if (SearchInSModuleManager(thread, recordName)) {
return JSHandle<JSTaggedValue>(GetSModule(thread, recordName));
}
// before resolving module completely, shared-module put into isolate -thread resolvedModules_ temporarily.
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<JSTaggedValue> module = moduleManager->TryGetImportedModule(recordName);
if (!module->IsUndefined()) {
return module;
}
ASSERT(jsPandaFile->IsModule(recordInfo));
JSHandle<JSTaggedValue> moduleRecord = SharedModuleHelper::ParseSharedModule(thread, jsPandaFile, recordName,
fileName, recordInfo);
JSHandle<SourceTextModule>::Cast(moduleRecord)->SetEcmaModuleRecordNameString(recordName);
moduleManager->AddResolveImportedModule(recordName, moduleRecord.GetTaggedValue());
moduleManager->AddToInstantiatingSModuleList(recordName);
return moduleRecord;
}
bool SharedModuleManager::SearchInSModuleManagerUnsafe(const CString &recordName)
{
auto entry = resolvedSharedModules_.find(recordName);

View File

@ -52,12 +52,6 @@ public:
void Iterate(const RootVisitor &v);
JSHandle<JSTaggedValue> ResolveImportedModule(JSThread *thread, const CString &referencingModule,
bool executeFromJob);
JSHandle<JSTaggedValue> PUBLIC_API ResolveImportedModuleWithMerge(JSThread *thread, const CString &fileName,
const CString &recordName, bool executeFromJob);
StateVisit &findModuleMutexWithLock(JSThread *thread, const JSHandle<SourceTextModule> &module);
bool SearchInSModuleManager(JSThread *thread, const CString &recordName);
@ -65,6 +59,8 @@ public:
void InsertInSModuleManager(JSThread *thread, const CString &recordName,
JSHandle<SourceTextModule> &moduleRecord);
JSHandle<SourceTextModule> GetSModule(JSThread *thread, const CString &recordName);
void PUBLIC_API TransferSModule(JSThread *thread);
bool IsInstantiatedSModule(JSThread *thread, const JSHandle<SourceTextModule> &module);
@ -93,15 +89,10 @@ private:
NO_COPY_SEMANTIC(SharedModuleManager);
NO_MOVE_SEMANTIC(SharedModuleManager);
JSHandle<JSTaggedValue> ResolveSharedImportedModuleWithMerge(JSThread *thread, const CString &fileName,
const CString &recordName, const JSPandaFile *jsPandaFile, JSRecordInfo *recordInfo);
bool SearchInSModuleManagerUnsafe(const CString &recordName);
JSHandle<SourceTextModule> GetSModuleUnsafe(JSThread *thread, const CString &recordName);
JSHandle<SourceTextModule> GetSModule(JSThread *thread, const CString &recordName);
static constexpr uint32_t DEAULT_DICTIONART_CAPACITY = 4;
CUnorderedMap<CString, JSTaggedValue> resolvedSharedModules_;
CMap<CString, StateVisit> sharedModuleMutex_;

View File

@ -23,6 +23,8 @@
#include "ecmascript/module/module_logger.h"
#include "ecmascript/module/js_shared_module_manager.h"
#include "ecmascript/module/module_path_helper.h"
#include "ecmascript/module/js_module_deregister.h"
#include "ecmascript/module/module_data_extractor.h"
#include "ecmascript/object_fast_operator-inl.h"
#include "ecmascript/runtime_lock.h"
#include "ecmascript/patch/quick_fix_manager.h"
@ -61,7 +63,7 @@ JSHandle<JSTaggedValue> ModuleResolver::HostResolveImportedModuleWithMerge(JSThr
if (moduleManager->IsLocalModuleLoaded(requestStr)) {
return JSHandle<JSTaggedValue>(moduleManager->HostGetImportedModule(requestStr));
}
return moduleManager->ResolveNativeModule(requestStr, baseFilename, moduleType);
return ResolveNativeModule(thread, requestStr, baseFilename, moduleType);
}
CString recordName = module->GetEcmaModuleRecordNameString();
std::shared_ptr<JSPandaFile> jsPandaFile =
@ -80,8 +82,7 @@ JSHandle<JSTaggedValue> ModuleResolver::HostResolveImportedModuleWithMerge(JSThr
THROW_SYNTAX_ERROR_AND_RETURN(thread, "", thread->GlobalConstants()->GetHandledUndefined());
}
#endif
return SharedModuleManager::GetInstance()->ResolveImportedModuleWithMerge(thread, outFileName, entryPoint,
executeFromJob);
return ResolveImportedModuleWithMerge(thread, outFileName, entryPoint, executeFromJob);
}
// old way with bundle
@ -99,7 +100,7 @@ JSHandle<JSTaggedValue> ModuleResolver::HostResolveImportedModuleBundlePack(JSTh
CString dirname = base::PathHelper::ResolveDirPath(module->GetEcmaModuleFilenameString());
CString moduleFilename = ResolveFilenameFromNative(thread, dirname, moduleRequestStr);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
return SharedModuleManager::GetInstance()->ResolveImportedModule(thread, moduleFilename, executeFromJob);
return ResolveImportedModuleBundlePack(thread, moduleFilename, executeFromJob);
}
CString ModuleResolver::ReplaceModuleThroughFeature(JSThread *thread, const CString &requestName)
{
@ -115,4 +116,243 @@ CString ModuleResolver::ReplaceModuleThroughFeature(JSThread *thread, const CStr
}
return requestName;
}
JSHandle<JSTaggedValue> ModuleResolver::ResolveImportedModuleBundlePack(JSThread *thread,
const CString &fileName,
bool executeFromJob)
{
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, JSPandaFile::ENTRY_MAIN_FUNCTION);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << fileName;
}
JSRecordInfo *recordInfo = nullptr;
[[maybe_unused]] bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(fileName, &recordInfo);
ASSERT(hasRecord && !jsPandaFile->IsSharedModule(recordInfo));
// loading unshared module though current context's module manager
return HostResolveImportedModuleBundlePack(thread, fileName, executeFromJob);
}
JSHandle<JSTaggedValue> ModuleResolver::ResolveImportedModuleWithMerge(JSThread *thread,
const CString &fileName,
const CString &recordName,
bool executeFromJob)
{
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, recordName, false);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
if (jsPandaFile == nullptr) {
CString msg = "Load file with filename '" + fileName + "' failed, recordName '" + recordName + "'";
THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str());
}
JSRecordInfo *recordInfo = nullptr;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(recordName, &recordInfo);
if (!hasRecord) {
CString msg = "cannot find record '" + recordName + "', please check the request path.'" + fileName + "'.";
THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str());
}
if (jsPandaFile->IsSharedModule(recordInfo)) {
return ResolveSharedImportedModuleWithMerge(thread, fileName, recordName, jsPandaFile.get(), recordInfo);
}
return HostResolveImportedModuleWithMerge(thread, fileName, recordName, executeFromJob);
}
JSHandle<JSTaggedValue> ModuleResolver::ResolveSharedImportedModuleWithMerge(JSThread *thread,
const CString &fileName,
const CString &recordName,
const JSPandaFile *jsPandaFile,
[[maybe_unused]] JSRecordInfo *recordInfo)
{
auto sharedModuleManager = SharedModuleManager::GetInstance();
if (sharedModuleManager->SearchInSModuleManager(thread, recordName)) {
return JSHandle<JSTaggedValue>(sharedModuleManager->GetSModule(thread, recordName));
}
// before resolving module completely, shared-module put into isolate -thread resolvedModules_ temporarily.
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<JSTaggedValue> module = moduleManager->TryGetImportedModule(recordName);
if (!module->IsUndefined()) {
return module;
}
ASSERT(jsPandaFile->IsModule(recordInfo));
JSHandle<JSTaggedValue> moduleRecord =
SharedModuleHelper::ParseSharedModule(thread, jsPandaFile, recordName, fileName, recordInfo);
JSHandle<SourceTextModule>::Cast(moduleRecord)->SetEcmaModuleRecordNameString(recordName);
moduleManager->AddResolveImportedModule(recordName, moduleRecord.GetTaggedValue());
moduleManager->AddToInstantiatingSModuleList(recordName);
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleResolver::HostResolveImportedModuleWithMerge(JSThread *thread,
const CString &moduleFileName,
const CString &recordName,
bool executeFromJob)
{
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<JSTaggedValue> module = moduleManager->TryGetImportedModule(recordName);
if (!module->IsUndefined()) {
return module;
}
return CommonResolveImportedModuleWithMerge(thread, moduleFileName, recordName, executeFromJob);
}
JSHandle<JSTaggedValue> ModuleResolver::HostResolveImportedModuleWithMergeForHotReload(JSThread *thread,
const CString &moduleFileName,
const CString &recordName,
bool executeFromJob)
{
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, recordName, false);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << moduleFileName;
}
JSHandle<JSTaggedValue> moduleRecord =
ResolveModuleWithMerge(thread, jsPandaFile.get(), recordName, executeFromJob);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
moduleManager->UpdateResolveImportedModule(recordName, moduleRecord.GetTaggedValue());
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleResolver::CommonResolveImportedModuleWithMerge(JSThread *thread,
const CString &moduleFileName,
const CString &recordName,
bool executeFromJob)
{
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, recordName, false);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << moduleFileName;
}
JSHandle<JSTaggedValue> moduleRecord =
ResolveModuleWithMerge(thread, jsPandaFile.get(), recordName, executeFromJob);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
moduleManager->AddResolveImportedModule(recordName, moduleRecord.GetTaggedValue());
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleResolver::HostResolveImportedModuleBundlePack(JSThread *thread,
const CString &referencingModule,
bool executeFromJob)
{
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
CString moduleFileName = referencingModule;
if (moduleManager->IsVMBundlePack()) {
if (!AOTFileManager::GetAbsolutePath(referencingModule, moduleFileName)) {
CString msg = "Parse absolute " + referencingModule + " path failed";
THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str());
}
}
JSHandle<JSTaggedValue> module = moduleManager->TryGetImportedModule(referencingModule);
if (!module->IsUndefined()) {
return module;
}
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, JSPandaFile::ENTRY_MAIN_FUNCTION);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << moduleFileName;
}
return ResolveModuleBundlePack(thread, jsPandaFile.get(), executeFromJob);
}
// The security interface needs to be modified accordingly.
JSHandle<JSTaggedValue> ModuleResolver::HostResolveImportedModuleBundlePack(JSThread *thread,
const void *buffer,
size_t size,
const CString &filename)
{
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<JSTaggedValue> module = moduleManager->TryGetImportedModule(filename);
if (!module->IsUndefined()) {
return module;
}
std::shared_ptr<JSPandaFile> jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, filename,
JSPandaFile::ENTRY_MAIN_FUNCTION, buffer, size);
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << filename;
}
return ResolveModuleBundlePack(thread, jsPandaFile.get());
}
JSHandle<JSTaggedValue> ModuleResolver::ResolveModuleBundlePack(JSThread *thread,
const JSPandaFile *jsPandaFile,
bool executeFromJob)
{
CString moduleFileName = jsPandaFile->GetJSPandaFileDesc();
JSHandle<JSTaggedValue> moduleRecord = thread->GlobalConstants()->GetHandledUndefined();
JSRecordInfo recordInfo = const_cast<JSPandaFile *>(jsPandaFile)->FindRecordInfo(JSPandaFile::ENTRY_FUNCTION_NAME);
if (jsPandaFile->IsModule(&recordInfo)) {
moduleRecord =
ModuleDataExtractor::ParseModule(thread, jsPandaFile, moduleFileName, moduleFileName, &recordInfo);
} else {
ASSERT(jsPandaFile->IsCjs(&recordInfo));
moduleRecord = ModuleDataExtractor::ParseCjsModule(thread, jsPandaFile);
}
// json file can not be compiled into isolate abc.
ASSERT(!jsPandaFile->IsJson(&recordInfo));
ModuleDeregister::InitForDeregisterModule(moduleRecord, executeFromJob);
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
moduleManager->AddResolveImportedModule(moduleFileName, moduleRecord.GetTaggedValue());
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleResolver::ResolveNativeModule(JSThread *thread,
const CString &moduleRequest,
const CString &baseFileName,
ModuleTypes moduleType)
{
JSHandle<JSTaggedValue> moduleRecord =
ModuleDataExtractor::ParseNativeModule(thread, moduleRequest, baseFileName, moduleType);
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
moduleManager->AddResolveImportedModule(moduleRequest, moduleRecord.GetTaggedValue());
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleResolver::ResolveModuleWithMerge(JSThread *thread,
const JSPandaFile *jsPandaFile,
const CString &recordName,
bool executeFromJob)
{
CString moduleFileName = jsPandaFile->GetJSPandaFileDesc();
JSHandle<JSTaggedValue> moduleRecord = thread->GlobalConstants()->GetHandledUndefined();
JSRecordInfo *recordInfo = nullptr;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(recordName, &recordInfo);
if (!hasRecord) {
JSHandle<JSTaggedValue> exp(thread, JSTaggedValue::Exception());
THROW_MODULE_NOT_FOUND_ERROR_WITH_RETURN_VALUE(thread, recordName, moduleFileName, exp);
}
if (jsPandaFile->IsModule(recordInfo)) {
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
moduleRecord = ModuleDataExtractor::ParseModule(thread, jsPandaFile, recordName, moduleFileName, recordInfo);
} else if (jsPandaFile->IsJson(recordInfo)) {
moduleRecord = ModuleDataExtractor::ParseJsonModule(thread, jsPandaFile, moduleFileName, recordName);
} else {
ASSERT(jsPandaFile->IsCjs(recordInfo));
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
moduleRecord = ModuleDataExtractor::ParseCjsModule(thread, jsPandaFile);
}
JSHandle<SourceTextModule>::Cast(moduleRecord)->SetEcmaModuleRecordNameString(recordName);
ModuleDeregister::InitForDeregisterModule(moduleRecord, executeFromJob);
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleResolver::HostResolveImportedModuleBundlePack(JSThread *thread,
const JSPandaFile *jsPandaFile,
const CString &filename)
{
if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << filename;
}
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<JSTaggedValue> module = moduleManager->TryGetImportedModule(filename);
if (!module->IsUndefined()) {
return module;
}
return ResolveModuleBundlePack(thread, jsPandaFile);
}
} // namespace panda::ecmascript

View File

@ -17,6 +17,7 @@
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/module/js_module_source_text.h"
#include "ecmascript/module/js_shared_module.h"
namespace panda::ecmascript {
class ModuleResolver {
@ -27,15 +28,74 @@ public:
const JSHandle<JSTaggedValue> &moduleRequest,
bool executeFromJob = false);
static CString ReplaceModuleThroughFeature(JSThread *thread, const CString &requestName);
private:
// Refactoring: From SharedModuleManager::ResolveSharedImportedModule
static JSHandle<JSTaggedValue> ResolveImportedModuleBundlePack(JSThread *thread,
const CString &fileName,
bool executeFromJob);
// Refactoring: From SharedModuleManager::ResolveImportedModuleWithMerge
static JSHandle<JSTaggedValue> PUBLIC_API ResolveImportedModuleWithMerge(JSThread *thread,
const CString &fileName,
const CString &recordName,
bool executeFromJob);
// Refactoring: From ModuleManager::ResolveNativeModule
static JSHandle<JSTaggedValue> ResolveNativeModule(JSThread *thread,
const CString &moduleRequest,
const CString &baseFileName,
ModuleTypes moduleType);
// Refactoring: From ModuleManager::HostResolveImportedModule
static JSHandle<JSTaggedValue> HostResolveImportedModuleBundlePack(JSThread *thread,
const JSHandle<SourceTextModule> &module,
const JSHandle<JSTaggedValue> &moduleRequest,
const void *buffer,
size_t size,
const CString &filename);
// Refactoring: From ModuleManager::HostResolveImportedModule
static JSHandle<JSTaggedValue> HostResolveImportedModuleBundlePack(JSThread *thread,
const CString &referencingModule,
bool executeFromJob = false);
// Refactoring: From ModuleManager::HostResolveImportedModuleWithMerge
static JSHandle<JSTaggedValue> PUBLIC_API HostResolveImportedModuleWithMerge(JSThread *thread,
const CString &referencingModule,
const CString &recordName,
bool executeFromJob = false);
// Refactoring: From ModuleManager::HostResolveImportedModuleWithMergeForHotReload
static JSHandle<JSTaggedValue> PUBLIC_API HostResolveImportedModuleWithMergeForHotReload(JSThread *thread,
const CString &referencingModule,
const CString &recordName,
bool executeFromJob = false);
// Refactoring: From ModuleManager::HostResolveImportedModule
static JSHandle<JSTaggedValue> HostResolveImportedModuleBundlePack(JSThread *thread,
const JSPandaFile *jsPandaFile,
const CString &filename);
private:
// Refactoring: From SourceTextModule::HostResolveImportedModule
static JSHandle<JSTaggedValue> HostResolveImportedModuleBundlePack(JSThread *thread,
const JSHandle<SourceTextModule> &module,
const JSHandle<JSTaggedValue> &moduleRequest,
bool executeFromJob = false);
// Refactoring: From SourceTextModule::HostResolveImportedModuleWithMerge
static JSHandle<JSTaggedValue> HostResolveImportedModuleWithMerge(JSThread *thread,
const JSHandle<SourceTextModule> &module,
const JSHandle<JSTaggedValue> &moduleRequest,
bool executeFromJob = false);
// Refactoring: From SharedModuleManager::ResolveSharedImportedModuleWithMerge
static JSHandle<JSTaggedValue> ResolveSharedImportedModuleWithMerge(JSThread *thread,
const CString &fileName,
const CString &recordName,
const JSPandaFile *jsPandaFile,
JSRecordInfo *recordInfo);
// Refactoring: From ModuleManager::ResolveModule
static JSHandle<JSTaggedValue> ResolveModuleBundlePack(JSThread *thread,
const JSPandaFile *jsPandaFile,
bool executeFromJob = false);
// Refactoring: From ModuleManager::ResolveModuleWithMerge
static JSHandle<JSTaggedValue> ResolveModuleWithMerge(JSThread *thread,
const JSPandaFile *jsPandaFile,
const CString &recordName,
bool executeFromJob = false);
// Refactoring: From ModuleManager::CommonResolveImportedModuleWithMerge
static JSHandle<JSTaggedValue> CommonResolveImportedModuleWithMerge(JSThread *thread,
const CString &moduleFileName,
const CString &recordName,
bool executeFromJob = false);
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_MODULE_MODULE_RESOLVER_H

View File

@ -579,7 +579,7 @@ HWTEST_F_L0(EcmaModuleTest, HostResolveImportedModule)
JSHandle<SourceTextModule> module = factory->NewSourceTextModule();
JSHandle<JSTaggedValue> moduleRecord(thread, module.GetTaggedValue());
moduleManager->AddResolveImportedModule(baseFileName.c_str(), moduleRecord.GetTaggedValue());
JSHandle<JSTaggedValue> res = moduleManager->HostResolveImportedModule(baseFileName.c_str());
JSHandle<JSTaggedValue> res = ModuleResolver::HostResolveImportedModuleBundlePack(thread, baseFileName.c_str());
EXPECT_EQ(moduleRecord->GetRawData(), res.GetTaggedValue().GetRawData());
}
@ -587,15 +587,15 @@ HWTEST_F_L0(EcmaModuleTest, HostResolveImportedModule)
HWTEST_F_L0(EcmaModuleTest, HostResolveImportedModule2)
{
CString recordName = "module_test_module_test_A";
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
CString baseFileName = MODULE_ABC_PATH "module_test_module_test_A.abc";
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFileName, JSPandaFile::ENTRY_MAIN_FUNCTION);
EXPECT_NE(jsPandaFile, nullptr);
JSHandle<JSTaggedValue> res1 = moduleManager->HostResolveImportedModule(jsPandaFile.get(), baseFileName);
JSHandle<JSTaggedValue> res1 =
ModuleResolver::HostResolveImportedModuleBundlePack(thread, jsPandaFile.get(), baseFileName);
EXPECT_NE(res1.GetTaggedValue(), JSTaggedValue::Undefined());
JSHandle<JSTaggedValue> res2 = moduleManager->HostResolveImportedModule(jsPandaFile.get(), baseFileName);
JSHandle<JSTaggedValue> res2 =
ModuleResolver::HostResolveImportedModuleBundlePack(thread, jsPandaFile.get(), baseFileName);
EXPECT_NE(res2.GetTaggedValue(), JSTaggedValue::Undefined());
}
@ -1991,9 +1991,8 @@ HWTEST_F_L0(EcmaModuleTest, ResolveImportedModuleWithMerge) {
module->SetSharedType(SharedTypes::SHARED_MODULE);
CString recordName2 = "testModule";
SharedModuleManager* manager1 = SharedModuleManager::GetInstance();
bool executeFromJob = false;
JSHandle<JSTaggedValue> res = manager1->ResolveImportedModuleWithMerge(
JSHandle<JSTaggedValue> res = ModuleResolver::ResolveImportedModuleWithMerge(
thread, baseFileName.c_str(), recordName2, executeFromJob);
EXPECT_EQ(res.GetTaggedValue(), JSTaggedValue::Exception());
}
@ -2002,9 +2001,8 @@ HWTEST_F_L0(EcmaModuleTest, ResolveImportedModuleWithMerge2) {
CString moduleName1;
CString recordName1;
SharedModuleManager* manager1 = SharedModuleManager::GetInstance();
bool executeFromJob = false;
JSHandle<JSTaggedValue> res = manager1->ResolveImportedModuleWithMerge(
JSHandle<JSTaggedValue> res = ModuleResolver::ResolveImportedModuleWithMerge(
thread, moduleName1, recordName1, executeFromJob);
EXPECT_EQ(res.GetTaggedValue(), JSTaggedValue::Exception());
}

View File

@ -15,6 +15,7 @@
#include "ecmascript/patch/patch_loader.h"
#include "ecmascript/interpreter/interpreter-inl.h"
#include "ecmascript/module/module_resolver.h"
namespace panda::ecmascript {
PatchErrorCode PatchLoader::LoadPatchInternal(JSThread *thread, const JSPandaFile *baseFile,
@ -79,11 +80,10 @@ void PatchLoader::ExecuteFuncOrPatchMain(
// Resolve all patch module records.
CMap<CString, JSHandle<JSTaggedValue>> moduleRecords {};
ModuleManager *moduleManager = context->GetModuleManager();
CString fileName = jsPandaFile->GetJSPandaFileDesc();
for (const auto &recordName : replacedRecordNames) {
JSHandle<JSTaggedValue> moduleRecord = moduleManager->
HostResolveImportedModuleWithMergeForHotReload(fileName, recordName, false);
JSHandle<JSTaggedValue> moduleRecord =
ModuleResolver::HostResolveImportedModuleWithMergeForHotReload(thread, fileName, recordName, false);
moduleRecords.emplace(recordName, moduleRecord);
}