!7522 Optimize HostResolveImportedModule

Merge pull request !7522 from yaochaonan/convert
This commit is contained in:
openharmony_ci 2024-06-09 10:49:51 +00:00 committed by Gitee
commit 8e542b7c9a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 109 additions and 75 deletions

View File

@ -86,11 +86,10 @@ public:
return u16str;
}
static inline std::string Utf8ToString(const uint8_t *utf8Data, uint32_t dataLen)
static inline void Utf8ToString(const uint8_t *utf8Data, uint32_t dataLen, std::string& str)
{
auto *charData = reinterpret_cast<const char *>(utf8Data);
std::string str(charData, dataLen);
return str;
str.append(charData, 0, dataLen); // 0: start
}
static inline std::u16string Utf8ToU16String(const uint8_t *utf8Data, uint32_t dataLen)

View File

@ -153,8 +153,8 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv)
// 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());
CString fileNameStr = ModulePathHelper::Utf8ConvertToString(dirPath.GetTaggedValue());
CString requestPath = ModulePathHelper::Utf8ConvertToString(specifierString.GetTaggedValue());
LOG_ECMA(DEBUG) << "Start importing dynamic module : " << requestPath;
if (thread->GetEcmaVM()->GetJSOptions().EnableESMTrace()) {
CString traceInfo = "DynamicImportJob: " + requestPath;
@ -163,7 +163,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv)
std::shared_ptr<JSPandaFile> curJsPandaFile;
CString recordNameStr;
if (!recordName->IsUndefined()) {
recordNameStr = ConvertToString(recordName.GetTaggedValue());
recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue());
curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileNameStr, recordNameStr.c_str());
if (curJsPandaFile == nullptr) {
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << recordNameStr;
@ -191,7 +191,8 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv)
moduleName.Update(ResolveFilenameFromNative(thread, dirPath.GetTaggedValue(),
specifierString.GetTaggedValue()).GetTaggedValue());
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject));
fileNameStr = ConvertToString(moduleName.GetTaggedValue());
fileNameStr =
ModulePathHelper::Utf8ConvertToString(moduleName.GetTaggedValue());
} else {
entryPoint =
ModulePathHelper::ConcatFileNameWithMerge(thread, curJsPandaFile.get(),

View File

@ -437,7 +437,7 @@ void EcmaContext::CJSExecution(JSHandle<JSFunction> &func, JSHandle<JSTaggedValu
} else {
filename.Update(func->GetModule());
ASSERT(filename->IsString());
CString fullName = ConvertToString(filename.GetTaggedValue());
CString fullName = ModulePathHelper::Utf8ConvertToString(filename.GetTaggedValue());
dirname.Update(PathHelper::ResolveDirPath(thread_, fullName));
}
CJSInfo cjsInfo(module, require, exports, filename, dirname);

View File

@ -1329,6 +1329,19 @@ std::string EcmaStringAccessor::ToStdString(StringConvertedUsage usage)
return res;
}
CString EcmaStringAccessor::Utf8ConvertToString()
{
std::string stdStr;
if (IsLineString()) {
base::StringHelper::Utf8ToString(GetDataUtf8(), GetLength(), stdStr);
return stdStr.c_str();
}
CVector<uint8_t> buf;
const uint8_t *data = EcmaString::GetUtf8DataFlat(string_, buf);
base::StringHelper::Utf8ToString(data, GetLength(), stdStr);
return stdStr.c_str();
}
std::string EcmaStringAccessor::DebuggerToStdString(StringConvertedUsage usage)
{
if (string_ == nullptr) {

View File

@ -1240,6 +1240,9 @@ public:
// if string is not flat, this func has low efficiency.
std::string ToStdString(StringConvertedUsage usage = StringConvertedUsage::PRINT);
// this function convert for Utf8
CString Utf8ConvertToString();
std::string DebuggerToStdString(StringConvertedUsage usage = StringConvertedUsage::PRINT);
// not change string data structure.
// if string is not flat, this func has low efficiency.

View File

@ -1049,8 +1049,8 @@ std::pair<std::string, std::string> EcmaVM::GetCurrentModuleInfo(bool needRecord
{
std::pair<JSTaggedValue, JSTaggedValue> moduleInfo = EcmaInterpreter::GetCurrentEntryPoint(thread_);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, std::make_pair("", ""));
CString recordName = ConvertToString(moduleInfo.first);
CString fileName = ConvertToString(moduleInfo.second);
CString recordName = ModulePathHelper::Utf8ConvertToString(moduleInfo.first);
CString fileName = ModulePathHelper::Utf8ConvertToString(moduleInfo.second);
LOG_FULL(INFO) << "Current recordName is " << recordName <<", current fileName is " << fileName;
if (needRecordName) {
if (fileName.length() > ModulePathHelper::BUNDLE_INSTALL_PATH_LEN &&

View File

@ -20,6 +20,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"
namespace panda::ecmascript {
using PathHelper = base::PathHelper;
@ -39,11 +40,12 @@ JSTaggedValue DynamicImport::ExecuteNativeOrJsonModule(JSThread *thread, JSHandl
moduleManager->HostGetImportedModule(specifierString.GetTaggedValue());
requiredModule.Update(moduleRecord);
} else {
CString requestPath = ConvertToString(specifierString.GetTaggedValue());
CString requestPath = ModulePathHelper::Utf8ConvertToString(specifierString.GetTaggedValue());
JSHandle<SourceTextModule> moduleRecord(thread, thread->GlobalConstants()->GetUndefined());
if (moduleType != ModuleTypes::JSON_MODULE) {
// nativeModule
JSHandle<JSTaggedValue> nativeModuleHld = moduleManager->ResolveNativeModule(requestPath, "", moduleType);
JSHandle<JSTaggedValue> nativeModuleHld =
moduleManager->ResolveNativeModule(JSHandle<JSTaggedValue>::Cast(specifierString), "", moduleType);
moduleRecord = JSHandle<SourceTextModule>::Cast(nativeModuleHld);
if (!SourceTextModule::LoadNativeModule(thread, moduleRecord, moduleType)) {
LOG_FULL(ERROR) << " dynamically loading native module" << requestPath << " failed";

View File

@ -333,7 +333,8 @@ bool ModuleManager::IsLocalModuleLoaded(JSTaggedValue referencing)
bool ModuleManager::IsSharedModuleLoaded(JSTaggedValue referencing)
{
SharedModuleManager* sharedModuleManager = SharedModuleManager::GetInstance();
return sharedModuleManager->SearchInSModuleManager(vm_->GetJSThread(), ConvertToString(referencing));
return sharedModuleManager->SearchInSModuleManager(vm_->GetJSThread(),
ModulePathHelper::Utf8ConvertToString(referencing));
}
bool ModuleManager::IsModuleLoaded(JSTaggedValue referencing)
@ -342,7 +343,8 @@ bool ModuleManager::IsModuleLoaded(JSTaggedValue referencing)
return true;
}
SharedModuleManager* sharedModuleManager = SharedModuleManager::GetInstance();
return sharedModuleManager->SearchInSModuleManager(vm_->GetJSThread(), ConvertToString(referencing));
return sharedModuleManager->SearchInSModuleManager(vm_->GetJSThread(),
ModulePathHelper::Utf8ConvertToString(referencing));
}
bool ModuleManager::IsEvaluatedModule(JSTaggedValue referencing)
@ -362,12 +364,13 @@ bool ModuleManager::IsEvaluatedModule(JSTaggedValue referencing)
}
JSHandle<JSTaggedValue> ModuleManager::ResolveModuleInMergedABC(JSThread *thread, const JSPandaFile *jsPandaFile,
const CString &recordName, bool executeFromJob)
const JSHandle<EcmaString> recordName, bool executeFromJob)
{
// In static parse Phase, due to lack of some parameters, we will create a empty SourceTextModule which will
// be marked as INSTANTIATED to skip Dfs traversal of this import branch.
CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue());
if (!vm_->EnableReportModuleResolvingFailure() && (jsPandaFile == nullptr ||
(jsPandaFile != nullptr && !jsPandaFile->HasRecord(recordName)))) {
(jsPandaFile != nullptr && !jsPandaFile->HasRecord(recordNameStr)))) {
return CreateEmptyModule();
} else {
return ResolveModuleWithMerge(thread, jsPandaFile, recordName, executeFromJob);
@ -383,22 +386,23 @@ JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModuleWithMerge(const
if (entry != -1) {
return JSHandle<JSTaggedValue>(vm_->GetJSThread(), dict->GetValue(entry));
}
return CommonResolveImportedModuleWithMerge(moduleFileName, recordName, executeFromJob);
return CommonResolveImportedModuleWithMerge(moduleFileName, recordNameHandle, executeFromJob);
}
JSHandle<JSTaggedValue> ModuleManager::HostResolveImportedModuleWithMergeForHotReload(const CString &moduleFileName,
const CString &recordName, bool executeFromJob)
{
return CommonResolveImportedModuleWithMerge(moduleFileName, recordName, executeFromJob);
JSHandle<EcmaString> recordNameHandle = vm_->GetFactory()->NewFromUtf8(recordName);
return CommonResolveImportedModuleWithMerge(moduleFileName, recordNameHandle, executeFromJob);
}
JSHandle<JSTaggedValue> ModuleManager::CommonResolveImportedModuleWithMerge(const CString &moduleFileName,
const CString &recordName, bool executeFromJob)
const JSHandle<EcmaString> recordName, bool executeFromJob)
{
JSThread *thread = vm_->GetJSThread();
CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue());
std::shared_ptr<JSPandaFile> jsPandaFile = ModulePathHelper::SkipDefaultBundleFile(thread, moduleFileName) ?
nullptr : JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, recordName, false);
nullptr : JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, recordNameStr, false);
if (jsPandaFile == nullptr) {
// In Aot Module Instantiate, we miss some runtime parameters from framework like bundleName or moduleName
// which may cause wrong recordName parsing and we also can't load files not in this app hap. But in static
@ -411,8 +415,7 @@ JSHandle<JSTaggedValue> ModuleManager::CommonResolveImportedModuleWithMerge(cons
jsPandaFile.get(), recordName, executeFromJob);
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
JSHandle<NameDictionary> handleDict(thread, resolvedModules_);
JSHandle<EcmaString> recordNameHandle= vm_->GetFactory()->NewFromUtf8(recordName);
resolvedModules_ = NameDictionary::Put(thread, handleDict, JSHandle<JSTaggedValue>(recordNameHandle),
resolvedModules_ = NameDictionary::Put(thread, handleDict, JSHandle<JSTaggedValue>(recordName),
moduleRecord, PropertyAttributes::Default()).GetTaggedValue();
return moduleRecord;
@ -511,46 +514,43 @@ JSHandle<JSTaggedValue> ModuleManager::ResolveModule(JSThread *thread, const JSP
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleManager::ResolveNativeModule(const CString &moduleRequestName,
JSHandle<JSTaggedValue> ModuleManager::ResolveNativeModule(const JSHandle<JSTaggedValue> moduleRequest,
const CString &baseFileName, ModuleTypes moduleType)
{
ObjectFactory *factory = vm_->GetFactory();
JSThread *thread = vm_->GetJSThread();
JSHandle<JSTaggedValue> referencingModule(factory->NewFromUtf8(moduleRequestName));
CString moduleRequestName = ModulePathHelper::Utf8ConvertToString(moduleRequest.GetTaggedValue());
JSHandle<JSTaggedValue> moduleRecord = ModuleDataExtractor::ParseNativeModule(thread,
moduleRequestName, baseFileName, moduleType);
JSHandle<NameDictionary> dict(thread, resolvedModules_);
resolvedModules_ = NameDictionary::Put(thread, dict, referencingModule, moduleRecord,
resolvedModules_ = NameDictionary::Put(thread, dict, moduleRequest, moduleRecord,
PropertyAttributes::Default()).GetTaggedValue();
return moduleRecord;
}
JSHandle<JSTaggedValue> ModuleManager::ResolveModuleWithMerge(
JSThread *thread, const JSPandaFile *jsPandaFile, const CString &recordName, bool executeFromJob)
JSThread *thread, const JSPandaFile *jsPandaFile, const JSHandle<EcmaString> recordName, bool executeFromJob)
{
ObjectFactory *factory = vm_->GetFactory();
CString moduleFileName = jsPandaFile->GetJSPandaFileDesc();
JSHandle<JSTaggedValue> moduleRecord = thread->GlobalConstants()->GetHandledUndefined();
CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue());
JSRecordInfo recordInfo;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(recordName, recordInfo);
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(recordNameStr, recordInfo);
if (!hasRecord) {
JSHandle<JSTaggedValue> exp(thread, JSTaggedValue::Exception());
THROW_MODULE_NOT_FOUND_ERROR_WITH_RETURN_VALUE(thread, recordName, moduleFileName, exp);
THROW_MODULE_NOT_FOUND_ERROR_WITH_RETURN_VALUE(thread, recordNameStr, moduleFileName, exp);
}
if (jsPandaFile->IsModule(recordInfo)) {
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
moduleRecord = ModuleDataExtractor::ParseModule(thread, jsPandaFile, recordName, moduleFileName);
moduleRecord = ModuleDataExtractor::ParseModule(thread, jsPandaFile, recordNameStr, moduleFileName);
} else if (jsPandaFile->IsJson(recordInfo)) {
moduleRecord = ModuleDataExtractor::ParseJsonModule(thread, jsPandaFile, moduleFileName, recordName);
moduleRecord = ModuleDataExtractor::ParseJsonModule(thread, jsPandaFile, moduleFileName, recordNameStr);
} else {
ASSERT(jsPandaFile->IsCjs(recordInfo));
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
moduleRecord = ModuleDataExtractor::ParseCjsModule(thread, jsPandaFile);
}
JSHandle<JSTaggedValue> recordNameHandle = JSHandle<JSTaggedValue>::Cast(factory->NewFromUtf8(recordName));
JSHandle<SourceTextModule>::Cast(moduleRecord)->SetEcmaModuleRecordName(thread, recordNameHandle);
JSHandle<SourceTextModule>::Cast(moduleRecord)->SetEcmaModuleRecordName(thread, recordName);
ModuleDeregister::InitForDeregisterModule(moduleRecord, executeFromJob);
return moduleRecord;
}
@ -678,12 +678,13 @@ CString ModuleManager::GetRecordName(JSTaggedValue module)
{
CString entry = "";
if (module.IsString()) {
entry = ConvertToString(module);
entry = ModulePathHelper::Utf8ConvertToString(module);
}
if (module.IsSourceTextModule()) {
SourceTextModule *sourceTextModule = SourceTextModule::Cast(module.GetTaggedObject());
if (sourceTextModule->GetEcmaModuleRecordName().IsString()) {
entry = ConvertToString(sourceTextModule->GetEcmaModuleRecordName());
JSTaggedValue recordName = sourceTextModule->GetEcmaModuleRecordName();
if (recordName.IsString()) {
entry = ModulePathHelper::Utf8ConvertToString(recordName);
}
}
return entry;
@ -758,14 +759,14 @@ JSHandle<JSTaggedValue> ModuleManager::ExecuteNativeModule(JSThread *thread, con
JSHandle<SourceTextModule> moduleRecord = HostGetImportedModule(record.GetTaggedValue());
requiredModule.Update(moduleRecord);
} else {
CString requestPath = ConvertToString(record.GetTaggedValue());
CString entryPoint = PathHelper::GetStrippedModuleName(requestPath);
auto [isNative, moduleType] = SourceTextModule::CheckNativeModule(requestPath);
JSHandle<JSTaggedValue> nativeModuleHandle = ResolveNativeModule(requestPath, "", moduleType);
CString entryPoint = PathHelper::GetStrippedModuleName(recordName.c_str());
auto [isNative, moduleType] = SourceTextModule::CheckNativeModule(recordName.c_str());
JSHandle<JSTaggedValue> nativeModuleHandle =
ResolveNativeModule(JSHandle<JSTaggedValue>::Cast(record), "", moduleType);
JSHandle<SourceTextModule> nativeModule =
JSHandle<SourceTextModule>::Cast(nativeModuleHandle);
if (!SourceTextModule::LoadNativeModule(thread, nativeModule, moduleType)) {
LOG_FULL(ERROR) << "loading native module " << requestPath << " failed";
LOG_FULL(ERROR) << "loading native module " << recordName << " failed";
}
nativeModule->SetStatus(ModuleStatus::EVALUATED);
nativeModule->SetLoadingTypes(LoadingTypes::STABLE_MODULE);

View File

@ -65,8 +65,8 @@ public:
bool IsEvaluatedModule(JSTaggedValue referencing);
JSHandle<JSTaggedValue> ResolveNativeModule(const CString &moduleRequestName, const CString &baseFileName,
ModuleTypes moduleType);
JSHandle<JSTaggedValue> ResolveNativeModule(const JSHandle<JSTaggedValue> 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);
@ -118,7 +118,7 @@ private:
NO_MOVE_SEMANTIC(ModuleManager);
JSHandle<JSTaggedValue> ResolveModuleInMergedABC(JSThread *thread, const JSPandaFile *jsPandaFile,
const CString &recordName, bool executeFromJob = false);
const JSHandle<EcmaString> recordName, bool executeFromJob = false);
JSHandle<JSTaggedValue> CreateEmptyModule();
JSTaggedValue GetModuleValueOutterInternal(int32_t index, JSTaggedValue currentModule);
void StoreModuleValueInternal(JSHandle<SourceTextModule> &currentModule,
@ -134,10 +134,10 @@ private:
bool executeFromJob = false);
JSHandle<JSTaggedValue> ResolveModuleWithMerge(JSThread *thread, const JSPandaFile *jsPandaFile,
const CString &recordName, bool executeFromJob = false);
const JSHandle<EcmaString> recordName, bool executeFromJob = false);
JSHandle<JSTaggedValue> CommonResolveImportedModuleWithMerge(const CString &moduleFileName,
const CString &recordName, bool executeFromJob = false);
const JSHandle<EcmaString> recordName, bool executeFromJob = false);
void AddToInstantiatingSModuleList(const CString &record);

View File

@ -91,7 +91,7 @@ CVector<std::string> SourceTextModule::GetExportedNames(JSThread *thread, const
JSHandle<JSTaggedValue> SourceTextModule::HostResolveImportedModuleWithMerge(JSThread *thread,
const JSHandle<SourceTextModule> &module, const JSHandle<JSTaggedValue> &moduleRequest, bool executeFromJob)
{
CString moduleRequestName = ConvertToString(moduleRequest.GetTaggedValue());
CString moduleRequestName = ModulePathHelper::Utf8ConvertToString(moduleRequest.GetTaggedValue());
JSHandle<JSTaggedValue> moduleRequestStr = ReplaceModuleThroughFeature(thread, moduleRequestName);
CString baseFilename;
@ -99,7 +99,7 @@ JSHandle<JSTaggedValue> SourceTextModule::HostResolveImportedModuleWithMerge(JST
baseFilename = thread->GetEcmaVM()->GetQuickFixManager()->GetCurrentBaseFileName();
} else {
ASSERT(module->GetEcmaModuleFilename().IsHeapObject());
baseFilename = ConvertToString(module->GetEcmaModuleFilename());
baseFilename = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename());
}
auto moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
@ -108,10 +108,10 @@ JSHandle<JSTaggedValue> SourceTextModule::HostResolveImportedModuleWithMerge(JST
if (moduleManager->IsLocalModuleLoaded(moduleRequestStr.GetTaggedValue())) {
return JSHandle<JSTaggedValue>(moduleManager->HostGetImportedModule(moduleRequestStr.GetTaggedValue()));
}
return moduleManager->ResolveNativeModule(moduleRequestName, baseFilename, moduleType);
return moduleManager->ResolveNativeModule(moduleRequest, baseFilename, moduleType);
}
ASSERT(module->GetEcmaModuleRecordName().IsHeapObject());
CString recordName = ConvertToString(module->GetEcmaModuleRecordName());
CString recordName = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleRecordName());
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFilename, recordName);
if (jsPandaFile == nullptr) {
@ -145,12 +145,12 @@ JSHandle<JSTaggedValue> SourceTextModule::HostResolveImportedModule(JSThread *th
}
JSHandle<EcmaString> dirname = base::PathHelper::ResolveDirPath(thread,
ConvertToString(module->GetEcmaModuleFilename()));
ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename()));
JSHandle<EcmaString> moduleFilename = ResolveFilenameFromNative(thread, dirname.GetTaggedValue(),
moduleRequest.GetTaggedValue());
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
return SharedModuleManager::GetInstance()->ResolveImportedModule(thread,
ConvertToString(moduleFilename.GetTaggedValue()), executeFromJob);
ModulePathHelper::Utf8ConvertToString(moduleFilename.GetTaggedValue()), executeFromJob);
}
bool SourceTextModule::CheckCircularImport(const JSHandle<SourceTextModule> &module,
@ -413,14 +413,16 @@ bool SourceTextModule::LoadNativeModule(JSThread *thread, const JSHandle<SourceT
EcmaVM *vm = thread->GetEcmaVM();
[[maybe_unused]] LocalScope scope(vm);
CString moduleRequestName = ConvertToString(EcmaString::Cast(requiredModule->GetEcmaModuleRecordName()));
CString moduleRequestName =
ModulePathHelper::Utf8ConvertToString(requiredModule->GetEcmaModuleRecordName());
if (thread->GetEcmaVM()->GetJSOptions().EnableESMTrace()) {
CString traceInfo = "LoadNativeModule: " + moduleRequestName;
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, traceInfo.c_str());
}
CString soName = PathHelper::GetStrippedModuleName(moduleRequestName);
CString fileName = ConvertToString(EcmaString::Cast(requiredModule->GetEcmaModuleFilename()));
CString fileName =
ModulePathHelper::Utf8ConvertToString(requiredModule->GetEcmaModuleFilename());
CString moduleName = ModulePathHelper::GetModuleNameWithBaseFile(fileName);
std::vector<Local<JSValueRef>> arguments;
LOG_FULL(DEBUG) << "Request module is " << moduleRequestName;
@ -464,8 +466,8 @@ void SourceTextModule::InstantiateNativeModule(JSThread *thread, JSHandle<Source
{
if (requiredModule->GetStatus() != ModuleStatus::EVALUATED) {
if (!SourceTextModule::LoadNativeModule(thread, requiredModule, moduleType)) {
LOG_FULL(WARN) << "LoadNativeModule " << ConvertToString(
EcmaString::Cast(moduleRequest->GetTaggedObject())) << " failed";
LOG_FULL(WARN) << "LoadNativeModule " <<
ModulePathHelper::Utf8ConvertToString(moduleRequest.GetTaggedValue()) << " failed";
return;
}
}
@ -514,11 +516,13 @@ void SourceTextModule::InitializeEnvironment(JSThread *thread, const JSHandle<So
SourceTextModule::ResolveExportObject(thread, requestedModule, exports, importName);
// ii. If resolution is null or "ambiguous", throw a SyntaxError exception.
if (resolution->IsNull() || resolution->IsString()) {
CString requestMod = ModulePathHelper::ReformatPath(ConvertToString(host->GetModuleRequest()));
CString recordStr = ModulePathHelper::ReformatPath(ConvertToString(
currentModule->GetEcmaModuleRecordName()));
CString requestMod = ModulePathHelper::ReformatPath(
ModulePathHelper::Utf8ConvertToString(host->GetModuleRequest()));
CString recordStr = ModulePathHelper::ReformatPath(
ModulePathHelper::Utf8ConvertToString(currentModule->GetEcmaModuleRecordName()));
CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) +
ConvertToString(importName.GetTaggedValue()) + "' which imported by '" + recordStr + "'";
ModulePathHelper::Utf8ConvertToString(importName.GetTaggedValue()) +
"' which imported by '" + recordStr + "'";
THROW_ERROR(thread, ErrorType::SYNTAX_ERROR, msg.c_str());
}
// iii. Call envRec.CreateImportBinding(
@ -1354,7 +1358,8 @@ Expected<JSTaggedValue, bool> SourceTextModule::ModuleExecution(JSThread *thread
{
JSTaggedValue moduleFileName = module->GetEcmaModuleFilename();
ASSERT(moduleFileName.IsString());
CString moduleFilenameStr = ConvertToString(EcmaString::Cast(moduleFileName.GetTaggedObject()));
CString moduleFilenameStr =
ModulePathHelper::Utf8ConvertToString(moduleFileName);
std::string entryPoint;
JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName();
@ -1362,7 +1367,7 @@ Expected<JSTaggedValue, bool> SourceTextModule::ModuleExecution(JSThread *thread
entryPoint = JSPandaFile::ENTRY_FUNCTION_NAME;
} else {
ASSERT(moduleRecordName.IsString());
entryPoint = ConvertToString(moduleRecordName);
entryPoint = ModulePathHelper::Utf8ConvertToString(moduleRecordName);
}
std::shared_ptr<JSPandaFile> jsPandaFile;
@ -1918,7 +1923,8 @@ void SourceTextModule::ExecuteAsyncModule(JSThread *thread, const JSHandle<Sourc
ASSERT(module->GetHasTLA());
JSTaggedValue moduleFileName = module->GetEcmaModuleFilename();
ASSERT(moduleFileName.IsString());
CString moduleFilenameStr = ConvertToString(EcmaString::Cast(moduleFileName.GetTaggedObject()));
CString moduleFilenameStr =
ModulePathHelper::Utf8ConvertToString(moduleFileName);
std::string entryPoint;
JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName();
@ -1926,7 +1932,7 @@ void SourceTextModule::ExecuteAsyncModule(JSThread *thread, const JSHandle<Sourc
entryPoint = JSPandaFile::ENTRY_FUNCTION_NAME;
} else {
ASSERT(moduleRecordName.IsString());
entryPoint = ConvertToString(moduleRecordName);
entryPoint = ModulePathHelper::Utf8ConvertToString(moduleRecordName);
}
std::shared_ptr<JSPandaFile> jsPandaFile;
@ -2222,7 +2228,8 @@ void SourceTextModule::SearchCircularImport(JSThread *thread, const CString &cir
requiredModule.Update(JSHandle<SourceTextModule>::Cast(
SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required)));
RETURN_IF_ABRUPT_COMPLETION(thread);
requiredModuleName = ConvertToString(requiredModule->GetEcmaModuleRecordName());
requiredModuleName =
ModulePathHelper::Utf8ConvertToString(requiredModule->GetEcmaModuleRecordName());
referenceList.push_back(requiredModuleName);
if (requiredModuleName == circularModuleRecordName) {
PrintCircular(referenceList, ERROR);
@ -2286,11 +2293,11 @@ std::tuple<bool, JSHandle<SourceTextModule>> SourceTextModule::GetResolvedModule
const JSHandle<SourceTextModule> &module, const JSHandle<JSTaggedValue> &moduleRequest)
{
JSHandle<EcmaString> dirname = base::PathHelper::ResolveDirPath(thread,
ConvertToString(module->GetEcmaModuleFilename()));
ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename()));
JSHandle<EcmaString> moduleFilename = ResolveFilenameFromNative(thread, dirname.GetTaggedValue(),
moduleRequest.GetTaggedValue());
CString fileName = ConvertToString(moduleFilename.GetTaggedValue());
CString fileName = ModulePathHelper::Utf8ConvertToString(moduleFilename.GetTaggedValue());
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, JSPandaFile::ENTRY_MAIN_FUNCTION);
ASSERT(!(jsPandaFile == nullptr));
@ -2308,7 +2315,7 @@ std::tuple<bool, JSHandle<SourceTextModule>> SourceTextModule::GetResolvedModule
std::tuple<bool, JSHandle<SourceTextModule>> SourceTextModule::GetResolvedModuleWithMerge(JSThread *thread,
const JSHandle<SourceTextModule> &module, const JSHandle<JSTaggedValue> &moduleRequest)
{
CString moduleRequestName = ConvertToString(moduleRequest.GetTaggedValue());
CString moduleRequestName = ModulePathHelper::Utf8ConvertToString(moduleRequest.GetTaggedValue());
JSHandle<JSTaggedValue> moduleRequestStr = ReplaceModuleThroughFeature(thread, moduleRequestName);
auto moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
@ -2320,8 +2327,8 @@ std::tuple<bool, JSHandle<SourceTextModule>> SourceTextModule::GetResolvedModule
moduleManager->HostGetImportedModule(moduleRequestStr.GetTaggedValue()));
}
CString baseFilename = ConvertToString(module->GetEcmaModuleFilename());
CString recordName = ConvertToString(module->GetEcmaModuleRecordName());
CString baseFilename = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename());
CString recordName = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleRecordName());
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFilename, recordName);
ASSERT(!(jsPandaFile == nullptr));

View File

@ -236,7 +236,7 @@ void SharedModuleManager::InsertInSModuleManager(JSThread *thread, JSHandle<JSTa
{
RuntimeLockHolder locker(thread, mutex_);
JSHandle<JSTaggedValue> module = JSHandle<JSTaggedValue>::Cast(moduleRecord);
CString recordName = ConvertToString(requireModule.GetTaggedValue());
CString recordName = ModulePathHelper::Utf8ConvertToString(requireModule.GetTaggedValue());
if (!SearchInSModuleManagerUnsafe(thread, recordName)) {
JSHandle<NameDictionary> handleDict(thread, resolvedSharedModules_);
resolvedSharedModules_ =
@ -266,7 +266,8 @@ void SharedModuleManager::TransferSModule(JSThread *thread)
StateVisit &SharedModuleManager::findModuleMutexWithLock(JSThread *thread, const JSHandle<SourceTextModule> &module)
{
RuntimeLockHolder locker(thread, mutex_);
CString moduleName = ConvertToString(SourceTextModule::GetModuleName(module.GetTaggedValue()));
CString moduleName =
ModulePathHelper::Utf8ConvertToString(SourceTextModule::GetModuleName(module.GetTaggedValue()));
auto it = sharedModuleMutex_.find(moduleName);
if (it == sharedModuleMutex_.end()) {
LOG_ECMA(FATAL) << " Get shared module mutex failed";

View File

@ -1043,4 +1043,10 @@ CString ModulePathHelper::GetBundleNameWithRecordName(EcmaVM *vm, const CString
}
return bundleName;
}
// this function convert for ESModule name string(Utf8)
CString ModulePathHelper::Utf8ConvertToString(JSTaggedValue str)
{
return EcmaStringAccessor(str).Utf8ConvertToString();
}
} // namespace panda::ecmascript

View File

@ -192,6 +192,7 @@ public:
[[maybe_unused]] CString &baseFileName, CString &requestPath);
static CString ConcatNormalizedOhmurlWithData(CVector<CString> &data, CString &pkgName, CString &entryPath);
static CString GetBundleNameWithRecordName(EcmaVM *vm, const CString &recordName);
static CString Utf8ConvertToString(JSTaggedValue str);
static inline bool IsSandboxPath(const CString &moduleFileName)
{
return base::StringHelper::StringStartWith(moduleFileName, ModulePathHelper::BUNDLE_INSTALL_PATH);