From a1e281d7fb202a3ac6acee6924c42b87c50f8375 Mon Sep 17 00:00:00 2001 From: chenlincl3 Date: Wed, 17 Jul 2024 18:19:22 +0800 Subject: [PATCH] Optimize source_text_module field to cstirng Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IADOXR Signed-off-by: chenlincl3 --- ecmascript/builtins/builtins_global.cpp | 8 +- ecmascript/debugger/debugger_api.cpp | 8 +- ecmascript/dump.cpp | 6 +- ecmascript/ecma_vm.cpp | 6 +- ecmascript/interpreter/interpreter-inl.cpp | 17 ++- ecmascript/interpreter/interpreter.h | 2 +- ecmascript/js_function.cpp | 6 +- ecmascript/js_function.h | 2 +- ecmascript/module/js_module_deregister.cpp | 27 ++-- ecmascript/module/js_module_manager.cpp | 44 +++--- ecmascript/module/js_module_manager.h | 2 + ecmascript/module/js_module_namespace.cpp | 3 +- ecmascript/module/js_module_source_text.cpp | 134 +++++++----------- ecmascript/module/js_module_source_text.h | 58 +++++++- ecmascript/module/js_shared_module.cpp | 17 +-- .../module/js_shared_module_manager.cpp | 9 +- ecmascript/module/module_data_extractor.cpp | 15 +- ecmascript/module/module_manager_helper.cpp | 30 ++-- ecmascript/module/tests/ecma_module_test.cpp | 3 +- ecmascript/napi/jsnapi_expo.cpp | 6 +- ecmascript/napi/test/jsnapi_second_tests.cpp | 3 +- ecmascript/object_factory.cpp | 4 +- ecmascript/pgo_profiler/pgo_profiler.cpp | 10 +- ecmascript/platform/unix/file.cpp | 2 +- ecmascript/require/js_cjs_module.cpp | 3 +- ecmascript/shared_object_factory.cpp | 4 +- ecmascript/stubs/runtime_stubs-inl.h | 2 +- .../jsvaluerefismodulenamespace_fuzzer.cpp | 3 +- 28 files changed, 218 insertions(+), 216 deletions(-) diff --git a/ecmascript/builtins/builtins_global.cpp b/ecmascript/builtins/builtins_global.cpp index d8d9f45a9b..1d780acb7f 100644 --- a/ecmascript/builtins/builtins_global.cpp +++ b/ecmascript/builtins/builtins_global.cpp @@ -984,10 +984,10 @@ JSTaggedValue BuiltinsGlobal::GetCurrentModuleName(EcmaRuntimeCallInfo *msg) JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, GetCurrentModuleName); [[maybe_unused]] EcmaHandleScope handleScope(thread); - std::pair moduleInfo = EcmaInterpreter::GetCurrentEntryPoint(thread); + std::pair moduleInfo = EcmaInterpreter::GetCurrentEntryPoint(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); EcmaVM *vm = thread->GetEcmaVM(); - CString recordName = ConvertToString(moduleInfo.first); + CString recordName = moduleInfo.first; CString moduleName; if (vm->IsNormalizedOhmUrlPack()) { moduleName = ModulePathHelper::GetModuleNameWithNormalizedName(recordName); @@ -1005,10 +1005,10 @@ JSTaggedValue BuiltinsGlobal::GetCurrentBundleName(EcmaRuntimeCallInfo *msg) JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, GetCurrentBundleName); [[maybe_unused]] EcmaHandleScope handleScope(thread); - std::pair moduleInfo = EcmaInterpreter::GetCurrentEntryPoint(thread); + std::pair moduleInfo = EcmaInterpreter::GetCurrentEntryPoint(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); EcmaVM *vm = thread->GetEcmaVM(); - CString recordName = ConvertToString(moduleInfo.first); + CString recordName = moduleInfo.first; CString bundleName = ModulePathHelper::GetBundleNameWithRecordName(vm, recordName); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle result = factory->NewFromUtf8(bundleName.c_str()); diff --git a/ecmascript/debugger/debugger_api.cpp b/ecmascript/debugger/debugger_api.cpp index 0c251661ac..a5dc9d61f5 100644 --- a/ecmascript/debugger/debugger_api.cpp +++ b/ecmascript/debugger/debugger_api.cpp @@ -764,8 +764,8 @@ void DebuggerApi::GetIndirectExportVariables(const EcmaVM *ecmaVm, Local moduleRequest(thread, ee->GetModuleRequest()); JSHandle importModule; JSHandle module = JSHandle::Cast(currentModule); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { importModule = SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); } else { importModule = SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); @@ -805,8 +805,8 @@ void DebuggerApi::GetImportVariables(const EcmaVM *ecmaVm, Local &mod JSHandle moduleRequest(thread, ee->GetModuleRequest()); JSHandle importModule; JSHandle module = JSHandle::Cast(currentModule); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { importModule = SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); } else { importModule = SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); diff --git a/ecmascript/dump.cpp b/ecmascript/dump.cpp index 1e195a3614..52440253ff 100644 --- a/ecmascript/dump.cpp +++ b/ecmascript/dump.cpp @@ -3699,10 +3699,10 @@ void SourceTextModule::Dump(std::ostream &os) const GetNamespace().Dump(os); os << "\n"; os << " - EcmaModuleFilename: "; - GetEcmaModuleFilename().Dump(os); + os << GetEcmaModuleFilenameString(); os << "\n"; os << " - EcmaModuleRecordName: "; - GetEcmaModuleRecordName().Dump(os); + os << GetEcmaModuleRecordNameString(); os << "\n"; os << " - RequestedModules: "; GetRequestedModules().Dump(os); @@ -5940,8 +5940,6 @@ void SourceTextModule::DumpForSnapshot(std::vector &vec) const vec.reserve(vec.size() + NUM_OF_ITEMS); vec.emplace_back(CString("Environment"), GetEnvironment()); vec.emplace_back(CString("Namespace"), GetNamespace()); - vec.emplace_back(CString("EcmaModuleFilename"), GetEcmaModuleFilename()); - vec.emplace_back(CString("EcmaModuleRecordName"), GetEcmaModuleRecordName()); vec.emplace_back(CString("RequestedModules"), GetRequestedModules()); vec.emplace_back(CString("ImportEntries"), GetImportEntries()); vec.emplace_back(CString("LocalExportEntries"), GetLocalExportEntries()); diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index c663c1b3e9..e91e604429 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -945,10 +945,10 @@ void EcmaVM::ResumeWorkerVm(uint32_t tid) */ std::pair EcmaVM::GetCurrentModuleInfo(bool needRecordName) { - std::pair moduleInfo = EcmaInterpreter::GetCurrentEntryPoint(thread_); + std::pair moduleInfo = EcmaInterpreter::GetCurrentEntryPoint(thread_); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, std::make_pair("", "")); - CString recordName = ModulePathHelper::Utf8ConvertToString(moduleInfo.first); - CString fileName = ModulePathHelper::Utf8ConvertToString(moduleInfo.second); + CString recordName = moduleInfo.first; + CString fileName = moduleInfo.second; LOG_FULL(INFO) << "Current recordName is " << recordName <<", current fileName is " << fileName; if (needRecordName) { if (fileName.length() > ModulePathHelper::BUNDLE_INSTALL_PATH_LEN && diff --git a/ecmascript/interpreter/interpreter-inl.cpp b/ecmascript/interpreter/interpreter-inl.cpp index c3cebbe028..68b261cb0a 100644 --- a/ecmascript/interpreter/interpreter-inl.cpp +++ b/ecmascript/interpreter/interpreter-inl.cpp @@ -969,11 +969,11 @@ const JSPandaFile *EcmaInterpreter::GetNativeCallPandafile(JSThread *thread) UNREACHABLE(); } -std::pair EcmaInterpreter::GetCurrentEntryPoint(JSThread *thread) +std::pair EcmaInterpreter::GetCurrentEntryPoint(JSThread *thread) { FrameHandler frameHandler(thread); - JSMutableHandle recordName(thread, thread->GlobalConstants()->GetUndefined()); - JSMutableHandle fileName(thread, thread->GlobalConstants()->GetUndefined()); + CString recordName; + CString fileName; for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) { if (frameHandler.IsEntryFrame()) { @@ -989,18 +989,17 @@ std::pair EcmaInterpreter::GetCurrentEntryPoint(JS if (module->IsSourceTextModule()) { SourceTextModule *sourceTextModule = SourceTextModule::Cast(module->GetTaggedObject()); - recordName.Update(sourceTextModule->GetEcmaModuleRecordName()); - fileName.Update(sourceTextModule->GetEcmaModuleFilename()); + recordName = sourceTextModule->GetEcmaModuleRecordNameString(); + fileName = sourceTextModule->GetEcmaModuleFilenameString(); } else if (module->IsString()) { - recordName.Update(module); + recordName = ConvertToString(module.GetTaggedValue()); } else { continue; } - return std::make_pair(recordName.GetTaggedValue(), fileName.GetTaggedValue()); + return std::make_pair(recordName, fileName); } CString msg = "Unable to get recordName and fileName due to failure in getting current entry point."; - THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), std::make_pair(JSTaggedValue::Undefined(), - JSTaggedValue::Undefined())); + THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), std::make_pair(recordName, fileName)); } void EcmaInterpreter::UpdateProfileTypeInfoCellToFunction(JSThread *thread, JSHandle &function, diff --git a/ecmascript/interpreter/interpreter.h b/ecmascript/interpreter/interpreter.h index baaa6399db..caca31adc7 100644 --- a/ecmascript/interpreter/interpreter.h +++ b/ecmascript/interpreter/interpreter.h @@ -70,7 +70,7 @@ public: static void MethodEntry(JSThread *thread); static void MethodExit(JSThread *thread); static const JSPandaFile *GetNativeCallPandafile(JSThread *thread); - static std::pair GetCurrentEntryPoint(JSThread *thread); + static std::pair GetCurrentEntryPoint(JSThread *thread); static JSTaggedValue GetFunction(JSTaggedType *sp); static JSTaggedValue GetNewTarget(JSTaggedType *sp); static JSTaggedValue GetThis(JSTaggedType *sp); diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index 1283562ed4..27df095777 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -924,17 +924,17 @@ JSHandle JSFunction::GetOrCreateDerivedJSHClass(JSThread *thread, JSHa return newJSHClass; } -JSTaggedValue JSFunction::GetRecordName() const +CString JSFunction::GetRecordName() const { JSTaggedValue module = GetModule(); if (module.IsSourceTextModule()) { return SourceTextModule::GetModuleName(module); } if (module.IsString()) { - return module; + return ConvertToString(module); } LOG_INTERPRETER(DEBUG) << "record name is undefined"; - return JSTaggedValue::Hole(); + return ""; } // Those interface below is discarded diff --git a/ecmascript/js_function.h b/ecmascript/js_function.h index 5120d97282..a1a25be8ec 100644 --- a/ecmascript/js_function.h +++ b/ecmascript/js_function.h @@ -312,7 +312,7 @@ public: JSTaggedValue GetFunctionExtraInfo() const; JSTaggedValue GetNativeFunctionExtraInfo() const; - JSTaggedValue GetRecordName() const; + CString GetRecordName() const; JSTaggedValue GetProfileTypeInfo() const { JSTaggedValue raw = GetRawProfileTypeInfo(); diff --git a/ecmascript/module/js_module_deregister.cpp b/ecmascript/module/js_module_deregister.cpp index a2454f3389..599f247b8d 100644 --- a/ecmascript/module/js_module_deregister.cpp +++ b/ecmascript/module/js_module_deregister.cpp @@ -47,8 +47,7 @@ void ModuleDeregister::FreeModuleRecord([[maybe_unused]] void *env, void *pointe } JSHandle module(thread, SourceTextModule::Cast(moduleVal.GetTaggedObject())); LoadingTypes type = module->GetLoadingTypes(); - JSTaggedValue moduleRecordName = SourceTextModule::GetModuleName(module.GetTaggedValue()); - CString recordNameStr = ConvertToString(moduleRecordName); + CString recordNameStr = SourceTextModule::GetModuleName(module.GetTaggedValue()); if (type != LoadingTypes::DYNAMITC_MODULE) { LOG_FULL(INFO) << "free stable module's ModuleNameSpace" << recordNameStr; } @@ -87,8 +86,7 @@ void ModuleDeregister::ReviseLoadedModuleCount(JSThread *thread, const CString & void ModuleDeregister::RemoveModule(JSThread *thread, JSHandle module) { - JSTaggedValue moduleRecordName = SourceTextModule::GetModuleName(module.GetTaggedValue()); - CString recordName = ModulePathHelper::Utf8ConvertToString(moduleRecordName); + CString recordName = SourceTextModule::GetModuleName(module.GetTaggedValue()); ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); if (!thread->GetEcmaVM()->IsWorkerThread() && (module->GetTypes() == ModuleTypes::APP_MODULE || module->GetTypes() == ModuleTypes::OHOS_MODULE)) { @@ -111,21 +109,20 @@ void ModuleDeregister::IncreaseRegisterCounts(JSThread *thread, JSHandleGet(idx)); JSMutableHandle requiredModule(thread, thread->GlobalConstants()->GetUndefined()); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); + const CString moduleRecordName = module->GetEcmaModuleRecordNameString(); CString moduleName; - if (moduleRecordName.IsUndefined()) { + if (moduleRecordName.empty()) { JSHandle requiredVal = SourceTextModule::HostResolveImportedModule(thread, module, required); RETURN_IF_ABRUPT_COMPLETION(thread); requiredModule.Update(JSHandle::Cast(requiredVal)); - moduleName = ConvertToString(requiredModule->GetEcmaModuleFilename()); + moduleName = requiredModule->GetEcmaModuleFilenameString(); } else { - ASSERT(moduleRecordName.IsString()); JSHandle requiredVal = SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required); RETURN_IF_ABRUPT_COMPLETION(thread); requiredModule.Update(JSHandle::Cast(requiredVal)); - moduleName = ConvertToString(requiredModule->GetEcmaModuleRecordName()); + moduleName = requiredModule->GetEcmaModuleRecordNameString(); } if (increaseModule.find(moduleName) != increaseModule.end()) { LOG_FULL(DEBUG) << "Find module cyclical loading, stop increasing."; @@ -161,21 +158,20 @@ void ModuleDeregister::DecreaseRegisterCounts(JSThread *thread, JSHandleGet(idx)); JSMutableHandle requiredModule(thread, thread->GlobalConstants()->GetUndefined()); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); + const CString moduleRecordName = module->GetEcmaModuleRecordNameString(); CString moduleName; - if (moduleRecordName.IsUndefined()) { + if (moduleRecordName.empty()) { JSHandle requiredVal = SourceTextModule::HostResolveImportedModule(thread, module, required); RETURN_IF_ABRUPT_COMPLETION(thread); requiredModule.Update(JSHandle::Cast(requiredVal)); - moduleName = ConvertToString(requiredModule->GetEcmaModuleFilename()); + moduleName = requiredModule->GetEcmaModuleFilenameString(); } else { - ASSERT(moduleRecordName.IsString()); JSHandle requiredVal = SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required); RETURN_IF_ABRUPT_COMPLETION(thread); requiredModule.Update(JSHandle::Cast(requiredVal)); - moduleName = ConvertToString(requiredModule->GetEcmaModuleRecordName()); + moduleName = requiredModule->GetEcmaModuleRecordNameString(); } if (decreaseModule.find(moduleName) != decreaseModule.end()) { LOG_FULL(DEBUG) << "Find module cyclical loading, stop increasing."; @@ -200,8 +196,7 @@ void ModuleDeregister::DecreaseRegisterCounts(JSThread *thread, JSHandleSetRegisterCounts(registerNum); diff --git a/ecmascript/module/js_module_manager.cpp b/ecmascript/module/js_module_manager.cpp index a22eb55d27..2150276783 100644 --- a/ecmascript/module/js_module_manager.cpp +++ b/ecmascript/module/js_module_manager.cpp @@ -50,8 +50,7 @@ JSTaggedValue ModuleManager::GetCurrentModule() JSTaggedValue currentFunc = frameHandler.GetFunction(); JSTaggedValue module = JSFunction::Cast(currentFunc.GetTaggedObject())->GetModule(); if (SourceTextModule::IsSendableFunctionModule(module)) { - JSTaggedValue recordName = SourceTextModule::GetModuleName(module); - CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName); + CString recordNameStr = SourceTextModule::GetModuleName(module); return HostGetImportedModule(recordNameStr).GetTaggedValue(); } return module; @@ -131,7 +130,7 @@ JSTaggedValue ModuleManager::GetModuleValueOutterInternal(int32_t index, JSTagge EcmaContext *context = thread->GetCurrentEcmaContext(); if (context->GetStageOfHotReload() == StageOfHotReload::LOAD_END_EXECUTE_PATCHMAIN) { const JSHandle resolvedModuleOfHotReload = - context->FindPatchModule(ConvertToString(module->GetEcmaModuleRecordName())); + context->FindPatchModule(module->GetEcmaModuleRecordNameString()); if (!resolvedModuleOfHotReload->IsHole()) { resolvedModule = resolvedModuleOfHotReload.GetTaggedValue(); JSHandle moduleOfHotReload(thread, resolvedModule); @@ -193,7 +192,7 @@ JSTaggedValue ModuleManager::GetLazyModuleValueOutterInternal(int32_t index, JST EcmaContext *context = thread->GetCurrentEcmaContext(); if (context->GetStageOfHotReload() == StageOfHotReload::LOAD_END_EXECUTE_PATCHMAIN) { const JSHandle resolvedModuleOfHotReload = - context->FindPatchModule(ConvertToString(module->GetEcmaModuleRecordName())); + context->FindPatchModule(module->GetEcmaModuleRecordNameString()); if (!resolvedModuleOfHotReload->IsHole()) { resolvedModule = resolvedModuleOfHotReload.GetTaggedValue(); JSHandle moduleOfHotReload(thread, resolvedModule); @@ -316,8 +315,9 @@ JSTaggedValue ModuleManager::GetModuleValueOutterInternal(JSTaggedValue key, JST ASSERT(resolvedModule.IsSourceTextModule()); SourceTextModule *module = SourceTextModule::Cast(resolvedModule.GetTaggedObject()); if (module->GetTypes() == ModuleTypes::CJS_MODULE) { - JSHandle cjsModuleName(thread, SourceTextModule::GetModuleName(JSTaggedValue(module))); - return CjsModule::SearchFromModuleCache(thread, cjsModuleName).GetTaggedValue(); + CString cjsModuleName = SourceTextModule::GetModuleName(JSTaggedValue(module)); + JSHandle moduleNameHandle(thread->GetEcmaVM()->GetFactory()->NewFromUtf8(cjsModuleName)); + return CjsModule::SearchFromModuleCache(thread, moduleNameHandle).GetTaggedValue(); } return module->GetModuleValue(thread, binding->GetBindingName(), false); } @@ -560,8 +560,7 @@ JSHandle ModuleManager::ResolveModuleWithMerge( moduleRecord = ModuleDataExtractor::ParseCjsModule(thread, jsPandaFile); } - JSHandle recordNameHdl = vm_->GetFactory()->NewFromUtf8(recordName); - JSHandle::Cast(moduleRecord)->SetEcmaModuleRecordName(thread, recordNameHdl.GetTaggedValue()); + JSHandle::Cast(moduleRecord)->SetEcmaModuleRecordNameString(recordName); ModuleDeregister::InitForDeregisterModule(moduleRecord, executeFromJob); return moduleRecord; } @@ -603,13 +602,12 @@ JSTaggedValue ModuleManager::GetModuleNamespaceInternal(int32_t index, JSTaggedV SourceTextModule *module = SourceTextModule::Cast(currentModule.GetTaggedObject()); JSTaggedValue requestedModule = module->GetRequestedModules(); JSTaggedValue moduleName = TaggedArray::Cast(requestedModule.GetTaggedObject())->Get(index); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); JSHandle requiredModule; - if (moduleRecordName.IsUndefined()) { + if (moduleRecordName.empty()) { requiredModule = SourceTextModule::HostResolveImportedModule(thread, JSHandle(thread, module), JSHandle(thread, moduleName)); } else { - ASSERT(moduleRecordName.IsString()); requiredModule = SourceTextModule::HostResolveImportedModuleWithMerge(thread, JSHandle(thread, module), JSHandle(thread, moduleName)); } @@ -622,9 +620,9 @@ JSTaggedValue ModuleManager::GetModuleNamespaceInternal(int32_t index, JSTaggedV } // if requiredModuleST is CommonJS if (moduleType == ModuleTypes::CJS_MODULE) { - JSHandle cjsModuleName(thread, - SourceTextModule::GetModuleName(requiredModuleST.GetTaggedValue())); - return CjsModule::SearchFromModuleCache(thread, cjsModuleName).GetTaggedValue(); + CString cjsModuleName = SourceTextModule::GetModuleName(requiredModuleST.GetTaggedValue()); + JSHandle moduleNameHandle(thread->GetEcmaVM()->GetFactory()->NewFromUtf8(cjsModuleName)); + return CjsModule::SearchFromModuleCache(thread, moduleNameHandle).GetTaggedValue(); } // if requiredModuleST is ESM JSHandle moduleNamespace = SourceTextModule::GetModuleNamespace(thread, requiredModuleST); @@ -680,9 +678,9 @@ CString ModuleManager::GetRecordName(JSTaggedValue module) } if (module.IsSourceTextModule()) { SourceTextModule *sourceTextModule = SourceTextModule::Cast(module.GetTaggedObject()); - JSTaggedValue recordName = sourceTextModule->GetEcmaModuleRecordName(); - if (recordName.IsString()) { - entry = ModulePathHelper::Utf8ConvertToString(recordName); + CString recordName = sourceTextModule->GetEcmaModuleRecordNameString(); + if (!recordName.empty()) { + return recordName; } } return entry; @@ -694,10 +692,10 @@ int ModuleManager::GetExportObjectIndex(EcmaVM *vm, JSHandle e JSThread *thread = vm->GetJSThread(); if (ecmaModule->GetLocalExportEntries().IsUndefined()) { CString msg = "No export named '" + key; - if (!ecmaModule->GetEcmaModuleRecordName().IsUndefined()) { - msg += "' which exported by '" + ConvertToString(ecmaModule->GetEcmaModuleRecordName()) + "'"; + if (!ecmaModule->GetEcmaModuleRecordNameString().empty()) { + msg += "' which exported by '" + ecmaModule->GetEcmaModuleRecordNameString() + "'"; } else { - msg += "' which exported by '" + ConvertToString(ecmaModule->GetEcmaModuleFilename()) + "'"; + msg += "' which exported by '" + ecmaModule->GetEcmaModuleFilenameString() + "'"; } ObjectFactory *factory = vm->GetFactory(); JSTaggedValue error = factory->GetJSError(ErrorType::SYNTAX_ERROR, msg.c_str(), @@ -810,7 +808,6 @@ JSHandle ModuleManager::ExecuteJsonModule(JSThread *thread, const JSHandle ModuleManager::ExecuteCjsModule(JSThread *thread, const CString &recordName, const JSPandaFile *jsPandaFile) { - ObjectFactory *factory = vm_->GetFactory(); CString entryPoint = JSPandaFile::ENTRY_FUNCTION_NAME; CString moduleRecord = jsPandaFile->GetJSPandaFileDesc(); if (!jsPandaFile->IsBundlePack()) { @@ -824,8 +821,7 @@ JSHandle ModuleManager::ExecuteCjsModule(JSThread *thread, const } else { JSHandle module = JSHandle::Cast(ModuleDataExtractor::ParseCjsModule(thread, jsPandaFile)); - JSHandle record = factory->NewFromASCII(moduleRecord); - module->SetEcmaModuleRecordName(thread, record); + module->SetEcmaModuleRecordNameString(moduleRecord); requiredModule.Update(module); JSPandaFileExecutor::Execute(thread, jsPandaFile, entryPoint); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, requiredModule); @@ -870,6 +866,8 @@ void ModuleManager::RemoveModuleFromCache(const CString& recordName) } JSTaggedValue result = entry->second; SourceTextModule::Cast(result)->DestoryLazyImportArray(); + SourceTextModule::Cast(result)->DestoryEcmaModuleFilenameString(); + SourceTextModule::Cast(result)->DestoryEcmaModuleRecordNameString(); resolvedModules_.erase(recordName); } diff --git a/ecmascript/module/js_module_manager.h b/ecmascript/module/js_module_manager.h index a89d8bb1e2..fc88241e67 100644 --- a/ecmascript/module/js_module_manager.h +++ b/ecmascript/module/js_module_manager.h @@ -130,6 +130,8 @@ public: ASSERT(!key.empty()); JSTaggedValue module = it->second; SourceTextModule::Cast(module)->DestoryLazyImportArray(); + SourceTextModule::Cast(module)->DestoryEcmaModuleFilenameString(); + SourceTextModule::Cast(module)->DestoryEcmaModuleRecordNameString(); } } diff --git a/ecmascript/module/js_module_namespace.cpp b/ecmascript/module/js_module_namespace.cpp index ee41f3f672..c8a98377a5 100644 --- a/ecmascript/module/js_module_namespace.cpp +++ b/ecmascript/module/js_module_namespace.cpp @@ -365,8 +365,7 @@ void ModuleNamespace::SetModuleDeregisterProcession(JSThread *thread, const JSHa ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle module(thread, nameSpace->GetModule()); - JSHandle moduleName(thread, SourceTextModule::GetModuleName(module.GetTaggedValue())); - CString moduleStr = ConvertToString(moduleName.GetTaggedValue()); + CString moduleStr = SourceTextModule::GetModuleName(module.GetTaggedValue()); int srcLength = strlen(moduleStr.c_str()) + 1; auto moduleNameData = thread->GetEcmaVM()->GetNativeAreaAllocator()->AllocateBuffer(srcLength); if (memcpy_s(moduleNameData, srcLength, moduleStr.c_str(), srcLength) != EOK) { diff --git a/ecmascript/module/js_module_source_text.cpp b/ecmascript/module/js_module_source_text.cpp index f68f0a8d5e..91a46fa7fd 100644 --- a/ecmascript/module/js_module_source_text.cpp +++ b/ecmascript/module/js_module_source_text.cpp @@ -99,8 +99,7 @@ JSHandle SourceTextModule::HostResolveImportedModuleWithMerge(JST if (thread->GetCurrentEcmaContext()->GetStageOfHotReload() == StageOfHotReload::BEGIN_EXECUTE_PATCHMAIN) { baseFilename = thread->GetEcmaVM()->GetQuickFixManager()->GetCurrentBaseFileName(); } else { - ASSERT(module->GetEcmaModuleFilename().IsHeapObject()); - baseFilename = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename()); + baseFilename = module->GetEcmaModuleFilenameString(); } auto moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); @@ -111,8 +110,7 @@ JSHandle SourceTextModule::HostResolveImportedModuleWithMerge(JST } return moduleManager->ResolveNativeModule(requestStr, baseFilename, moduleType); } - ASSERT(module->GetEcmaModuleRecordName().IsHeapObject()); - CString recordName = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleRecordName()); + CString recordName = module->GetEcmaModuleRecordNameString(); std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFilename, recordName); if (jsPandaFile == nullptr) { @@ -145,8 +143,7 @@ JSHandle SourceTextModule::HostResolveImportedModule(JSThread *th return JSHandle(moduleManager->HostGetImportedModule(moduleRequestStr)); } - CString dirname = base::PathHelper::ResolveDirPath( - ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename())); + 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, @@ -238,7 +235,8 @@ JSHandle SourceTextModule::ResolveCjsStarExport(JSThread *thread, cjsModule->SetStatus(ModuleStatus::EVALUATED); } - JSHandle cjsModuleName(thread, GetModuleName(cjsModule.GetTaggedValue())); + CString moduleName = GetModuleName(cjsModule.GetTaggedValue()); + JSHandle cjsModuleName(thread->GetEcmaVM()->GetFactory()->NewFromUtf8(moduleName)); JSHandle cjsExports = CjsModule::SearchFromModuleCache(thread, cjsModuleName); return SourceTextModule::ResolveExportObject(thread, cjsModule, cjsExports, exportName); } @@ -384,8 +382,7 @@ void SourceTextModule::MakeInternalArgs(const EcmaVM *vm, std::vector SourceTextModule::LoadNativeModuleImpl(EcmaVM *vm, JSThread *thread, const JSHandle &requiredModule, ModuleTypes moduleType) { - CString moduleRequestName = - ModulePathHelper::Utf8ConvertToString(requiredModule->GetEcmaModuleRecordName()); + CString moduleRequestName = requiredModule->GetEcmaModuleRecordNameString(); bool enableESMTrace = thread->GetEcmaVM()->GetJSOptions().EnableESMTrace(); if (enableESMTrace) { CString traceInfo = "LoadNativeModule: " + moduleRequestName; @@ -393,8 +390,7 @@ Local SourceTextModule::LoadNativeModuleImpl(EcmaVM *vm, JSThread *t } CString soName = PathHelper::GetStrippedModuleName(moduleRequestName); - CString fileName = - ModulePathHelper::Utf8ConvertToString(requiredModule->GetEcmaModuleFilename()); + CString fileName = requiredModule->GetEcmaModuleFilenameString(); CString moduleName = ModulePathHelper::GetModuleNameWithBaseFile(fileName); std::vector> arguments; LOG_FULL(DEBUG) << "Request module is " << moduleRequestName; @@ -443,8 +439,7 @@ bool SourceTextModule::LoadNativeModule(JSThread *thread, const JSHandleGetEcmaVM()->GetJSOptions().EnableESMTrace(); - CString fileName = - ModulePathHelper::Utf8ConvertToString(requiredModule->GetEcmaModuleFilename()); + CString fileName = requiredModule->GetEcmaModuleFilenameString(); CString moduleName = ModulePathHelper::GetModuleNameWithBaseFile(fileName); if (UNLIKELY(exportObject->IsUndefined())) { LOG_FULL(ERROR) << "export objects of native so is undefined, so name is " << moduleName; @@ -474,8 +469,7 @@ void SourceTextModule::EvaluateNativeModule(JSThread *thread, JSHandleGetEcmaModuleRecordName()) << " failed"; + LOG_FULL(INFO) << "LoadNativeModule " << nativeModule->GetEcmaModuleRecordNameString() << " failed"; return; } nativeModule->SetStatus(ModuleStatus::EVALUATED); @@ -588,14 +582,13 @@ std::optional SourceTextModule::HandleInnerModuleInstantiation(JSThread *th { // a. Let requiredModule be ? HostResolveImportedModule(module, required). JSMutableHandle requiredModule(thread, thread->GlobalConstants()->GetUndefined()); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { JSHandle requiredVal = SourceTextModule::HostResolveImportedModule(thread, module, required, executeFromJob); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, SourceTextModule::UNDEFINED_INDEX); requiredModule.Update(JSHandle::Cast(requiredVal)); } else { - ASSERT(moduleRecordName.IsString()); JSHandle requiredVal = SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required, executeFromJob); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, SourceTextModule::UNDEFINED_INDEX); @@ -718,14 +711,13 @@ void SourceTextModule::ModuleDeclarationEnvironmentSetup(JSThread *thread, moduleRequest.Update(in->GetModuleRequest()); // a. Let importedModule be ! HostResolveImportedModule(module, in.[[ModuleRequest]]). JSMutableHandle importedModule(thread, thread->GlobalConstants()->GetUndefined()); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { JSHandle importedVal = SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); RETURN_IF_ABRUPT_COMPLETION(thread); importedModule.Update(JSHandle::Cast(importedVal)); } else { - ASSERT(moduleRecordName.IsString()); JSHandle importedVal = SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); RETURN_IF_ABRUPT_COMPLETION(thread); @@ -752,12 +744,11 @@ void SourceTextModule::ModuleDeclarationEnvironmentSetup(JSThread *thread, CString requestMod = ModulePathHelper::ReformatPath(ConvertToString(moduleRequest.GetTaggedValue())); CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + ConvertToString(importName.GetTaggedValue()); - if (!module->GetEcmaModuleRecordName().IsUndefined()) { - CString recordStr = ModulePathHelper::ReformatPath(ConvertToString( - module->GetEcmaModuleRecordName())); + if (!module->GetEcmaModuleRecordNameString().empty()) { + CString recordStr = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); msg += "' which imported by '" + recordStr + "'"; } else { - msg += "' which imported by '" + ConvertToString(module->GetEcmaModuleFilename()) + "'"; + msg += "' which imported by '" + module->GetEcmaModuleFilenameString() + "'"; } THROW_ERROR(thread, ErrorType::SYNTAX_ERROR, msg.c_str()); } @@ -805,14 +796,13 @@ void SourceTextModule::ModuleDeclarationArrayEnvironmentSetup(JSThread *thread, moduleRequest.Update(in->GetModuleRequest()); // a. Let importedModule be ! HostResolveImportedModule(module, in.[[ModuleRequest]]). JSMutableHandle importedModule(thread, thread->GlobalConstants()->GetUndefined()); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { JSHandle importedVal = SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); RETURN_IF_ABRUPT_COMPLETION(thread); importedModule.Update(JSHandle::Cast(importedVal)); } else { - ASSERT(moduleRecordName.IsString()); JSHandle importedVal = SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); RETURN_IF_ABRUPT_COMPLETION(thread); @@ -835,12 +825,12 @@ void SourceTextModule::ModuleDeclarationArrayEnvironmentSetup(JSThread *thread, CString requestMod = ModulePathHelper::ReformatPath(ConvertToString(moduleRequest.GetTaggedValue())); CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + ConvertToString(importName.GetTaggedValue()); - if (!module->GetEcmaModuleRecordName().IsUndefined()) { - CString recordStr = ModulePathHelper::ReformatPath(ConvertToString( - module->GetEcmaModuleRecordName())); + if (!module->GetEcmaModuleRecordNameString().empty()) { + CString recordStr = ModulePathHelper::ReformatPath( + module->GetEcmaModuleRecordNameString()); msg += "' which imported by '" + recordStr + "'"; } else { - msg += "' which imported by '" + ConvertToString(module->GetEcmaModuleFilename()) + "'"; + msg += "' which imported by '" + module->GetEcmaModuleFilenameString() + "'"; } THROW_ERROR(thread, ErrorType::SYNTAX_ERROR, msg.c_str()); } @@ -1044,12 +1034,11 @@ int SourceTextModule::InnerModuleEvaluationUnsafe(JSThread *thread, const JSHand continue; } required.Update(requestedModules->Get(idx)); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { requiredModule = JSHandle::Cast( SourceTextModule::HostResolveImportedModule(thread, module, required)); } else { - ASSERT(moduleRecordName.IsString()); requiredModule = JSHandle::Cast( SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, index); @@ -1267,12 +1256,11 @@ int SourceTextModule::ModuleEvaluation(JSThread *thread, const JSHandleGet(idx)); JSMutableHandle requiredModule(thread, thread->GlobalConstants()->GetUndefined()); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { requiredModule.Update(SourceTextModule::HostResolveImportedModule(thread, module, required)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, index); } else { - ASSERT(moduleRecordName.IsString()); requiredModule.Update(SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, index); } @@ -1298,18 +1286,13 @@ int SourceTextModule::ModuleEvaluation(JSThread *thread, const JSHandle SourceTextModule::ModuleExecution(JSThread *thread, const JSHandle &module, const void *buffer, size_t size, bool executeFromJob) { - JSTaggedValue moduleFileName = module->GetEcmaModuleFilename(); - ASSERT(moduleFileName.IsString()); - CString moduleFilenameStr = - ModulePathHelper::Utf8ConvertToString(moduleFileName); - + CString moduleFilenameStr = module->GetEcmaModuleFilenameString(); std::string entryPoint; - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { entryPoint = JSPandaFile::ENTRY_FUNCTION_NAME; } else { - ASSERT(moduleRecordName.IsString()); - entryPoint = ModulePathHelper::Utf8ConvertToString(moduleRecordName); + entryPoint = moduleRecordName; } std::shared_ptr jsPandaFile; @@ -1513,14 +1496,13 @@ void SourceTextModule::SetExportName(JSThread *thread, const JSHandle requestedModule(thread, thread->GlobalConstants()->GetUndefined()); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { JSHandle requestedVal = SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); RETURN_IF_ABRUPT_COMPLETION(thread); requestedModule.Update(JSHandle::Cast(requestedVal)); } else { - ASSERT(moduleRecordName.IsString()); JSHandle requestedVal = SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); RETURN_IF_ABRUPT_COMPLETION(thread); @@ -1551,14 +1533,13 @@ JSHandle SourceTextModule::GetStarResolution(JSThread *thread, auto globalConstants = thread->GlobalConstants(); // a. Let importedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). JSMutableHandle importedModule(thread, thread->GlobalConstants()->GetUndefined()); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { JSHandle importedVal = SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); importedModule.Update(JSHandle::Cast(importedVal)); } else { - ASSERT(moduleRecordName.IsString()); JSHandle importedVal = SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); @@ -1704,11 +1685,10 @@ JSHandle SourceTextModule::ResolveIndirectExport(JSThread *thread // ii. Let importedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). moduleRequest.Update(ee->GetModuleRequest()); JSMutableHandle requestedModule(thread, undefined); - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { requestedModule.Update(SourceTextModule::HostResolveImportedModule(thread, module, moduleRequest)); } else { - ASSERT(moduleRecordName.IsString()); requestedModule.Update( SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, moduleRequest)); } @@ -1746,11 +1726,11 @@ void SourceTextModule::CheckResolvedBinding(JSThread *thread, const JSHandleGetModuleRequest())); CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + ConvertToString(exportName.GetTaggedValue()); - if (!module->GetEcmaModuleRecordName().IsUndefined()) { - CString recordStr = ModulePathHelper::ReformatPath(ConvertToString(module->GetEcmaModuleRecordName())); + if (!module->GetEcmaModuleRecordNameString().empty()) { + CString recordStr = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); msg += "' which exported by '" + recordStr + "'"; } else { - msg += "' which exported by '" + ConvertToString(module->GetEcmaModuleFilename()) + "'"; + msg += "' which exported by '" + module->GetEcmaModuleFilenameString() + "'"; } THROW_ERROR(thread, ErrorType::SYNTAX_ERROR, msg.c_str()); } @@ -1784,23 +1764,23 @@ void SourceTextModule::CheckResolvedIndexBinding(JSThread *thread, const JSHandl CString requestMod = ModulePathHelper::ReformatPath(ConvertToString(ee->GetModuleRequest())); CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + ConvertToString(exportName.GetTaggedValue()); - if (!module->GetEcmaModuleRecordName().IsUndefined()) { - CString record = ModulePathHelper::ReformatPath(ConvertToString(module->GetEcmaModuleRecordName())); + if (!module->GetEcmaModuleRecordNameString().empty()) { + CString record = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); msg += "' which exported by '" + record + "'"; } else { - msg += "' which exported by '" + ConvertToString(module->GetEcmaModuleFilename()) + "'"; + msg += "' which exported by '" + module->GetEcmaModuleFilenameString() + "'"; } THROW_ERROR(thread, ErrorType::SYNTAX_ERROR, msg.c_str()); } } } -JSTaggedValue SourceTextModule::GetModuleName(JSTaggedValue currentModule) +CString SourceTextModule::GetModuleName(JSTaggedValue currentModule) { SourceTextModule *module = SourceTextModule::Cast(currentModule.GetTaggedObject()); - JSTaggedValue recordName = module->GetEcmaModuleRecordName(); - if (recordName.IsUndefined()) { - return module->GetEcmaModuleFilename(); + CString recordName = module->GetEcmaModuleRecordNameString(); + if (recordName.empty()) { + recordName = module->GetEcmaModuleFilenameString(); } return recordName; } @@ -1840,18 +1820,14 @@ void SourceTextModule::ExecuteAsyncModule(JSThread *thread, const JSHandleGetStatus() == ModuleStatus::EVALUATING || module->GetStatus() == ModuleStatus::EVALUATING_ASYNC); // 2. Assert: module.[[HasTLA]] is true. ASSERT(module->GetHasTLA()); - JSTaggedValue moduleFileName = module->GetEcmaModuleFilename(); - ASSERT(moduleFileName.IsString()); - CString moduleFilenameStr = - ModulePathHelper::Utf8ConvertToString(moduleFileName); + CString moduleFilenameStr = module->GetEcmaModuleFilenameString(); std::string entryPoint; - JSTaggedValue moduleRecordName = module->GetEcmaModuleRecordName(); - if (moduleRecordName.IsUndefined()) { + CString moduleRecordName = module->GetEcmaModuleRecordNameString(); + if (moduleRecordName.empty()) { entryPoint = JSPandaFile::ENTRY_FUNCTION_NAME; } else { - ASSERT(moduleRecordName.IsString()); - entryPoint = ModulePathHelper::Utf8ConvertToString(moduleRecordName); + entryPoint = moduleRecordName; } std::shared_ptr jsPandaFile; @@ -2145,8 +2121,7 @@ void SourceTextModule::SearchCircularImport(JSThread *thread, const CString &cir requiredModule.Update(JSHandle::Cast( SourceTextModule::HostResolveImportedModuleWithMerge(thread, module, required))); RETURN_IF_ABRUPT_COMPLETION(thread); - requiredModuleName = - ModulePathHelper::Utf8ConvertToString(requiredModule->GetEcmaModuleRecordName()); + requiredModuleName = requiredModule->GetEcmaModuleRecordNameString(); referenceList.push_back(requiredModuleName); if (requiredModuleName == circularModuleRecordName) { PrintCircular(referenceList, ERROR); @@ -2205,8 +2180,7 @@ CString SourceTextModule::ReplaceModuleThroughFeature(JSThread *thread, const CS std::tuple> SourceTextModule::GetResolvedModule(JSThread *thread, const JSHandle &module, const JSHandle &moduleRequest) { - CString dirname = base::PathHelper::ResolveDirPath( - ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename())); + CString dirname = base::PathHelper::ResolveDirPath(module->GetEcmaModuleFilenameString()); CString moduleRequestStr = ModulePathHelper::Utf8ConvertToString(moduleRequest.GetTaggedValue()); CString fileName = ResolveFilenameFromNative(thread, dirname, moduleRequestStr); @@ -2239,8 +2213,8 @@ std::tuple> SourceTextModule::GetResolvedModule moduleManager->HostGetImportedModule(moduleRequestStr)); } - CString baseFilename = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename()); - CString recordName = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleRecordName()); + CString baseFilename = module->GetEcmaModuleFilenameString(); + CString recordName = module->GetEcmaModuleRecordNameString(); std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFilename, recordName); ASSERT(!(jsPandaFile == nullptr)); diff --git a/ecmascript/module/js_module_source_text.h b/ecmascript/module/js_module_source_text.h index f198743a56..7f5339d12f 100644 --- a/ecmascript/module/js_module_source_text.h +++ b/ecmascript/module/js_module_source_text.h @@ -259,11 +259,55 @@ public: return lazyArray[index]; } + inline CString GetEcmaModuleFilenameString() const + { + CString *fileName = reinterpret_cast(GetEcmaModuleFilename()); + if (fileName == nullptr) { + return CString(); + } + return *fileName; + } + + inline CString GetEcmaModuleRecordNameString() const + { + CString *recordName = reinterpret_cast(GetEcmaModuleRecordName()); + if (recordName == nullptr) { + return CString(); + } + return *recordName; + } + + inline void SetEcmaModuleFilenameString(const CString &fileName) + { + CString *ptr = new CString(fileName); + DestoryEcmaModuleFilenameString(); + SetEcmaModuleFilename(ToUintPtr(ptr)); + } + + inline void SetEcmaModuleRecordNameString(const CString &recordName) + { + CString *ptr = new CString(recordName); + DestoryEcmaModuleRecordNameString(); + SetEcmaModuleRecordName(ToUintPtr(ptr)); + } + + inline void DestoryEcmaModuleFilenameString() + { + CString *ptr = reinterpret_cast(GetEcmaModuleFilename()); + delete ptr; + SetEcmaModuleFilename(ToUintPtr(nullptr)); + } + + inline void DestoryEcmaModuleRecordNameString() + { + CString *ptr = reinterpret_cast(GetEcmaModuleRecordName()); + delete ptr; + SetEcmaModuleRecordName(ToUintPtr(nullptr)); + } + static constexpr size_t SOURCE_TEXT_MODULE_OFFSET = ModuleRecord::SIZE; ACCESSORS(Environment, SOURCE_TEXT_MODULE_OFFSET, NAMESPACE_OFFSET); - ACCESSORS(Namespace, NAMESPACE_OFFSET, ECMA_MODULE_FILENAME); - ACCESSORS(EcmaModuleFilename, ECMA_MODULE_FILENAME, ECMA_MODULE_RECORDNAME); - ACCESSORS(EcmaModuleRecordName, ECMA_MODULE_RECORDNAME, REQUESTED_MODULES_OFFSET); + ACCESSORS(Namespace, NAMESPACE_OFFSET, REQUESTED_MODULES_OFFSET); ACCESSORS(RequestedModules, REQUESTED_MODULES_OFFSET, IMPORT_ENTRIES_OFFSET); ACCESSORS(ImportEntries, IMPORT_ENTRIES_OFFSET, LOCAL_EXPORT_ENTTRIES_OFFSET); ACCESSORS(LocalExportEntries, LOCAL_EXPORT_ENTTRIES_OFFSET, INDIRECT_EXPORT_ENTTRIES_OFFSET); @@ -280,7 +324,9 @@ public: ACCESSORS_PRIMITIVE_FIELD(AsyncEvaluatingOrdinal, uint32_t, ASYNC_EVALUATION_OFFSET, PENDING_DEPENDENCIES_OFFSET); ACCESSORS_PRIMITIVE_FIELD(PendingAsyncDependencies, int32_t, PENDING_DEPENDENCIES_OFFSET, LAYZ_IMPORT_STATUS_OFFSET); - ACCESSORS_PRIMITIVE_FIELD(LazyImportStatus, uintptr_t, LAYZ_IMPORT_STATUS_OFFSET, BIT_FIELD_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(LazyImportStatus, uintptr_t, LAYZ_IMPORT_STATUS_OFFSET, ECMA_MODULE_FILENAME); + ACCESSORS_PRIMITIVE_FIELD(EcmaModuleFilename, uintptr_t, ECMA_MODULE_FILENAME, ECMA_MODULE_RECORDNAME); + ACCESSORS_PRIMITIVE_FIELD(EcmaModuleRecordName, uintptr_t, ECMA_MODULE_RECORDNAME, BIT_FIELD_OFFSET); ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) DEFINE_ALIGN_SIZE(LAST_OFFSET); @@ -333,7 +379,7 @@ public: const JSHandle &module, CVector, JSHandle>> &resolveVector); - static JSTaggedValue GetModuleName(JSTaggedValue currentModule); + static CString GetModuleName(JSTaggedValue currentModule); static bool IsDynamicModule(LoadingTypes types); @@ -373,6 +419,8 @@ private: const JSHandle &exportName, CVector, JSHandle>> &resolveVector); + static void InitializeEnvironment(JSThread *thread, const JSHandle ¤tModule, + CString &moduleName, JSHandle &exports, bool isBundle); static void CheckResolvedBinding(JSThread *thread, const JSHandle &module); static void CheckResolvedIndexBinding(JSThread *thread, const JSHandle &module); diff --git a/ecmascript/module/js_shared_module.cpp b/ecmascript/module/js_shared_module.cpp index 7919454559..8a8f0f0896 100644 --- a/ecmascript/module/js_shared_module.cpp +++ b/ecmascript/module/js_shared_module.cpp @@ -41,8 +41,8 @@ JSHandle SendableClassModule::GenerateSendableFuncModule(JSThread currentEnvironment); sModule->SetSharedType(SharedTypes::SENDABLE_FUNCTION_MODULE); sModule->SetEnvironment(thread, sendableEnvironment); - sModule->SetEcmaModuleFilename(thread, currentModule->GetEcmaModuleFilename()); - sModule->SetEcmaModuleRecordName(thread, currentModule->GetEcmaModuleRecordName()); + sModule->SetEcmaModuleFilenameString(currentModule->GetEcmaModuleFilenameString()); + sModule->SetEcmaModuleRecordNameString(currentModule->GetEcmaModuleRecordNameString()); sModule->SetSendableEnv(thread, JSTaggedValue::Undefined()); return JSHandle(sModule); } @@ -50,15 +50,16 @@ JSHandle SendableClassModule::GenerateSendableFuncModule(JSThread JSHandle SendableClassModule::CloneRecordIndexBinding(JSThread *thread, JSTaggedValue indexBinding) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - ResolvedIndexBinding *binding = ResolvedIndexBinding::Cast(indexBinding.GetTaggedObject()); + JSHandle binding(thread, indexBinding); JSHandle resolvedModule(thread, binding->GetModule()); if (SourceTextModule::IsSharedModule((resolvedModule))) { return JSHandle::Cast( factory->NewSResolvedIndexBindingRecord(resolvedModule, binding->GetIndex())); } - JSHandle record(thread, SourceTextModule::GetModuleName(resolvedModule.GetTaggedValue())); - JSHandle fileName(thread, resolvedModule->GetEcmaModuleFilename()); + CString moduleName = SourceTextModule::GetModuleName(resolvedModule.GetTaggedValue()); + JSHandle record = thread->GetEcmaVM()->GetFactory()->NewFromUtf8(moduleName); + JSHandle fileName = factory->NewFromUtf8(resolvedModule->GetEcmaModuleFilenameString()); int32_t index = binding->GetIndex(); return JSHandle::Cast(factory->NewSResolvedRecordIndexBindingRecord(record, fileName, index)); } @@ -74,7 +75,8 @@ JSHandle SendableClassModule::CloneRecordNameBinding(JSThread *th factory->NewSResolvedBindingRecord(resolvedModule, bindingName)); } - JSHandle record(thread, SourceTextModule::GetModuleName(resolvedModule.GetTaggedValue())); + CString moduleName = SourceTextModule::GetModuleName(resolvedModule.GetTaggedValue()); + JSHandle record = thread->GetEcmaVM()->GetFactory()->NewFromUtf8(moduleName); JSHandle bindingName(thread, resolvedBinding->GetBindingName()); return JSHandle::Cast(factory->NewSResolvedRecordBindingRecord(record, bindingName)); } @@ -141,8 +143,7 @@ JSHandle SharedModuleHelper::ParseSharedModule(JSThread *thread, bool hasTLA = jsPandaFile->GetHasTopLevelAwait(descriptor); moduleRecord->SetHasTLA(hasTLA); - JSHandle ecmaModuleFilename = factory->NewFromUtf8(moduleFilename); - moduleRecord->SetEcmaModuleFilename(thread, ecmaModuleFilename); + moduleRecord->SetEcmaModuleFilenameString(moduleFilename); moduleRecord->SetStatus(ModuleStatus::UNINSTANTIATED); moduleRecord->SetTypes(ModuleTypes::ECMA_MODULE); moduleRecord->SetIsNewBcVersion(true); diff --git a/ecmascript/module/js_shared_module_manager.cpp b/ecmascript/module/js_shared_module_manager.cpp index fdba0adba6..37c2a5e27d 100644 --- a/ecmascript/module/js_shared_module_manager.cpp +++ b/ecmascript/module/js_shared_module_manager.cpp @@ -208,9 +208,7 @@ JSHandle SharedModuleManager::ResolveSharedImportedModuleWithMerg ASSERT(jsPandaFile->IsModule(recordInfo)); JSHandle moduleRecord = SharedModuleHelper::ParseSharedModule(thread, jsPandaFile, recordName, fileName, recordInfo); - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle requireModule = JSHandle(factory->NewFromUtf8(recordName)); - JSHandle::Cast(moduleRecord)->SetEcmaModuleRecordName(thread, requireModule); + JSHandle::Cast(moduleRecord)->SetEcmaModuleRecordNameString(recordName); moduleManager->AddResolveImportedModule(recordName, moduleRecord.GetTaggedValue()); moduleManager->AddToInstantiatingSModuleList(recordName); return moduleRecord; @@ -274,8 +272,7 @@ void SharedModuleManager::TransferSModule(JSThread *thread) StateVisit &SharedModuleManager::findModuleMutexWithLock(JSThread *thread, const JSHandle &module) { RuntimeLockHolder locker(thread, mutex_); - CString moduleName = - ModulePathHelper::Utf8ConvertToString(SourceTextModule::GetModuleName(module.GetTaggedValue())); + CString moduleName = SourceTextModule::GetModuleName(module.GetTaggedValue()); auto it = sharedModuleMutex_.find(moduleName); if (it == sharedModuleMutex_.end()) { LOG_ECMA(FATAL) << " Get shared module mutex failed"; @@ -329,6 +326,8 @@ void SharedModuleManager::SharedNativeObjDestory() ASSERT(!key.empty()); JSTaggedValue module = it->second; SourceTextModule::Cast(module)->DestoryLazyImportArray(); + SourceTextModule::Cast(module)->DestoryEcmaModuleFilenameString(); + SourceTextModule::Cast(module)->DestoryEcmaModuleRecordNameString(); } } } // namespace panda::ecmascript diff --git a/ecmascript/module/module_data_extractor.cpp b/ecmascript/module/module_data_extractor.cpp index 56e0d7434f..e74a5a3e9b 100644 --- a/ecmascript/module/module_data_extractor.cpp +++ b/ecmascript/module/module_data_extractor.cpp @@ -51,8 +51,7 @@ JSHandle ModuleDataExtractor::ParseModule(JSThread *thread, const bool hasTLA = recordInfo->hasTopLevelAwait; moduleRecord->SetHasTLA(hasTLA); - JSHandle ecmaModuleFilename = factory->NewFromUtf8(moduleFilename); - moduleRecord->SetEcmaModuleFilename(thread, ecmaModuleFilename); + moduleRecord->SetEcmaModuleFilenameString(moduleFilename); moduleRecord->SetStatus(ModuleStatus::UNINSTANTIATED); moduleRecord->SetTypes(ModuleTypes::ECMA_MODULE); @@ -106,8 +105,7 @@ JSHandle ModuleDataExtractor::ParseCjsModule(JSThread *thread, co ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle moduleRecord = factory->NewSourceTextModule(); - JSHandle cjsModuleFilename = factory->NewFromUtf8(descriptor); - moduleRecord->SetEcmaModuleFilename(thread, cjsModuleFilename); + moduleRecord->SetEcmaModuleFilenameString(descriptor); JSHandle defaultName = thread->GlobalConstants()->GetHandledDefaultString(); JSHandle localExportEntry = factory->NewLocalExportEntry(defaultName, @@ -133,8 +131,7 @@ JSHandle ModuleDataExtractor::ParseJsonModule(JSThread *thread, c JSTaggedValue jsonData = JsonParse(thread, jsPandaFile, recordName); moduleRecord->StoreModuleValue(thread, 0, JSHandle(thread, jsonData)); // index = 0 - JSHandle ecmaModuleFilename = factory->NewFromUtf8(moduleFilename); - moduleRecord->SetEcmaModuleFilename(thread, ecmaModuleFilename); + moduleRecord->SetEcmaModuleFilenameString(moduleFilename); moduleRecord->SetStatus(ModuleStatus::UNINSTANTIATED); moduleRecord->SetTypes(ModuleTypes::JSON_MODULE); @@ -150,10 +147,8 @@ JSHandle ModuleDataExtractor::ParseNativeModule(JSThread *thread, JSHandle moduleRecord = factory->NewSourceTextModule(); // set moduleRecordName as non-undefined to distinguish between merge and non-merge mode - JSHandle falsyRecordName = factory->NewFromUtf8(moduleRequestName); - JSHandle fileName = factory->NewFromUtf8(baseFileName); - moduleRecord->SetEcmaModuleRecordName(thread, falsyRecordName); - moduleRecord->SetEcmaModuleFilename(thread, fileName); + moduleRecord->SetEcmaModuleRecordNameString(moduleRequestName); + moduleRecord->SetEcmaModuleFilenameString(baseFileName); JSHandle defaultName = thread->GlobalConstants()->GetHandledDefaultString(); JSHandle localExportEntry = factory->NewLocalExportEntry(defaultName, defaultName, LocalExportEntry::LOCAL_DEFAULT_INDEX, SharedTypes::UNSENDABLE_MODULE); diff --git a/ecmascript/module/module_manager_helper.cpp b/ecmascript/module/module_manager_helper.cpp index e1c21ba672..64b95cdee3 100644 --- a/ecmascript/module/module_manager_helper.cpp +++ b/ecmascript/module/module_manager_helper.cpp @@ -50,17 +50,17 @@ JSHandle ModuleManagerHelper::GetNativeOrCjsExports(JSThread *thr if (SourceTextModule::IsNativeModule(moduleType)) { exports.Update(module->GetModuleValue(thread, 0, false)); if (!exports->IsJSObject()) { - LOG_FULL(WARN) << "Load native module failed, so is " << - ConvertToString(SourceTextModule::GetModuleName(resolvedModule)); + LOG_FULL(WARN) << "Load native module failed, so is " << SourceTextModule::GetModuleName(resolvedModule); } return exports; } if (SourceTextModule::IsCjsModule(moduleType)) { - JSHandle cjsModuleName(thread, SourceTextModule::GetModuleName(module.GetTaggedValue())); - exports.Update(CjsModule::SearchFromModuleCache(thread, cjsModuleName).GetTaggedValue()); + CString cjsModuleName = SourceTextModule::GetModuleName(module.GetTaggedValue()); + JSHandle moduleNameHandle(thread->GetEcmaVM()->GetFactory()->NewFromUtf8(cjsModuleName)); + exports.Update(CjsModule::SearchFromModuleCache(thread, moduleNameHandle).GetTaggedValue()); if (exports->IsHole()) { CString errorMsg = - "Loading cjs module:" + ConvertToString(SourceTextModule::GetModuleName(resolvedModule)) + ", failed"; + "Loading cjs module:" + SourceTextModule::GetModuleName(resolvedModule) + ", failed"; JSHandle exception(thread, JSTaggedValue::Exception()); THROW_NEW_ERROR_WITH_MSG_AND_RETURN_VALUE(thread, ErrorType::SYNTAX_ERROR, errorMsg.c_str(), exception); @@ -100,7 +100,7 @@ JSTaggedValue ModuleManagerHelper::GetModuleValueFromIndexBinding(JSThread *thre if (moduleManager->IsEvaluatedModule(recordNameStr)) { resolvedModule = moduleManager->HostGetImportedModule(recordNameStr); } else { - auto isMergedAbc = !module->GetEcmaModuleRecordName().IsUndefined(); + auto isMergedAbc = !module->GetEcmaModuleRecordNameString().empty(); CString fileName = ModulePathHelper::Utf8ConvertToString((binding->GetAbcFileName())); if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordNameStr, fileName, isMergedAbc)) { LOG_ECMA(FATAL) << "LazyExecuteModule failed"; @@ -123,8 +123,8 @@ JSTaggedValue ModuleManagerHelper::GetModuleValueFromRecordBinding(JSThread *thr if (moduleManager->IsEvaluatedModule(recordNameStr)) { resolvedModule = moduleManager->HostGetImportedModule(recordNameStr); } else { - auto isMergedAbc = !module->GetEcmaModuleRecordName().IsUndefined(); - CString fileName = ModulePathHelper::Utf8ConvertToString((module->GetEcmaModuleFilename())); + auto isMergedAbc = !module->GetEcmaModuleRecordNameString().empty(); + CString fileName = module->GetEcmaModuleFilenameString(); if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordNameStr, fileName, isMergedAbc)) { LOG_ECMA(FATAL) << "LazyExecuteModule failed"; } @@ -151,7 +151,7 @@ JSTaggedValue ModuleManagerHelper::GetLazyModuleValueFromIndexBinding(JSThread * RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); } } else { - auto isMergedAbc = !module->GetEcmaModuleRecordName().IsUndefined(); + auto isMergedAbc = !module->GetEcmaModuleRecordNameString().empty(); CString fileName = ModulePathHelper::Utf8ConvertToString(binding->GetAbcFileName()); if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordNameStr, fileName, isMergedAbc)) { LOG_ECMA(FATAL) << "LazyExecuteModule failed"; @@ -178,8 +178,8 @@ JSTaggedValue ModuleManagerHelper::GetLazyModuleValueFromRecordBinding( RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); } } else { - auto isMergedAbc = !module->GetEcmaModuleRecordName().IsUndefined(); - CString fileName = ModulePathHelper::Utf8ConvertToString(module->GetEcmaModuleFilename()); + auto isMergedAbc = !module->GetEcmaModuleRecordNameString().empty(); + CString fileName = module->GetEcmaModuleFilenameString(); if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordNameStr, fileName, isMergedAbc)) { LOG_ECMA(FATAL) << "LazyExecuteModule failed"; } @@ -203,10 +203,10 @@ JSTaggedValue ModuleManagerHelper::UpdateBindingAndGetModuleValue(JSThread *thre SourceTextModule::ResolveExportObject(thread, requiredModule, exports, exportName); // ii. If resolution is null or "ambiguous", throw a SyntaxError exception. if (resolution->IsNull() || resolution->IsString()) { - CString requestMod = ModulePathHelper::ReformatPath( - ModulePathHelper::Utf8ConvertToString(SourceTextModule::GetModuleName(requiredModule.GetTaggedValue()))); - CString recordStr = ModulePathHelper::ReformatPath( - ModulePathHelper::Utf8ConvertToString(SourceTextModule::GetModuleName(module.GetTaggedValue()))); + CString requestMod = ModulePathHelper::ReformatPath(SourceTextModule::GetModuleName( + requiredModule.GetTaggedValue())); + CString recordStr = ModulePathHelper::ReformatPath(SourceTextModule::GetModuleName( + module.GetTaggedValue())); CString msg = "the requested module '" + requestMod + SourceTextModule::GetResolveErrorReason(resolution) + ModulePathHelper::Utf8ConvertToString(bindingName) + "' which imported by '" + recordStr + "'"; diff --git a/ecmascript/module/tests/ecma_module_test.cpp b/ecmascript/module/tests/ecma_module_test.cpp index d7df75de21..39e2cb6be4 100644 --- a/ecmascript/module/tests/ecma_module_test.cpp +++ b/ecmascript/module/tests/ecma_module_test.cpp @@ -260,8 +260,7 @@ HWTEST_F_L0(EcmaModuleTest, PreventExtensions_IsExtensible) SourceTextModule::AddLocalExportEntry(thread, module, localExportEntry2, 1, 2); JSHandle localExportEntries(thread, module->GetLocalExportEntries()); CString baseFileName = "a.abc"; - JSHandle moduleFilename = objectFactory->NewFromUtf8(baseFileName); - module->SetEcmaModuleFilename(thread, moduleFilename); + module->SetEcmaModuleFilenameString(baseFileName); ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); JSHandle moduleRecord = JSHandle::Cast(module); moduleManager->AddResolveImportedModule(baseFileName, moduleRecord.GetTaggedValue()); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 0c8c957495..32f11fd210 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -3476,9 +3476,9 @@ Local FunctionRef::GetSourceCode(const EcmaVM *vm, int lineNumber) ecmascript::CString entry = JSPandaFile::ENTRY_FUNCTION_NAME; if (!jsPandaFile->IsBundlePack()) { JSFunction *function = JSFunction::Cast(func.GetTaggedValue().GetTaggedObject()); - JSTaggedValue recordName = function->GetRecordName(); - ASSERT(!recordName.IsHole()); - entry = ConvertToString(recordName); + ecmascript::CString recordName = function->GetRecordName(); + ASSERT(!recordName.empty()); + entry = recordName; } uint32_t mainMethodIndex = jsPandaFile->GetMainMethodIndex(entry); diff --git a/ecmascript/napi/test/jsnapi_second_tests.cpp b/ecmascript/napi/test/jsnapi_second_tests.cpp index eddbd3fb0c..09335e8da3 100644 --- a/ecmascript/napi/test/jsnapi_second_tests.cpp +++ b/ecmascript/napi/test/jsnapi_second_tests.cpp @@ -1150,8 +1150,7 @@ HWTEST_F_L0(JSNApiTests, JSValueRef_IsModuleNamespaceObject) SourceTextModule::AddLocalExportEntry(thread_, module, localExportEntry2, 1, 2); JSHandle localExportEntries(thread_, module->GetLocalExportEntries()); CString baseFileName = "a.abc"; - JSHandle moduleFilename = objectFactory->NewFromUtf8(baseFileName); - module->SetEcmaModuleFilename(thread_, moduleFilename); + module->SetEcmaModuleFilenameString(baseFileName); ModuleManager *moduleManager = thread_->GetCurrentEcmaContext()->GetModuleManager(); moduleManager->AddResolveImportedModule(baseFileName, module.GetTaggedValue()); JSHandle np = diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index 0d94acbb5e..2f167f44ef 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -4700,8 +4700,6 @@ JSHandle ObjectFactory::NewSourceTextModule() JSTaggedValue undefinedValue = thread_->GlobalConstants()->GetUndefined(); obj->SetEnvironment(thread_, undefinedValue); obj->SetNamespace(thread_, undefinedValue); - obj->SetEcmaModuleFilename(thread_, undefinedValue); - obj->SetEcmaModuleRecordName(thread_, undefinedValue); obj->SetRequestedModules(thread_, undefinedValue); obj->SetImportEntries(thread_, undefinedValue); obj->SetLocalExportEntries(thread_, undefinedValue); @@ -4723,6 +4721,8 @@ JSHandle ObjectFactory::NewSourceTextModule() obj->SetIsNewBcVersion(false); obj->SetRegisterCounts(UINT16_MAX); obj->SetLazyImportStatus(ToUintPtr(nullptr)); + obj->SetEcmaModuleFilename(ToUintPtr(nullptr)); + obj->SetEcmaModuleRecordName(ToUintPtr(nullptr)); obj->SetSharedType(SharedTypes::UNSENDABLE_MODULE); obj->SetSendableEnv(thread_, undefinedValue); return obj; diff --git a/ecmascript/pgo_profiler/pgo_profiler.cpp b/ecmascript/pgo_profiler/pgo_profiler.cpp index f57944c7c3..bcdd795ef0 100644 --- a/ecmascript/pgo_profiler/pgo_profiler.cpp +++ b/ecmascript/pgo_profiler/pgo_profiler.cpp @@ -572,11 +572,10 @@ void PGOProfiler::HandlePGOPreDump() if (!methodValue.IsMethod()) { return; } - JSTaggedValue recordNameValue = func->GetRecordName(); - if (!recordNameValue.IsString()) { + CString recordName = func->GetRecordName(); + if (recordName.empty()) { return; } - CString recordName = ConvertToString(recordNameValue); auto abcId = GetMethodAbcId(func); if (current->HasExtraProfileTypeInfo()) { @@ -623,12 +622,11 @@ void PGOProfiler::HandlePGODumpByDumpThread(bool force) current = PopFromProfileQueue(); continue; } - JSTaggedValue recordNameValue = func->GetRecordName(); - if (!recordNameValue.IsString()) { + CString recordName = func->GetRecordName(); + if (recordName.empty()) { current = PopFromProfileQueue(); continue; } - CString recordName = ConvertToString(recordNameValue); auto abcId = GetMethodAbcId(func); if (current->HasExtraProfileTypeInfo()) { diff --git a/ecmascript/platform/unix/file.cpp b/ecmascript/platform/unix/file.cpp index 37b3b13d5c..a14cd770a9 100644 --- a/ecmascript/platform/unix/file.cpp +++ b/ecmascript/platform/unix/file.cpp @@ -186,7 +186,7 @@ bool TryToRemoveSO(JSThread *thread, JSHandle module) return false; } - CString soName = base::PathHelper::GetStrippedModuleName(ConvertToString(module->GetEcmaModuleRecordName())); + CString soName = base::PathHelper::GetStrippedModuleName(module->GetEcmaModuleRecordNameString()); return unloadNativeModuleCallback(soName.c_str()); } diff --git a/ecmascript/require/js_cjs_module.cpp b/ecmascript/require/js_cjs_module.cpp index 384aad19bb..9fba581721 100644 --- a/ecmascript/require/js_cjs_module.cpp +++ b/ecmascript/require/js_cjs_module.cpp @@ -108,8 +108,7 @@ JSHandle CjsModule::Load(JSThread *thread, JSHandle & RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); filename = recordName; } else { - JSHandle entrypointVal(thread, EcmaInterpreter::GetCurrentEntryPoint(thread).first); - CString currentEntryPoint = ModulePathHelper::Utf8ConvertToString(entrypointVal.GetTaggedValue()); + CString currentEntryPoint = EcmaInterpreter::GetCurrentEntryPoint(thread).first; requestEntryPoint = ModulePathHelper::ConcatFileNameWithMerge(thread, jsPandaFile, filename, currentEntryPoint, requestStr); recordName = requestEntryPoint; diff --git a/ecmascript/shared_object_factory.cpp b/ecmascript/shared_object_factory.cpp index 1d3084d2c4..a68126ddab 100644 --- a/ecmascript/shared_object_factory.cpp +++ b/ecmascript/shared_object_factory.cpp @@ -667,8 +667,6 @@ JSHandle ObjectFactory::NewSSourceTextModule() JSTaggedValue undefinedValue = thread_->GlobalConstants()->GetUndefined(); obj->SetEnvironment(thread_, undefinedValue); obj->SetNamespace(thread_, undefinedValue); - obj->SetEcmaModuleFilename(thread_, undefinedValue); - obj->SetEcmaModuleRecordName(thread_, undefinedValue); obj->SetRequestedModules(thread_, undefinedValue); obj->SetImportEntries(thread_, undefinedValue); obj->SetLocalExportEntries(thread_, undefinedValue); @@ -690,6 +688,8 @@ JSHandle ObjectFactory::NewSSourceTextModule() obj->SetIsNewBcVersion(false); obj->SetRegisterCounts(UINT16_MAX); obj->SetLazyImportStatus(ToUintPtr(nullptr)); + obj->SetEcmaModuleFilename(ToUintPtr(nullptr)); + obj->SetEcmaModuleRecordName(ToUintPtr(nullptr)); obj->SetSharedType(SharedTypes::UNSENDABLE_MODULE); obj->SetSendableEnv(thread_, undefinedValue); return obj; diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index 7f50e81fba..cc207dbe4e 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -1674,7 +1674,7 @@ JSTaggedValue RuntimeStubs::RuntimeDynamicImport(JSThread *thread, const JSHandl if (jsPandaFile->IsBundlePack()) { dirPath.Update(factory->NewFromUtf8(currentfilename).GetTaggedValue()); } else { - recordName.Update(function->GetRecordName()); + recordName.Update(factory->NewFromUtf8(function->GetRecordName())); dirPath.Update(factory->NewFromUtf8(currentfilename).GetTaggedValue()); } diff --git a/test/fuzztest/jsvaluerefismodulenamespace_fuzzer/jsvaluerefismodulenamespace_fuzzer.cpp b/test/fuzztest/jsvaluerefismodulenamespace_fuzzer/jsvaluerefismodulenamespace_fuzzer.cpp index 7f3e53eb92..550b5be361 100644 --- a/test/fuzztest/jsvaluerefismodulenamespace_fuzzer/jsvaluerefismodulenamespace_fuzzer.cpp +++ b/test/fuzztest/jsvaluerefismodulenamespace_fuzzer/jsvaluerefismodulenamespace_fuzzer.cpp @@ -52,8 +52,7 @@ void IsModuleNamespaceObjectFuzztest([[maybe_unused]]const uint8_t *data, size_t SourceTextModule::AddLocalExportEntry(vm->GetJSThread(), module, localExportEntry2, 1, ERROR_TYPE_LEN); JSHandle localExportEntries(vm->GetJSThread(), module->GetLocalExportEntries()); CString baseFileName = "a.abc"; - JSHandle moduleFilename = objectFactory->NewFromUtf8(baseFileName); - module->SetEcmaModuleFilename(vm->GetJSThread(), moduleFilename); + module->SetEcmaModuleFilenameString(baseFileName); ModuleManager *moduleManager = vm->GetJSThread()->GetCurrentEcmaContext()->GetModuleManager(); moduleManager->AddResolveImportedModule(baseFileName, module.GetTaggedValue()); JSHandle np = ModuleNamespace::ModuleNamespaceCreate(vm->GetJSThread(),