!3674 Refactor module, modify unreasonable hierarchical[Part 2]

Merge pull request !3674 from DaiHN/reflactor
This commit is contained in:
openharmony_ci 2023-08-30 09:13:21 +00:00 committed by Gitee
commit 9824afc4c0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
21 changed files with 207 additions and 233 deletions

View File

@ -148,13 +148,8 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv)
JSHandle<EcmaString> specifierString = JSTaggedValue::ToString(thread, specifier);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject));
// Resolve request module's ohmurl
JSMutableHandle<JSTaggedValue> moduleName(thread, thread->GlobalConstants()->GetUndefined());
CString entryPoint = JSPandaFile::ENTRY_MAIN_FUNCTION;
CString fileNameStr = ConvertToString(dirPath.GetTaggedValue());
CString requestPath = ConvertToString(specifierString.GetTaggedValue());
LOG_ECMA(DEBUG) << "Start importing dynamic module : " << requestPath;
// resolve native module
auto [isNative, moduleType] = SourceTextModule::CheckNativeModule(requestPath);
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
@ -162,6 +157,10 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv)
return DynamicImport::ExecuteNativeModule(thread, specifierString, moduleType, resolve, reject);
}
// Resolve request module's ohmurl
CString entryPoint = JSPandaFile::ENTRY_MAIN_FUNCTION;
CString fileNameStr = ConvertToString(dirPath.GetTaggedValue());
JSMutableHandle<JSTaggedValue> moduleName(thread, thread->GlobalConstants()->GetUndefined());
if (recordName->IsUndefined()) {
moduleName.Update(ResolveFilenameFromNative(thread, dirPath.GetTaggedValue(),
specifierString.GetTaggedValue()).GetTaggedValue());

View File

@ -661,7 +661,7 @@ void BytecodeInfoCollector::CollectRecordImportInfo(const CString &recordName)
continue;
}
ResolvedIndexBinding *binding = ResolvedIndexBinding::Cast(resolvedBinding.GetTaggedObject());
CString resolvedRecord = ModuleManager::GetRecordName(binding->GetModule());
CString resolvedRecord = SourceTextModule::GetRecordName(binding->GetModule());
auto bindingIndex = binding->GetIndex();
if (bytecodeInfo_.HasExportIndexToRecord(resolvedRecord, bindingIndex)) {
bytecodeInfo_.AddImportRecordInfoToRecord(recordName, resolvedRecord, index, bindingIndex);

View File

@ -1097,7 +1097,7 @@ bool MethodTypeInfer::InferLdExternalModuleVar(GateRef gate)
return UpdateType(gate, GateType::AnyType());
}
ResolvedIndexBinding *binding = ResolvedIndexBinding::Cast(resolvedBinding.GetTaggedObject());
resolvedRecord = ModuleManager::GetRecordName(binding->GetModule());
resolvedRecord = SourceTextModule::GetRecordName(binding->GetModule());
resolvedIndex = static_cast<uint32_t>(binding->GetIndex());
if (tsManager_->HasExportGT(jsPandaFile, resolvedRecord, resolvedIndex)) {
return UpdateType(gate, tsManager_->GetGTFromModuleMap(jsPandaFile, resolvedRecord, resolvedIndex));

View File

@ -254,7 +254,11 @@ Expected<JSTaggedValue, bool> EcmaContext::InvokeEcmaEntrypoint(const JSPandaFil
JSHandle<JSFunction> func(thread_, program->GetMainFunction());
JSHandle<JSTaggedValue> global = GlobalEnv::Cast(globalEnv_.GetTaggedObject())->GetJSGlobalObject();
JSHandle<JSTaggedValue> undefined = thread_->GlobalConstants()->GetHandledUndefined();
CString moduleName = jsPandaFile->GetJSPandaFileDesc();
CString entry = entryPoint.data();
if (jsPandaFile->IsMergedPF()) {
moduleName = entry;
}
JSRecordInfo recordInfo;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(entry, recordInfo);
if (!hasRecord) {
@ -264,16 +268,12 @@ Expected<JSTaggedValue, bool> EcmaContext::InvokeEcmaEntrypoint(const JSPandaFil
}
if (jsPandaFile->IsModule(recordInfo)) {
global = undefined;
CString moduleName = jsPandaFile->GetJSPandaFileDesc();
if (!jsPandaFile->IsBundlePack()) {
moduleName = entry;
}
JSHandle<SourceTextModule> module = moduleManager_->HostGetImportedModule(moduleName);
func->SetModule(thread_, module);
} else {
// if it is Cjs at present, the module slot of the function is not used. We borrow it to store the recordName,
// which can avoid the problem of larger memory caused by the new slot
JSHandle<EcmaString> recordName = factory_->NewFromUtf8(entry);
JSHandle<EcmaString> recordName = factory_->NewFromUtf8(moduleName);
func->SetModule(thread_, recordName);
}
vm_->CheckStartCpuProfiler();
@ -315,14 +315,10 @@ void EcmaContext::CJSExecution(JSHandle<JSFunction> &func, JSHandle<JSTaggedValu
JSHandle<CjsExports> exports = factory_->NewCjsExports();
JSMutableHandle<JSTaggedValue> filename(thread_, JSTaggedValue::Undefined());
JSMutableHandle<JSTaggedValue> dirname(thread_, JSTaggedValue::Undefined());
if (jsPandaFile->IsBundlePack()) {
ModulePathHelper::ResolveCurrentPath(thread_, dirname, filename, jsPandaFile);
} else {
filename.Update(func->GetModule());
ASSERT(filename->IsString());
CString fullName = ConvertToString(filename.GetTaggedValue());
dirname.Update(PathHelper::ResolveDirPath(thread_, fullName));
}
// Cjs's module slot of the function stores the recordName.
filename.Update(func->GetModule());
CString fullName = ConvertToString(filename.GetTaggedValue());
dirname.Update(PathHelper::ResolveDirPath(thread_, fullName));
CJSInfo cjsInfo(module, require, exports, filename, dirname);
RequireManager::InitializeCommonJS(thread_, cjsInfo);
if (aotFileManager_->IsLoadMain(jsPandaFile, entryPoint.data())) {

View File

@ -25,15 +25,15 @@ JSPandaFile::JSPandaFile(const panda_file::File *pf, const CString &descriptor)
: pf_(pf), desc_(descriptor)
{
ASSERT(pf_ != nullptr);
CheckIsBundlePack();
if (isBundlePack_) {
CheckIsMergedPF();
if (!IsMergedPF()) {
InitializeUnMergedPF();
} else {
InitializeMergedPF();
}
checksum_ = pf->GetHeader()->checksum;
isNewVersion_ = pf_->GetHeader()->version > OLD_VERSION;
if (!loadedFirstPandaFile && !isBundlePack_) {
if (!loadedFirstPandaFile && IsMergedPF()) {
// Tag the first merged abc to use constant string. The lifetime of this first panda file is the same
// as the vm. And make sure the first pandafile is the same at the compile time and runtime.
isFirstPandafile_ = true;
@ -41,7 +41,7 @@ JSPandaFile::JSPandaFile(const panda_file::File *pf, const CString &descriptor)
}
}
void JSPandaFile::CheckIsBundlePack()
void JSPandaFile::CheckIsMergedPF()
{
Span<const uint32_t> classIndexes = pf_->GetClasses();
for (const uint32_t index : classIndexes) {
@ -55,10 +55,10 @@ void JSPandaFile::CheckIsBundlePack()
panda_file::File::StringData sd = GetStringData(fieldNameId);
const char *fieldName = utf::Mutf8AsCString(sd.data);
if (std::strcmp(IS_COMMON_JS, fieldName) == 0 || std::strcmp(MODULE_RECORD_IDX, fieldName) == 0) {
isBundlePack_ = false;
isMergedPF_ = true;
}
});
if (!isBundlePack_) {
if (isMergedPF_) {
return;
}
}
@ -108,7 +108,7 @@ uint32_t JSPandaFile::GetOrInsertConstantPool(ConstPoolType type, uint32_t offse
const CUnorderedMap<uint32_t, uint64_t> *constpoolMap)
{
CUnorderedMap<uint32_t, uint64_t> *map = nullptr;
if (constpoolMap != nullptr && !IsBundlePack()) {
if (constpoolMap != nullptr && IsMergedPF()) {
map = const_cast<CUnorderedMap<uint32_t, uint64_t> *>(constpoolMap);
} else {
map = &constpoolMap_;
@ -213,7 +213,7 @@ MethodLiteral *JSPandaFile::FindMethodLiteral(uint32_t offset) const
bool JSPandaFile::IsFirstMergedAbc() const
{
if (isFirstPandafile_ && !IsBundlePack()) {
if (isFirstPandafile_ && IsMergedPF()) {
return true;
}
return false;
@ -221,7 +221,7 @@ bool JSPandaFile::IsFirstMergedAbc() const
bool JSPandaFile::CheckAndGetRecordInfo(const CString &recordName, JSRecordInfo &recordInfo) const
{
if (IsBundlePack()) {
if (!IsMergedPF()) {
recordInfo = jsRecordInfo_.begin()->second;
return true;
}

View File

@ -139,7 +139,7 @@ public:
uint32_t GetMainMethodIndex(const CString &recordName = ENTRY_FUNCTION_NAME) const
{
if (IsBundlePack()) {
if (!IsMergedPF()) {
return jsRecordInfo_.begin()->second.mainMethodIndex;
}
auto info = jsRecordInfo_.find(recordName);
@ -168,15 +168,18 @@ public:
uint32_t PUBLIC_API GetOrInsertConstantPool(ConstPoolType type, uint32_t offset,
const CUnorderedMap<uint32_t, uint64_t> *constpoolMap = nullptr);
void UpdateMainMethodIndex(uint32_t mainMethodIndex, const CString &recordName = ENTRY_FUNCTION_NAME)
// Only for unmerged abc
void UpdateMainMethodIndex(uint32_t mainMethodIndex)
{
if (IsBundlePack()) {
jsRecordInfo_.begin()->second.mainMethodIndex = mainMethodIndex;
} else {
auto info = jsRecordInfo_.find(recordName);
if (info != jsRecordInfo_.end()) {
info->second.mainMethodIndex = mainMethodIndex;
}
jsRecordInfo_.begin()->second.mainMethodIndex = mainMethodIndex;
}
// merged abc
void UpdateMainMethodIndex(uint32_t mainMethodIndex, const CString &recordName)
{
auto info = jsRecordInfo_.find(recordName);
if (info != jsRecordInfo_.end()) {
info->second.mainMethodIndex = mainMethodIndex;
}
}
@ -184,7 +187,7 @@ public:
int GetModuleRecordIdx(const CString &recordName = ENTRY_FUNCTION_NAME) const
{
if (IsBundlePack()) {
if (!IsMergedPF()) {
return jsRecordInfo_.begin()->second.moduleRecordIdx;
}
auto info = jsRecordInfo_.find(recordName);
@ -261,9 +264,9 @@ public:
return jsRecordInfo.isJson;
}
bool IsBundlePack() const
inline bool IsMergedPF() const
{
return isBundlePack_;
return isMergedPF_;
}
bool IsLoadedAOT() const
@ -313,7 +316,7 @@ public:
return desc.substr(1, desc.size() - 2); // 2 : skip symbol "L" and ";"
}
void CheckIsBundlePack();
void CheckIsMergedPF();
void CheckIsRecordWithBundleName(const CString &entry);
bool IsRecordWithBundleName() const
{
@ -397,8 +400,7 @@ private:
uint32_t anFileInfoIndex_ {INVALID_INDEX};
bool isNewVersion_ {false};
// marge abc
bool isBundlePack_ {true}; // isBundlePack means app compile mode is JSBundle
bool isMergedPF_ {false};// marge abc
CUnorderedMap<CString, JSRecordInfo> jsRecordInfo_;
bool isRecordWithBundleName_ {true};
static bool loadedFirstPandaFile;

View File

@ -72,7 +72,7 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromFile(JSThread *thr
// realEntry is used to record the original record, which is easy to throw when there are exceptions
const CString realEntry = entry;
// If it is an old record, delete the bundleName and moduleName
if (!jsPandaFile->IsBundlePack() && !excuteFromJob && !vm->GetBundleName().empty()) {
if (jsPandaFile->IsMergedPF() && !excuteFromJob && !vm->GetBundleName().empty()) {
jsPandaFile->CheckIsRecordWithBundleName(entry);
if (!jsPandaFile->IsRecordWithBundleName()) {
PathHelper::AdaptOldIsaRecord(entry);
@ -90,7 +90,7 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromFile(JSThread *thr
[[maybe_unused]] EcmaHandleScope scope(thread);
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<JSTaggedValue> moduleRecord(thread->GlobalConstants()->GetHandledUndefined());
if (jsPandaFile->IsBundlePack()) {
if (!jsPandaFile->IsMergedPF()) {
moduleRecord = moduleManager->HostResolveImportedModule(name, excuteFromJob);
} else {
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(name, entry, excuteFromJob);
@ -135,8 +135,8 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromBuffer(JSThread *t
THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), Unexpected(false));
}
if (jsPandaFile->IsModule(recordInfo)) {
bool isBundle = jsPandaFile->IsBundlePack();
return CommonExecuteBuffer(thread, isBundle, normalName, entry, buffer, size);
bool isMergedPF = jsPandaFile->IsMergedPF();
return CommonExecuteBuffer(thread, isMergedPF, normalName, entry, buffer, size);
}
return JSPandaFileExecutor::Execute(thread, jsPandaFile.get(), entry);
}
@ -169,11 +169,11 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteModuleBuffer(
}
LoadAOTFilesForFile(vm, jsPandaFile.get());
bool isBundle = jsPandaFile->IsBundlePack();
bool isMergedPF = jsPandaFile->IsMergedPF();
// realEntry is used to record the original record, which is easy to throw when there are exceptions
const CString realEntry = entry;
if (!isBundle) {
if (isMergedPF) {
jsPandaFile->CheckIsRecordWithBundleName(entry);
if (!jsPandaFile->IsRecordWithBundleName()) {
PathHelper::AdaptOldIsaRecord(entry);
@ -189,18 +189,18 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteModuleBuffer(
if (!jsPandaFile->IsModule(recordInfo)) {
LOG_ECMA(FATAL) << "Input file is not esmodule";
}
return CommonExecuteBuffer(thread, isBundle, name, entry, buffer, size);
return CommonExecuteBuffer(thread, isMergedPF, name, entry, buffer, size);
}
// The security interface needs to be modified accordingly.
Expected<JSTaggedValue, bool> JSPandaFileExecutor::CommonExecuteBuffer(JSThread *thread,
bool isBundle, const CString &filename, const CString &entry, const void *buffer, size_t size)
bool isMergedPF, const CString &filename, const CString &entry, const void *buffer, size_t size)
{
[[maybe_unused]] EcmaHandleScope scope(thread);
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
moduleManager->SetExecuteMode(true);
JSMutableHandle<JSTaggedValue> moduleRecord(thread, thread->GlobalConstants()->GetUndefined());
if (isBundle) {
if (!isMergedPF) {
moduleRecord.Update(moduleManager->HostResolveImportedModule(buffer, size, filename));
} else {
moduleRecord.Update(moduleManager->HostResolveImportedModuleWithMerge(filename, entry));
@ -283,7 +283,7 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::CommonExecuteBuffer(JSThread
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
moduleManager->SetExecuteMode(true);
JSMutableHandle<JSTaggedValue> moduleRecord(thread, thread->GlobalConstants()->GetUndefined());
if (jsPandaFile->IsBundlePack()) {
if (!jsPandaFile->IsMergedPF()) {
moduleRecord.Update(moduleManager->HostResolveImportedModule(jsPandaFile, filename));
} else {
moduleRecord.Update(moduleManager->HostResolveImportedModuleWithMerge(filename, entry));
@ -330,7 +330,7 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteModuleBufferSecure(JST
// realEntry is used to record the original record, which is easy to throw when there are exceptions
const CString realEntry = entry;
if (!jsPandaFile->IsBundlePack()) {
if (jsPandaFile->IsMergedPF()) {
jsPandaFile->CheckIsRecordWithBundleName(entry);
if (!jsPandaFile->IsRecordWithBundleName()) {
PathHelper::AdaptOldIsaRecord(entry);

View File

@ -19,6 +19,7 @@
#include "ecmascript/compiler/aot_file/aot_file_manager.h"
#include "ecmascript/js_file_path.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/module_path_helper.h"
#include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
#include "file.h"
@ -429,15 +430,15 @@ DebugInfoExtractor *JSPandaFileManager::CpuProfilerGetJSPtExtractor(const JSPand
return extractor;
}
std::shared_ptr<JSPandaFile> JSPandaFileManager::GenerateJSPandaFile(JSThread *thread, const panda_file::File *pf,
const CString &desc, std::string_view entryPoint)
std::shared_ptr<JSPandaFile> JSPandaFileManager::GenerateJSPandaFile(JSThread *thread,
const panda_file::File *pf, const CString &desc, std::string_view entryPoint)
{
ASSERT(GetJSPandaFile(pf) == nullptr);
std::shared_ptr<JSPandaFile> newJsPandaFile = NewJSPandaFile(pf, desc);
EcmaVM *vm = thread->GetEcmaVM();
CString methodName = entryPoint.data();
if (newJsPandaFile->IsBundlePack()) {
if (!newJsPandaFile->IsMergedPF()) {
// entryPoint maybe is _GLOBAL::func_main_watch to execute func_main_watch
auto pos = entryPoint.find_last_of("::");
if (pos != std::string_view::npos) {

View File

@ -87,7 +87,7 @@ private:
};
std::shared_ptr<JSPandaFile> GenerateJSPandaFile(JSThread *thread, const panda_file::File *pf, const CString &desc,
std::string_view entryPoint);
std::string_view entryPoint = JSPandaFile::ENTRY_FUNCTION_NAME);
std::shared_ptr<JSPandaFile> GetJSPandaFile(const panda_file::File *pf);
std::shared_ptr<JSPandaFile> FindJSPandaFileWithChecksum(const CString &filename, uint32_t checksum);
std::shared_ptr<JSPandaFile> FindJSPandaFileUnlocked(const CString &filename);

View File

@ -59,7 +59,7 @@ void PandaFileTranslator::TranslateClasses(JSPandaFile *jsPandaFile, const CStri
auto methodId = mda.GetMethodId();
CString name = reinterpret_cast<const char *>(jsPandaFile->GetStringData(mda.GetNameId()).data);
auto methodOffset = methodId.GetOffset();
if (jsPandaFile->IsBundlePack()) {
if (!jsPandaFile->IsMergedPF()) {
if (!isUpdateMainMethodIndex && name == methodName) {
jsPandaFile->UpdateMainMethodIndex(methodOffset);
isUpdateMainMethodIndex = true;
@ -88,7 +88,7 @@ void PandaFileTranslator::TranslateClasses(JSPandaFile *jsPandaFile, const CStri
const uint8_t *insns = codeDataAccessor.GetInstructions();
if (translatedCode.find(insns) == translatedCode.end()) {
translatedCode.insert(insns);
if (jsPandaFile->IsBundlePack()) {
if (!jsPandaFile->IsMergedPF()) {
TranslateBytecode(jsPandaFile, codeSize, insns, methodLiteral);
} else {
TranslateBytecode(jsPandaFile, codeSize, insns, methodLiteral, recordName);
@ -119,7 +119,7 @@ JSHandle<Program> PandaFileTranslator::GenerateProgram(EcmaVM *vm, const JSPanda
constpool = JSHandle<ConstantPool>(vm->GetJSThread(), constpoolVal);
}
if (!jsPandaFile->IsBundlePack()) {
if (jsPandaFile->IsMergedPF()) {
ParseFuncAndLiteralConstPool(vm, jsPandaFile, entryPoint.data(), constpool);
}
}

View File

@ -24,7 +24,7 @@
#include "ecmascript/jspandafile/constpool_value.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/jspandafile/literal_data_extractor.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/js_module_source_text.h"
#include "ecmascript/patch/quick_fix_manager.h"
#include "ecmascript/pgo_profiler/pgo_profiler.h"
@ -346,7 +346,7 @@ public:
static JSTaggedValue GetLiteralFromCache(JSThread *thread, JSTaggedValue constpool,
uint32_t index, JSTaggedValue module)
{
CString entry = ModuleManager::GetRecordName(module);
CString entry = SourceTextModule::GetRecordName(module);
return GetLiteralFromCache<type>(thread, constpool, index, entry);
}

View File

@ -50,10 +50,59 @@ JSTaggedValue ModuleManager::GetCurrentModule()
return JSFunction::Cast(currentFunc.GetTaggedObject())->GetModule();
}
JSTaggedValue ModuleManager::GetExportObject(const CString &file, const CString &key)
{
CString entry = file;
JSThread *thread = vm_->GetJSThread();
CString name = vm_->GetAssetPath();
if (!vm_->IsBundlePack()) {
ModulePathHelper::ParseOhmUrl(vm_, file, name, entry);
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, name, entry.c_str(), false);
if (jsPandaFile == nullptr) {
return JSTaggedValue::Null();
}
if (!jsPandaFile->IsRecordWithBundleName()) {
PathHelper::AdaptOldIsaRecord(entry);
}
}
JSHandle<SourceTextModule> ecmaModule = HostGetImportedModule(entry);
if (ecmaModule->GetIsNewBcVersion()) {
int index = SourceTextModule::GetExportObjectIndex(vm_, ecmaModule, key.c_str());
if (index >= 0) {
return ecmaModule->GetModuleValue(thread, index, false);
}
return JSTaggedValue::Null();
}
ObjectFactory *factory = vm_->GetFactory();
JSHandle<EcmaString> keyHandle = factory->NewFromASCII(key);
return ecmaModule->GetModuleValue(thread, keyHandle.GetTaggedValue(), false);
}
JSTaggedValue ModuleManager::GetExportObjectFromBuffer(const CString &file, const CString &key)
{
JSThread *thread = vm_->GetJSThread();
JSHandle<SourceTextModule> ecmaModule = HostGetImportedModule(file);
if (ecmaModule->GetIsNewBcVersion()) {
int index = SourceTextModule::GetExportObjectIndex(vm_, ecmaModule, key.c_str());
if (index >= 0) {
return ecmaModule->GetModuleValue(thread, index, false);
}
return JSTaggedValue::Null();
}
ObjectFactory *factory = vm_->GetFactory();
JSHandle<EcmaString> keyHandle = factory->NewFromASCII(key);
return ecmaModule->GetModuleValue(thread, keyHandle.GetTaggedValue(), false);
}
JSTaggedValue ModuleManager::GetModuleValueInner(int32_t index)
{
JSTaggedValue currentModule = GetCurrentModule();
if (currentModule.IsUndefined()) {
// if currentModule is undefined or ecma string, exception has occurred.
if (!currentModule.IsSourceTextModule()) {
LOG_FULL(FATAL) << "GetModuleValueInner currentModule failed";
}
return SourceTextModule::Cast(currentModule.GetTaggedObject())->GetModuleValue(vm_->GetJSThread(), index, false);
@ -62,7 +111,8 @@ JSTaggedValue ModuleManager::GetModuleValueInner(int32_t index)
JSTaggedValue ModuleManager::GetModuleValueInner(int32_t index, JSTaggedValue jsFunc)
{
JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule();
if (currentModule.IsUndefined()) {
// if currentModule is undefined or ecma string, exception has occurred.
if (!currentModule.IsSourceTextModule()) {
LOG_FULL(FATAL) << "GetModuleValueInner currentModule failed";
}
return SourceTextModule::Cast(currentModule.GetTaggedObject())->GetModuleValue(vm_->GetJSThread(), index, false);
@ -83,7 +133,7 @@ JSTaggedValue ModuleManager::GetModuleValueOutter(int32_t index, JSTaggedValue j
JSTaggedValue ModuleManager::GetModuleValueOutterInternal(int32_t index, JSTaggedValue currentModule)
{
JSThread *thread = vm_->GetJSThread();
if (currentModule.IsUndefined()) {
if (!currentModule.IsSourceTextModule()) {
LOG_FULL(FATAL) << "GetModuleValueOutter currentModule failed";
UNREACHABLE();
}
@ -211,7 +261,7 @@ void ModuleManager::StoreModuleValueInternal(JSHandle<SourceTextModule> &current
JSTaggedValue ModuleManager::GetModuleValueInner(JSTaggedValue key)
{
JSTaggedValue currentModule = GetCurrentModule();
if (currentModule.IsUndefined()) {
if (!currentModule.IsSourceTextModule()) {
LOG_FULL(FATAL) << "GetModuleValueInner currentModule failed";
UNREACHABLE();
}
@ -221,7 +271,7 @@ JSTaggedValue ModuleManager::GetModuleValueInner(JSTaggedValue key)
JSTaggedValue ModuleManager::GetModuleValueInner(JSTaggedValue key, JSTaggedValue jsFunc)
{
JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule();
if (currentModule.IsUndefined()) {
if (!currentModule.IsSourceTextModule()) {
LOG_FULL(FATAL) << "GetModuleValueInner currentModule failed";
UNREACHABLE();
}
@ -243,7 +293,7 @@ JSTaggedValue ModuleManager::GetModuleValueOutter(JSTaggedValue key, JSTaggedVal
JSTaggedValue ModuleManager::GetModuleValueOutterInternal(JSTaggedValue key, JSTaggedValue currentModule)
{
JSThread *thread = vm_->GetJSThread();
if (currentModule.IsUndefined()) {
if (!currentModule.IsSourceTextModule()) {
LOG_FULL(FATAL) << "GetModuleValueOutter currentModule failed";
UNREACHABLE();
}
@ -297,8 +347,7 @@ void ModuleManager::StoreModuleValueInternal(JSHandle<SourceTextModule> &current
JSHandle<SourceTextModule> ModuleManager::HostGetImportedModule(const CString &referencingModule)
{
ObjectFactory *factory = vm_->GetFactory();
JSHandle<EcmaString> referencingHandle = factory->NewFromUtf8(referencingModule);
JSHandle<EcmaString> referencingHandle = vm_->GetFactory()->NewFromUtf8(referencingModule);
return HostGetImportedModule(referencingHandle.GetTaggedValue());
}
@ -306,8 +355,7 @@ JSHandle<SourceTextModule> ModuleManager::HostGetImportedModule(JSTaggedValue re
{
NameDictionary *dict = NameDictionary::Cast(resolvedModules_.GetTaggedObject());
int entry = dict->FindEntry(referencing);
LOG_ECMA_IF(entry == -1, FATAL) << "Can not get module: "
<< ConvertToString(referencing);
LOG_ECMA_IF(entry == -1, FATAL) << "Can not get module: " << ConvertToString(referencing);
JSTaggedValue result = dict->GetValue(entry);
return JSHandle<SourceTextModule>(vm_->GetJSThread(), result);
}
@ -363,13 +411,10 @@ JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModuleWithMerge(const
const CString &recordName, bool excuteFromJob)
{
JSThread *thread = vm_->GetJSThread();
ObjectFactory *factory = vm_->GetFactory();
JSHandle<EcmaString> recordNameHandle = vm_->GetFactory()->NewFromUtf8(recordName);
JSHandle<EcmaString> recordNameHandle = factory->NewFromUtf8(recordName);
NameDictionary *dict = NameDictionary::Cast(resolvedModules_.GetTaggedObject());
int entry = dict->FindEntry(recordNameHandle.GetTaggedValue());
if (entry != -1) {
return JSHandle<JSTaggedValue>(thread, dict->GetValue(entry));
if (IsImportedModuleLoaded(recordNameHandle.GetTaggedValue())) {
return JSHandle<JSTaggedValue>::Cast(HostGetImportedModule(recordNameHandle.GetTaggedValue()));
}
std::shared_ptr<JSPandaFile> jsPandaFile = SkipDefaultBundleFile(moduleFileName) ? nullptr :
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, recordName, false);
@ -410,23 +455,17 @@ JSHandle<JSTaggedValue> ModuleManager::CreateEmptyModule()
JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModule(const CString &referencingModule, bool excuteFromJob)
{
JSThread *thread = vm_->GetJSThread();
ObjectFactory *factory = vm_->GetFactory();
JSHandle<EcmaString> referencingHandle = factory->NewFromUtf8(referencingModule);
JSHandle<EcmaString> referencingHandle = vm_->GetFactory()->NewFromUtf8(referencingModule);
CString moduleFileName = referencingModule;
if (vm_->IsBundlePack()) {
if (AOTFileManager::GetAbsolutePath(referencingModule, moduleFileName)) {
referencingHandle = factory->NewFromUtf8(moduleFileName);
} else {
CString msg = "Parse absolute " + referencingModule + " path failed";
THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str());
}
if (AOTFileManager::GetAbsolutePath(referencingModule, moduleFileName)) {
referencingHandle = vm_->GetFactory()->NewFromUtf8(moduleFileName);
} else {
CString msg = "Parse absolute " + referencingModule + " path failed";
THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str());
}
NameDictionary *dict = NameDictionary::Cast(resolvedModules_.GetTaggedObject());
int entry = dict->FindEntry(referencingHandle.GetTaggedValue());
if (entry != -1) {
return JSHandle<JSTaggedValue>(thread, dict->GetValue(entry));
if (IsImportedModuleLoaded(referencingHandle.GetTaggedValue())) {
return JSHandle<JSTaggedValue>::Cast(HostGetImportedModule(referencingHandle.GetTaggedValue()));
}
std::shared_ptr<JSPandaFile> jsPandaFile =
@ -444,13 +483,9 @@ JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModule(const void *buf
const CString &filename)
{
JSThread *thread = vm_->GetJSThread();
ObjectFactory *factory = vm_->GetFactory();
JSHandle<EcmaString> referencingHandle = factory->NewFromUtf8(filename);
NameDictionary *dict = NameDictionary::Cast(resolvedModules_.GetTaggedObject());
int entry = dict->FindEntry(referencingHandle.GetTaggedValue());
if (entry != -1) {
return JSHandle<JSTaggedValue>(thread, dict->GetValue(entry));
JSHandle<EcmaString> referencingHandle = vm_->GetFactory()->NewFromUtf8(filename);
if (IsImportedModuleLoaded(referencingHandle.GetTaggedValue())) {
return JSHandle<JSTaggedValue>::Cast(HostGetImportedModule(referencingHandle.GetTaggedValue()));
}
std::shared_ptr<JSPandaFile> jsPandaFile =
@ -475,6 +510,7 @@ JSHandle<JSTaggedValue> ModuleManager::ResolveModule(JSThread *thread, const JSP
moduleRecord = ModuleDataExtractor::ParseModule(thread, jsPandaFile, moduleFileName, moduleFileName);
} else if (jsPandaFile->IsJson(recordInfo)) {
moduleRecord = ModuleDataExtractor::ParseJsonModule(thread, jsPandaFile, moduleFileName);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
} else {
ASSERT(jsPandaFile->IsCjs(recordInfo));
moduleRecord = ModuleDataExtractor::ParseCjsModule(thread, jsPandaFile);
@ -520,6 +556,7 @@ JSHandle<JSTaggedValue> ModuleManager::ResolveModuleWithMerge(
moduleRecord = ModuleDataExtractor::ParseModule(thread, jsPandaFile, recordName, moduleFileName);
} else if (jsPandaFile->IsJson(recordInfo)) {
moduleRecord = ModuleDataExtractor::ParseJsonModule(thread, jsPandaFile, moduleFileName, recordName);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
} else {
ASSERT(jsPandaFile->IsCjs(recordInfo));
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
@ -532,14 +569,6 @@ JSHandle<JSTaggedValue> ModuleManager::ResolveModuleWithMerge(
return moduleRecord;
}
void ModuleManager::AddResolveImportedModule(const JSPandaFile *jsPandaFile, const CString &referencingModule)
{
JSThread *thread = vm_->GetJSThread();
JSHandle<JSTaggedValue> moduleRecord =
ModuleDataExtractor::ParseModule(thread, jsPandaFile, referencingModule, referencingModule);
AddResolveImportedModule(referencingModule, moduleRecord);
}
void ModuleManager::AddResolveImportedModule(const CString &referencingModule, JSHandle<JSTaggedValue> moduleRecord)
{
JSThread *thread = vm_->GetJSThread();
@ -565,7 +594,7 @@ JSTaggedValue ModuleManager::GetModuleNamespace(int32_t index, JSTaggedValue cur
JSTaggedValue ModuleManager::GetModuleNamespaceInternal(int32_t index, JSTaggedValue currentModule)
{
if (currentModule.IsUndefined()) {
if (!currentModule.IsSourceTextModule()) {
LOG_FULL(FATAL) << "GetModuleNamespace currentModule failed";
UNREACHABLE();
}
@ -616,7 +645,7 @@ JSTaggedValue ModuleManager::GetModuleNamespace(JSTaggedValue localName, JSTagge
JSTaggedValue ModuleManager::GetModuleNamespaceInternal(JSTaggedValue localName, JSTaggedValue currentModule)
{
if (currentModule.IsUndefined()) {
if (!currentModule.IsSourceTextModule()) {
LOG_FULL(FATAL) << "GetModuleNamespace currentModule failed";
UNREACHABLE();
}
@ -639,43 +668,6 @@ void ModuleManager::Iterate(const RootVisitor &v)
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(&cachedEmptyModule_)));
}
CString ModuleManager::GetRecordName(JSTaggedValue module)
{
CString entry = "";
if (module.IsString()) {
entry = ConvertToString(module);
}
if (module.IsSourceTextModule()) {
SourceTextModule *sourceTextModule = SourceTextModule::Cast(module.GetTaggedObject());
if (sourceTextModule->GetEcmaModuleRecordName().IsString()) {
entry = ConvertToString(sourceTextModule->GetEcmaModuleRecordName());
}
}
return entry;
}
int ModuleManager::GetExportObjectIndex(EcmaVM *vm, JSHandle<SourceTextModule> ecmaModule,
const std::string &key)
{
JSThread *thread = vm->GetJSThread();
JSHandle<TaggedArray> localExportEntries(thread, ecmaModule->GetLocalExportEntries());
size_t exportEntriesLen = localExportEntries->GetLength();
// 0: There's only one export value "default"
int index = 0;
JSMutableHandle<LocalExportEntry> ee(thread, thread->GlobalConstants()->GetUndefined());
if (exportEntriesLen > 1) { // 1: The number of export objects exceeds 1
for (size_t idx = 0; idx < exportEntriesLen; idx++) {
ee.Update(localExportEntries->Get(idx));
if (EcmaStringAccessor(ee->GetExportName()).ToStdString() == key) {
ASSERT(idx <= static_cast<size_t>(INT_MAX));
index = static_cast<int>(ee->GetLocalIndex());
break;
}
}
}
return index;
}
JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModule(const JSPandaFile *jsPandaFile,
const CString &filename)
{

View File

@ -61,13 +61,13 @@ public:
JSHandle<JSTaggedValue> PUBLIC_API HostResolveImportedModuleWithMerge(const CString &referencingModule,
const CString &recordName, bool excuteFromJob = false);
JSHandle<JSTaggedValue> HostResolveImportedModule(const JSPandaFile *jsPandaFile, const CString &filename);
JSTaggedValue GetExportObject(const CString &file, const CString &key);
JSTaggedValue GetExportObjectFromBuffer(const CString &file, const CString &key);
JSTaggedValue GetCurrentModule();
JSTaggedValue GetNativeModuleValue(JSThread *thread, JSTaggedValue currentModule,
JSTaggedValue resolvedModule, ResolvedIndexBinding *binding);
JSTaggedValue GetCJSModuleValue(JSThread *thread, JSTaggedValue currentModule,
JSTaggedValue resolvedModule, ResolvedIndexBinding *binding);
void AddResolveImportedModule(const JSPandaFile *jsPandaFile, const CString &referencingModule);
void AddResolveImportedModule(const CString &referencingModule, JSHandle<JSTaggedValue> moduleRecord);
void Iterate(const RootVisitor &v);
@ -80,9 +80,6 @@ public:
isExecuteBuffer_ = mode;
}
static CString GetRecordName(JSTaggedValue module);
static int GetExportObjectIndex(EcmaVM *vm, JSHandle<SourceTextModule> ecmaModule, const std::string &key);
private:
NO_COPY_SEMANTIC(ModuleManager);
NO_MOVE_SEMANTIC(ModuleManager);

View File

@ -93,9 +93,7 @@ JSHandle<JSTaggedValue> SourceTextModule::HostResolveImportedModuleWithMerge(
return moduleManager->ResolveNativeModule(moduleRequestName, moduleType);
}
ASSERT(module->GetEcmaModuleFilename().IsHeapObject());
CString baseFilename = ConvertToString(module->GetEcmaModuleFilename());
ASSERT(module->GetEcmaModuleRecordName().IsHeapObject());
CString moduleRecordName = ConvertToString(module->GetEcmaModuleRecordName());
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFilename, moduleRecordName);
@ -269,16 +267,13 @@ void SourceTextModule::InstantiateCJS(JSThread *thread, const JSHandle<SourceTex
JSTaggedValue cjsRecordName(requiredModule->GetEcmaModuleRecordName());
JSMutableHandle<JSTaggedValue> cjsModuleName(thread, JSTaggedValue::Undefined());
// Get exported cjs module
bool isBundle;
if (cjsRecordName.IsUndefined()) {
cjsModuleName.Update(cjsFileName);
isBundle = true;
} else {
cjsModuleName.Update(cjsRecordName);
isBundle = false;
}
JSHandle<JSTaggedValue> cjsExports = CjsModule::SearchFromModuleCache(thread, cjsModuleName);
InitializeEnvironment(thread, currentModule, cjsModuleName, cjsExports, isBundle);
InitializeEnvironment(thread, currentModule, cjsModuleName, cjsExports);
}
std::pair<bool, ModuleTypes> SourceTextModule::CheckNativeModule(const CString &moduleRequestName)
@ -311,7 +306,7 @@ Local<JSValueRef> SourceTextModule::GetRequireNativeModuleFunc(EcmaVM *vm, Modul
globalConstants->GetHandledRequireNapiString();
return globalObject->Get(vm, JSNApiHelper::ToLocal<StringRef>(funcName));
}
void SourceTextModule::MakeAppArgs(const EcmaVM *vm, std::vector<Local<JSValueRef>> &arguments,
const CString &moduleName)
{
@ -386,11 +381,11 @@ void SourceTextModule::InstantiateNativeModule(JSThread *thread, JSHandle<Source
JSHandle<JSTaggedValue> nativeModuleName(thread, requiredModule->GetEcmaModuleRecordName());
JSHandle<JSTaggedValue> nativeExports(thread, requiredModule->GetModuleValue(thread, 0, false));
InitializeEnvironment(thread, currentModule, nativeModuleName, nativeExports, false);
InitializeEnvironment(thread, currentModule, nativeModuleName, nativeExports);
}
void SourceTextModule::InitializeEnvironment(JSThread *thread, const JSHandle<SourceTextModule> &currentModule,
JSHandle<JSTaggedValue> &moduleName, JSHandle<JSTaggedValue> &exports, bool isBundle)
JSHandle<JSTaggedValue> &moduleName, JSHandle<JSTaggedValue> &exports)
{
// Get esm environment
JSHandle<JSTaggedValue> moduleEnvironment(thread, currentModule->GetEnvironment());
@ -412,10 +407,11 @@ void SourceTextModule::InitializeEnvironment(JSThread *thread, const JSHandle<So
}
JSHandle<SourceTextModule> requestedModule = GetModuleFromBinding(thread, resolvedBinding);
JSMutableHandle<JSTaggedValue> requestedName(thread, JSTaggedValue::Undefined());
if (isBundle) {
JSTaggedValue recordName = requestedModule->GetEcmaModuleRecordName();
if (recordName.IsUndefined()) {
requestedName.Update(requestedModule->GetEcmaModuleFilename());
} else {
requestedName.Update(requestedModule->GetEcmaModuleRecordName());
requestedName.Update(recordName);
}
// if not the same module, then don't have to update
if (!JSTaggedValue::SameValue(requestedName, moduleName)) {
@ -1066,18 +1062,8 @@ int SourceTextModule::ModuleEvaluation(JSThread *thread, const JSHandle<ModuleRe
void SourceTextModule::ModuleExecution(JSThread *thread, const JSHandle<SourceTextModule> &module,
const void *buffer, size_t size, bool excuteFromJob)
{
JSTaggedValue moduleFileName = module->GetEcmaModuleFilename();
ASSERT(moduleFileName.IsString());
CString moduleFilenameStr = ConvertToString(EcmaString::Cast(moduleFileName.GetTaggedObject()));
std::string entryPoint;
JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName();
if (moduleRecordName.IsUndefined()) {
entryPoint = JSPandaFile::ENTRY_FUNCTION_NAME;
} else {
ASSERT(moduleRecordName.IsString());
entryPoint = ConvertToString(moduleRecordName);
}
CString moduleFilenameStr = ConvertToString(module->GetEcmaModuleFilename());
CString entryPoint = GetRecordName(module.GetTaggedValue());
std::shared_ptr<JSPandaFile> jsPandaFile;
if (buffer != nullptr) {
@ -1090,7 +1076,7 @@ void SourceTextModule::ModuleExecution(JSThread *thread, const JSHandle<SourceTe
if (jsPandaFile == nullptr) {
CString msg = "Load file with filename '" + moduleFilenameStr + "' failed, recordName '" +
entryPoint.c_str() + "'";
entryPoint + "'";
THROW_ERROR(thread, ErrorType::REFERENCE_ERROR, msg.c_str());
}
JSPandaFileExecutor::Execute(thread, jsPandaFile.get(), entryPoint, excuteFromJob);
@ -1561,4 +1547,40 @@ bool SourceTextModule::IsDynamicModule(LoadingTypes types)
{
return types == LoadingTypes::DYNAMITC_MODULE;
}
} // namespace panda::ecmascript
CString SourceTextModule::GetRecordName(JSTaggedValue module)
{
if (module.IsString()) {
return ConvertToString(module);
}
if (module.IsSourceTextModule()) {
SourceTextModule *sourceTextModule = SourceTextModule::Cast(module.GetTaggedObject());
if (sourceTextModule->GetEcmaModuleRecordName().IsString()) {
return ConvertToString(sourceTextModule->GetEcmaModuleRecordName());
}
}
return "";
}
int SourceTextModule::GetExportObjectIndex(EcmaVM *vm, JSHandle<SourceTextModule> ecmaModule,
const std::string &key)
{
JSThread *thread = vm->GetJSThread();
JSHandle<TaggedArray> localExportEntries(thread, ecmaModule->GetLocalExportEntries());
size_t exportEntriesLen = localExportEntries->GetLength();
// 0: There's only one export value "default"
if (exportEntriesLen == 0) {
return exportEntriesLen;
}
JSMutableHandle<LocalExportEntry> ee(thread, thread->GlobalConstants()->GetUndefined());
ASSERT(exportEntriesLen > 1); // 1: The number of export objects exceeds 1
for (size_t idx = 0; idx < exportEntriesLen; idx++) {
ee.Update(localExportEntries->Get(idx));
if (EcmaStringAccessor(ee->GetExportName()).ToStdString() == key) {
ASSERT(idx <= static_cast<size_t>(INT_MAX));
return static_cast<int>(idx);
}
}
return -1;
}
} // namespace panda::ecmascript

View File

@ -178,6 +178,9 @@ public:
static JSTaggedValue GetModuleName(JSTaggedValue currentModule);
static bool IsDynamicModule(LoadingTypes types);
static CString GetRecordName(JSTaggedValue module);
static int GetExportObjectIndex(EcmaVM *vm, JSHandle<SourceTextModule> ecmaModule, const std::string &key);
private:
static void SetExportName(JSThread *thread,
const JSHandle<JSTaggedValue> &moduleRequest, const JSHandle<SourceTextModule> &module,
@ -201,7 +204,7 @@ private:
const JSHandle<JSTaggedValue> &exportName,
CVector<std::pair<JSHandle<SourceTextModule>, JSHandle<JSTaggedValue>>> &resolveVector);
static void InitializeEnvironment(JSThread *thread, const JSHandle<SourceTextModule> &currentModule,
JSHandle<JSTaggedValue> &moduleName, JSHandle<JSTaggedValue> &exports, bool isBundle);
JSHandle<JSTaggedValue> &moduleName, JSHandle<JSTaggedValue> &exports);
static void CheckResolvedBinding(JSThread *thread, const JSHandle<SourceTextModule> &module);
static void CheckResolvedIndexBinding(JSThread *thread, const JSHandle<SourceTextModule> &module);

View File

@ -115,6 +115,7 @@ JSHandle<JSTaggedValue> ModuleDataExtractor::ParseJsonModule(JSThread *thread, c
defaultName, LocalExportEntry::LOCAL_DEFAULT_INDEX);
SourceTextModule::AddLocalExportEntry(thread, moduleRecord, localExportEntry, 0, 1); // 1 means len
JSTaggedValue jsonData = JsonParse(thread, jsPandaFile, recordName);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
moduleRecord->StoreModuleValue(thread, 0, JSHandle<JSTaggedValue>(thread, jsonData)); // index = 0
JSHandle<EcmaString> ecmaModuleFilename = factory->NewFromUtf8(moduleFilename);

View File

@ -29,12 +29,12 @@ CString ModulePathHelper::ConcatFileNameWithMerge(JSThread *thread, const JSPand
// requestName: @package:pkg_modules@namespace/xxx/Index
entryPoint = requestName.substr(PREFIX_PACKAGE_LEN);
} else if (IsImportFile(requestName)) {
// this branch save for require/dynamic import/old version sdk
// this branch save for cjs, dynamic import and old-version's sdk
// load a relative pathName.
// requestName: ./ || ./xxx/xxx.js || ../xxx/xxx.js || ./xxx/xxx
entryPoint = MakeNewRecord(jsPandaFile, baseFileName, recordName, requestName);
} else {
// this branch save for require/dynamic import/old version sdk
// this branch save for cjs, dynamic import and old-version's sdk
// requestName: requestPkgName
entryPoint = ParseThirdPartyPackage(jsPandaFile, recordName, requestName);
}

View File

@ -905,57 +905,18 @@ bool JSNApi::ExecuteModuleFromBuffer(EcmaVM *vm, const void *data, int32_t size,
Local<ObjectRef> JSNApi::GetExportObject(EcmaVM *vm, const std::string &file, const std::string &key)
{
CHECK_HAS_PENDING_EXCEPTION_RETURN_UNDEFINED(vm);
ecmascript::CString entry = file.c_str();
JSThread *thread = vm->GetJSThread();
ecmascript::CString name = vm->GetAssetPath();
if (!vm->IsBundlePack()) {
ModulePathHelper::ParseOhmUrl(vm, entry, name, entry);
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, name, entry.c_str(), false);
if (jsPandaFile == nullptr) {
JSHandle<JSTaggedValue> exportObj(thread, JSTaggedValue::Null());
return JSNApiHelper::ToLocal<ObjectRef>(exportObj);
}
if (!jsPandaFile->IsRecordWithBundleName()) {
PathHelper::AdaptOldIsaRecord(entry);
}
}
ecmascript::ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<ecmascript::SourceTextModule> ecmaModule = moduleManager->HostGetImportedModule(entry);
if (ecmaModule->GetIsNewBcVersion()) {
int index = ecmascript::ModuleManager::GetExportObjectIndex(vm, ecmaModule, key);
JSTaggedValue result = ecmaModule->GetModuleValue(thread, index, false);
JSHandle<JSTaggedValue> exportObj(thread, result);
return JSNApiHelper::ToLocal<ObjectRef>(exportObj);
}
ObjectFactory *factory = vm->GetFactory();
JSHandle<EcmaString> keyHandle = factory->NewFromASCII(key.c_str());
JSTaggedValue result = ecmaModule->GetModuleValue(thread, keyHandle.GetTaggedValue(), false);
JSHandle<JSTaggedValue> exportObj(thread, result);
ecmascript::ModuleManager *moduleManager = vm->GetAssociatedJSThread()->GetCurrentEcmaContext()->GetModuleManager();
JSTaggedValue result = moduleManager->GetExportObject(file.c_str(), key.c_str());
JSHandle<JSTaggedValue> exportObj(vm->GetJSThread(), result);
return JSNApiHelper::ToLocal<ObjectRef>(exportObj);
}
Local<ObjectRef> JSNApi::GetExportObjectFromBuffer(EcmaVM *vm, const std::string &file,
const std::string &key)
{
CHECK_HAS_PENDING_EXCEPTION_RETURN_UNDEFINED(vm);
JSThread *thread = vm->GetJSThread();
ecmascript::ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<ecmascript::SourceTextModule> ecmaModule = moduleManager->HostGetImportedModule(file.c_str());
if (ecmaModule->GetIsNewBcVersion()) {
int index = ecmascript::ModuleManager::GetExportObjectIndex(vm, ecmaModule, key);
JSTaggedValue result = ecmaModule->GetModuleValue(thread, index, false);
JSHandle<JSTaggedValue> exportObj(thread, result);
return JSNApiHelper::ToLocal<ObjectRef>(exportObj);
}
ObjectFactory *factory = vm->GetFactory();
JSHandle<EcmaString> keyHandle = factory->NewFromASCII(key.c_str());
JSTaggedValue result = ecmaModule->GetModuleValue(thread, keyHandle.GetTaggedValue(), false);
JSHandle<JSTaggedValue> exportObj(thread, result);
ecmascript::ModuleManager *moduleManager = vm->GetAssociatedJSThread()->GetCurrentEcmaContext()->GetModuleManager();
JSTaggedValue result = moduleManager->GetExportObjectFromBuffer(file.c_str(), key.c_str());
JSHandle<JSTaggedValue> exportObj(vm->GetJSThread(), result);
return JSNApiHelper::ToLocal<ObjectRef>(exportObj);
}
@ -1841,7 +1802,7 @@ Local<StringRef> FunctionRef::GetSourceCode(const EcmaVM *vm, int lineNumber)
const JSPandaFile *jsPandaFile = method->GetJSPandaFile();
DebugInfoExtractor *debugExtractor = JSPandaFileManager::GetInstance()->GetJSPtExtractor(jsPandaFile);
ecmascript::CString entry = JSPandaFile::ENTRY_FUNCTION_NAME;
if (!jsPandaFile->IsBundlePack()) {
if (jsPandaFile->IsMergedPF()) {
JSFunction *function = JSFunction::Cast(func.GetTaggedValue().GetTaggedObject());
JSTaggedValue recordName = function->GetRecordName();
ASSERT(!recordName.IsHole());
@ -3623,7 +3584,7 @@ bool JSNApi::InitForConcurrentFunction(EcmaVM *vm, Local<JSValueRef> function, v
ecmascript::ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
JSHandle<ecmascript::JSTaggedValue> moduleRecord;
// check compileMode
if (jsPandaFile->IsBundlePack()) {
if (!jsPandaFile->IsMergedPF()) {
LOG_ECMA(DEBUG) << "CompileMode is jsbundle";
moduleRecord = moduleManager->HostResolveImportedModule(moduleName);
} else {

View File

@ -28,7 +28,7 @@ PatchErrorCode PatchLoader::LoadPatchInternal(JSThread *thread, const JSPandaFil
EcmaVM *vm = thread->GetEcmaVM();
// hot reload and hot patch only support merge-abc file.
if (baseFile->IsBundlePack() || patchFile->IsBundlePack()) {
if (!baseFile->IsMergedPF() || !patchFile->IsMergedPF()) {
LOG_ECMA(ERROR) << "base or patch is not merge abc!";
return PatchErrorCode::PACKAGE_NOT_ESMODULE;
}

View File

@ -103,7 +103,7 @@ JSHandle<JSTaggedValue> CjsModule::Load(JSThread *thread, JSHandle<EcmaString> &
CString requestEntryPoint = JSPandaFile::ENTRY_MAIN_FUNCTION;
JSMutableHandle<JSTaggedValue> filename(thread, JSTaggedValue::Undefined());
if (jsPandaFile->IsBundlePack()) {
if (!jsPandaFile->IsMergedPF()) {
ModulePathHelper::ResolveCurrentPath(thread, parent, dirname, jsPandaFile);
filename.Update(ResolveFilenameFromNative(thread, dirname.GetTaggedValue(),
request.GetTaggedValue()));
@ -142,6 +142,7 @@ JSHandle<JSTaggedValue> CjsModule::Load(JSThread *thread, JSHandle<EcmaString> &
if (jsPandaFile->IsJson(recordInfo)) {
JSHandle<JSTaggedValue> result = JSHandle<JSTaggedValue>(thread,
ModuleDataExtractor::JsonParse(thread, jsPandaFile, requestEntryPoint));
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
// Set module.exports ---> exports
JSHandle<JSTaggedValue> exportsKey = thread->GlobalConstants()->GetHandledCjsExportsString();
SlowRuntimeStub::StObjByName(thread, module.GetTaggedValue(), exportsKey.GetTaggedValue(),

View File

@ -37,7 +37,6 @@
#include "ecmascript/jspandafile/class_info_extractor.h"
#include "ecmascript/jspandafile/literal_data_extractor.h"
#include "ecmascript/jspandafile/scope_info_extractor.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/js_module_source_text.h"
#include "ecmascript/platform/file.h"
#include "ecmascript/stackmap/llvm_stackmap_parser.h"
@ -821,7 +820,7 @@ JSTaggedValue RuntimeStubs::RuntimeCreateClassWithBuffer(JSThread *thread,
{
[[maybe_unused]] EcmaHandleScope handleScope(thread);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
CString entry = ModuleManager::GetRecordName(module.GetTaggedValue());
CString entry = SourceTextModule::GetRecordName(module.GetTaggedValue());
// For class constructor.
auto methodObj = ConstantPool::GetMethodFromCache(thread, constpool.GetTaggedValue(), methodId);
@ -1385,7 +1384,7 @@ JSTaggedValue RuntimeStubs::RuntimeDynamicImport(JSThread *thread, const JSHandl
JSMutableHandle<JSTaggedValue> dirPath(thread, thread->GlobalConstants()->GetUndefined());
JSMutableHandle<JSTaggedValue> recordName(thread, thread->GlobalConstants()->GetUndefined());
if (jsPandaFile->IsBundlePack()) {
if (!jsPandaFile->IsMergedPF()) {
dirPath.Update(factory->NewFromUtf8(currentfilename).GetTaggedValue());
} else {
JSFunction *function = JSFunction::Cast(func.GetTaggedValue().GetTaggedObject());