From dbca2637e072a6b79dfe704b0dc5fbf06d0923fa Mon Sep 17 00:00:00 2001 From: z00932658 Date: Tue, 17 Jun 2025 21:15:04 +0800 Subject: [PATCH 1/2] Revert "add hybrid for load_module_with_info" Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICIBCU Signed-off-by: zhushihao Change-Id: I69e9dc74300ca9a064a9cdce67c39ada7a0427a7 --- ecmascript/builtins/builtins_global.cpp | 2 +- ecmascript/builtins/builtins_promise_job.cpp | 4 +-- ecmascript/ecma_vm.h | 2 +- .../jspandafile/js_pandafile_executor.cpp | 8 +++--- .../jspandafile/js_pandafile_manager.cpp | 9 +++---- ecmascript/jspandafile/js_pandafile_manager.h | 4 +-- .../tests/js_pandafile_manager_test.cpp | 2 +- ecmascript/module/js_module_source_text.cpp | 4 +-- ecmascript/module/module_resolver.cpp | 13 ++++----- ecmascript/module/napi_module_loader.cpp | 27 +++++++++---------- ecmascript/module/napi_module_loader.h | 11 ++++---- ecmascript/napi/include/jsnapi_expo.h | 4 +-- ecmascript/napi/jsnapi_expo.cpp | 8 +++--- ecmascript/napi/test/ffi_workload.cpp | 5 ++-- ecmascript/napi/test/jsnapi_third_tests.cpp | 2 +- ecmascript/patch/quick_fix_manager.cpp | 4 +-- ecmascript/require/js_cjs_module.cpp | 2 +- ...isethostpromiserejectiontracker_fuzzer.cpp | 2 +- 18 files changed, 54 insertions(+), 59 deletions(-) diff --git a/ecmascript/builtins/builtins_global.cpp b/ecmascript/builtins/builtins_global.cpp index b7ddbce6bd..3a47f6f84c 100644 --- a/ecmascript/builtins/builtins_global.cpp +++ b/ecmascript/builtins/builtins_global.cpp @@ -731,7 +731,7 @@ JSTaggedValue BuiltinsGlobal::LoadNativeModule(EcmaRuntimeCallInfo *msg) CString abcFilePath = fileName.c_str(); if (moduleName.size() != 0) { curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, abcFilePath, requestPath, false, false, ExecuteTypes::STATIC); + thread, abcFilePath, requestPath, false, ExecuteTypes::STATIC); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (curJsPandaFile == nullptr) { errorMsg = "Load native module failed, filename '" + abcFilePath + diff --git a/ecmascript/builtins/builtins_promise_job.cpp b/ecmascript/builtins/builtins_promise_job.cpp index d8de2bf3b6..d705932ca9 100644 --- a/ecmascript/builtins/builtins_promise_job.cpp +++ b/ecmascript/builtins/builtins_promise_job.cpp @@ -158,7 +158,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) if (!recordName->IsUndefined()) { recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue()); curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, fileName, recordNameStr.c_str(), false, false, ExecuteTypes::STATIC); + thread, fileName, recordNameStr.c_str(), false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); if (curJsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << recordNameStr; @@ -194,7 +194,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) moduleName = entryPoint; } std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, fileName, entryPoint, false, false, ExecuteTypes::STATIC); + thread, fileName, entryPoint, false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); if (jsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << fileName; diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index 68c438a26d..f427221a0d 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -128,7 +128,7 @@ using SourceMapCallback = std::function; using ResolveBufferCallback = - std::function; + std::function; using TimerCallbackFunc = void (*)(void *data); using TimerTaskCallback = void* (*)(EcmaVM *vm, void *data, TimerCallbackFunc func, uint64_t timeout, bool repeat); using CancelTimerCallback = void (*)(void *timerCallbackInfo); diff --git a/ecmascript/jspandafile/js_pandafile_executor.cpp b/ecmascript/jspandafile/js_pandafile_executor.cpp index 128e69084a..7e15c9abd7 100644 --- a/ecmascript/jspandafile/js_pandafile_executor.cpp +++ b/ecmascript/jspandafile/js_pandafile_executor.cpp @@ -33,7 +33,7 @@ Expected JSPandaFileExecutor::ExecuteFromFile(JSThread *thr EcmaVM *vm = thread->GetEcmaVM(); std::shared_ptr jsPandaFile = - JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, name, entry, needUpdate, false, executeType); + JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, name, entry, needUpdate, executeType); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, Unexpected(false)); if (jsPandaFile == nullptr) { #ifdef FUZZ_TEST @@ -429,7 +429,7 @@ Expected JSPandaFileExecutor::LazyExecuteModule( std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, filename, recordName, false, false, ExecuteTypes::STATIC); + thread, filename, recordName, false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, Unexpected(false)); if (jsPandaFile == nullptr) { #ifdef FUZZ_TEST @@ -476,7 +476,7 @@ int JSPandaFileExecutor::ExecuteAbcFileWithSingletonPatternFlag(JSThread *thread { CString abcFilePath = ModulePathHelper::ConcatPandaFilePath(moduleName); std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, abcFilePath, entry, false, false, ExecuteTypes::STATIC); + thread, abcFilePath, entry, false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ROUTE_URI_ERROR); if (jsPandaFile == nullptr) { LOG_ECMA(ERROR) << "When the route jump, loading panda file failed. Current file is " << abcFilePath; @@ -519,7 +519,7 @@ bool JSPandaFileExecutor::IsExecuteModuleInAbcFile(JSThread *thread, [[maybe_unu return false; } std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, abcFilePath, entry, false, false, ExecuteTypes::STATIC); + thread, abcFilePath, entry, false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (jsPandaFile == nullptr) { LOG_ECMA(ERROR) << "When checking if module is in abc file, loading panda file failed. Current file is " << diff --git a/ecmascript/jspandafile/js_pandafile_manager.cpp b/ecmascript/jspandafile/js_pandafile_manager.cpp index 30feebd395..1c039b6840 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.cpp +++ b/ecmascript/jspandafile/js_pandafile_manager.cpp @@ -50,7 +50,7 @@ JSPandaFileManager::~JSPandaFileManager() * Specifically, return jscrash if napi load hsp failed. */ std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, const CString &filename, - std::string_view entryPoint, bool needUpdate, bool isHybrid, const ExecuteTypes &executeType) + std::string_view entryPoint, bool needUpdate, const ExecuteTypes &executeType) { { LockHolder lock(jsPandaFileLock_); @@ -97,7 +97,7 @@ std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *threa uint8_t *data = nullptr; size_t dataSize = 0; std::string errorMsg; - bool getBuffer = resolveBufferCallback(hspPath, isHybrid, &data, &dataSize, errorMsg); + bool getBuffer = resolveBufferCallback(hspPath, &data, &dataSize, errorMsg); if (!getBuffer) { LoadJSPandaFileFailLog("[ArkRuntime Log] Importing shared package in the Previewer."); CString msg = "resolveBufferCallback get hsp buffer failed, hsp path:" + filename + @@ -552,7 +552,7 @@ std::shared_ptr JSPandaFileManager::GenerateJSPandaFile(JSThread *t /* * Check whether the file path can be loaded into pandafile, excluding bundle packaging and decompression paths */ -bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName, bool isHybrid) +bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName) { std::shared_ptr jsPandaFile = FindJSPandaFileUnlocked(fileName); if (jsPandaFile != nullptr) { @@ -569,8 +569,7 @@ bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName uint8_t *data = nullptr; size_t dataSize = 0; std::string errorMsg; - bool getBuffer = - resolveBufferCallback(ModulePathHelper::ParseHapPath(fileName), isHybrid, &data, &dataSize, errorMsg); + bool getBuffer = resolveBufferCallback(ModulePathHelper::ParseHapPath(fileName), &data, &dataSize, errorMsg); if (!getBuffer) { LOG_FULL(ERROR) << "When checking file path, resolveBufferCallback get buffer failed, errorMsg = " << errorMsg; diff --git a/ecmascript/jspandafile/js_pandafile_manager.h b/ecmascript/jspandafile/js_pandafile_manager.h index 734a0f34d0..460ac1c5a4 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.h +++ b/ecmascript/jspandafile/js_pandafile_manager.h @@ -34,7 +34,7 @@ public: JSHandle GenerateProgram(EcmaVM *vm, const JSPandaFile *jsPandaFile, std::string_view entryPoint); std::shared_ptr LoadJSPandaFile(JSThread *thread, const CString &filename, std::string_view entryPoint, - bool needUpdate = false, bool isHybrid = false, + bool needUpdate = false, const ExecuteTypes &executeType = ExecuteTypes::STATIC); std::shared_ptr LoadJSPandaFile(JSThread *thread, const CString &filename, std::string_view entryPoint, @@ -59,7 +59,7 @@ public: DebugInfoExtractor *CpuProfilerGetJSPtExtractor(const JSPandaFile *jsPandaFile); - bool CheckFilePath(JSThread *thread, const CString &fileName, bool isHybrid = false); + bool CheckFilePath(JSThread *thread, const CString &fileName); // for debugger template diff --git a/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp b/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp index 1f369a8356..f1eecb2bc6 100644 --- a/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp +++ b/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp @@ -166,7 +166,7 @@ HWTEST_F_L0(JSPandaFileManagerTest, MultiEcmaVM_Add_Find_Remove_JSPandaFile) JSThread *thread1; TestHelper::CreateEcmaVMWithScope(instance1, thread1, scope1); std::shared_ptr loadedPf1 = pfManager->LoadJSPandaFile( - thread1, filename1, JSPandaFile::ENTRY_MAIN_FUNCTION, false, false, ExecuteTypes::STATIC); + thread1, filename1, JSPandaFile::ENTRY_MAIN_FUNCTION, false, ExecuteTypes::STATIC); EXPECT_TRUE(pf1 == loadedPf1); EXPECT_TRUE(instance1->GetJSThread()->GetEcmaVM()->HasCachedConstpool(pf1.get())); TestHelper::DestroyEcmaVMWithScope(instance1, scope1); // Remove 'instance1' when ecmaVM destruct. diff --git a/ecmascript/module/js_module_source_text.cpp b/ecmascript/module/js_module_source_text.cpp index 5e71844da8..c739f52308 100644 --- a/ecmascript/module/js_module_source_text.cpp +++ b/ecmascript/module/js_module_source_text.cpp @@ -1186,7 +1186,7 @@ Expected SourceTextModule::ModuleExecution(JSThread *thread JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFilenameStr, entryPoint, buffer, size); } else { jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFilenameStr, entryPoint, false, false, executeType); + thread, moduleFilenameStr, entryPoint, false, executeType); } RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, Unexpected(false)); if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE @@ -1728,7 +1728,7 @@ void SourceTextModule::ExecuteAsyncModule(JSThread *thread, const JSHandleLoadJSPandaFile(thread, moduleFilenameStr, entryPoint, buffer, size); } else { jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFilenameStr, entryPoint, false, false, executeType); + thread, moduleFilenameStr, entryPoint, false, executeType); } RETURN_IF_ABRUPT_COMPLETION(thread); if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE diff --git a/ecmascript/module/module_resolver.cpp b/ecmascript/module/module_resolver.cpp index 355886d392..69ded0c7d7 100644 --- a/ecmascript/module/module_resolver.cpp +++ b/ecmascript/module/module_resolver.cpp @@ -43,7 +43,7 @@ JSHandle ModuleResolver::HostResolveImportedModule(JSThread* thre { if (jsPandaFile == nullptr) { std::shared_ptr file = - JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, recordName, false, false, executeType); + JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, recordName, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (file == nullptr) { CString msg = "Load file with filename '" + fileName + "' failed, recordName '" + recordName + "'"; @@ -103,7 +103,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleWithMerge(JSThr } CString recordName = module->GetEcmaModuleRecordNameString(); std::shared_ptr pandaFile = - JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFilename, recordName, false, false, executeType); + JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFilename, recordName, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (pandaFile == nullptr) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << baseFilename; @@ -182,7 +182,8 @@ JSHandle ModuleResolver::HostResolveImportedModuleForHotReload(JS const ExecuteTypes &executeType) { std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFileName, recordName, false, false, executeType); + thread, moduleFileName, recordName, false, executeType); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << moduleFileName; } @@ -209,7 +210,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleWithMerge(JSThr { if (jsPandaFile == nullptr) { std::shared_ptr file = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFileName, recordName, false, false, executeType); + thread, moduleFileName, recordName, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (file == nullptr) { CString msg = "Load file with filename '" + moduleFileName + "' failed, recordName '" + recordName + "'"; @@ -257,7 +258,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleBundlePack(JSTh // Can not use jsPandaFile from js_pandafile_executor, need to construct with JSPandaFile::ENTRY_MAIN_FUNCTION std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, referencingModule, JSPandaFile::ENTRY_MAIN_FUNCTION, false, false, executeType); + thread, referencingModule, JSPandaFile::ENTRY_MAIN_FUNCTION, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << referencingModule; @@ -278,7 +279,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleBundlePack(JSTh return module; } std::shared_ptr pandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFileName, JSPandaFile::ENTRY_MAIN_FUNCTION, false, false, executeType); + thread, moduleFileName, JSPandaFile::ENTRY_MAIN_FUNCTION, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (pandaFile == nullptr) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << referencingModule; diff --git a/ecmascript/module/napi_module_loader.cpp b/ecmascript/module/napi_module_loader.cpp index 9ffb7ec702..f996390a7d 100644 --- a/ecmascript/module/napi_module_loader.cpp +++ b/ecmascript/module/napi_module_loader.cpp @@ -22,8 +22,7 @@ namespace panda::ecmascript { JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(EcmaVM *vm, CString &requestPath, - CString &modulePath, CString &abcFilePath, - bool isHybrid) + CString &modulePath, CString &abcFilePath) { LOG_ECMA(INFO) << "NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo requestPath:" << requestPath << "," << "modulePath:" << modulePath; @@ -31,7 +30,7 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(Ecma std::shared_ptr curJsPandaFile; if (!modulePath.empty()) { curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, abcFilePath, requestPath, false, - isHybrid, ExecuteTypes::NAPI); + ExecuteTypes::NAPI); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (curJsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << abcFilePath; @@ -49,8 +48,7 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(Ecma } JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, - const CString &moduleName, CString &abcFilePath, - bool isHybrid) + const CString &moduleName, CString &abcFilePath) { JSThread *thread = vm->GetJSThread(); CString path = base::ConcatToCString(vm->GetBundleName(), PathHelper::SLASH_TAG); @@ -67,13 +65,12 @@ JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CStrin path += abcModuleName; // RequestPath starts with moduleName/src/main/xxx if (StringHelper::StringStartWith(requestPath, srcPrefix)) { - return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, path, isHybrid); + return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, path); } - return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, path, abcFilePath, isHybrid); + return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, path, abcFilePath); } -JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, CString modulePath, - bool isHybrid) +JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, CString modulePath) { JSThread *thread = vm->GetJSThread(); CString moduleName = ModulePathHelper::GetModuleNameWithPath(modulePath); @@ -81,20 +78,20 @@ JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CStrin CString srcPrefix = base::ConcatToCString(moduleName, ModulePathHelper::PHYCICAL_FILE_PATH.data()); // RequestPath starts with moduleName/src/main/xxx if (StringHelper::StringStartWith(requestPath, srcPrefix)) { - return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, modulePath, isHybrid); + return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, modulePath); } - return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, modulePath, abcFilePath, isHybrid); + return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, modulePath, abcFilePath); } JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thread, const CString& abcFilePath, - const CString& srcPrefix, const CString& requestPath, const CString& modulePath, bool isHybrid) + const CString& srcPrefix, const CString& requestPath, const CString& modulePath) { if (requestPath.size() > srcPrefix.size()) { // Sub after moduleName/src/main/ CString fileName = requestPath.substr(srcPrefix.size() + 1); CString recordNameStr = ModulePathHelper::TranslateNapiFileRequestPath(thread, modulePath, fileName); LOG_ECMA(DEBUG) << "NapiModuleLoader::LoadFilePathWithinModule: Concated recordName " << recordNameStr; - return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath, isHybrid); + return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); } else { CString msg = "cannot find record '" + requestPath + "' in basefileName " + abcFilePath + "," + "from napi load module"; @@ -117,10 +114,10 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithPath(JSThread * } JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( - JSThread *thread, const CString &entryPoint, const CString &abcFilePath, bool isHybrid) + JSThread *thread, const CString &entryPoint, const CString &abcFilePath) { std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, abcFilePath, entryPoint, false, isHybrid, ExecuteTypes::NAPI); + thread, abcFilePath, entryPoint, false, ExecuteTypes::NAPI); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (jsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << abcFilePath; diff --git a/ecmascript/module/napi_module_loader.h b/ecmascript/module/napi_module_loader.h index 05f523e4eb..3f6575ac13 100644 --- a/ecmascript/module/napi_module_loader.h +++ b/ecmascript/module/napi_module_loader.h @@ -21,18 +21,18 @@ namespace panda::ecmascript { class NapiModuleLoader { public: static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, const CString &moduleName, - CString &abcFilePath, bool isHybrid = false); + CString &abcFilePath); static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, - CString modulePath, bool isHybrid = false); + CString modulePath); static JSHandle GetModuleNameSpace(JSThread *thread, const CString &entryPoint, const CString &abcFilePath); static JSHandle LoadModuleNameSpaceFromFile(JSThread *thread, const CString &entryPoint, - const CString &abcFilePath, bool isHybrid = false); + const CString &abcFilePath); private: static JSHandle LoadModuleNameSpaceWithModuleInfo( EcmaVM *vm, CString &requestPath, CString &modulePath, - CString &abcFilePath, bool isHybrid = false); + CString &abcFilePath); static JSHandle LoadModuleNameSpaceWithPath( JSThread *thread, CString &abcFilePath, const CString &requestPath, @@ -40,8 +40,7 @@ private: static JSHandle LoadFilePathWithinModule( JSThread *thread, const CString &abcFilePath, const CString &srcPrefix, - const CString &requestPath, const CString &modulePath, - bool isHybrid = false); + const CString &requestPath, const CString &modulePath); }; } diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index f5d78d3095..c569a670c2 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1710,7 +1710,7 @@ public: static Local ExecuteNativeModule(EcmaVM *vm, const std::string &key); static Local GetModuleNameSpaceFromFile(EcmaVM *vm, const std::string &file); static Local GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std::string &file, - const std::string &module_path, bool isHybrid = false); + const std::string &module_path); static Local GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path); static std::pair ResolveOhmUrl(std::string ohmUrl); @@ -1800,7 +1800,7 @@ public: static void SetCancelTimerCallback(EcmaVM *vm, CancelTimerCallback callback); static void NotifyEnvInitialized(EcmaVM *vm); static void SetReleaseSecureMemCallback(EcmaVM *vm, ReleaseSecureMemCallback releaseSecureMemFunc); - static void SetHostResolveBufferTracker(EcmaVM *vm, std::function cb); static void PandaFileSerialize(const EcmaVM *vm); static void ModuleSerialize(const EcmaVM *vm); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 3a308fb385..1e4369306a 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -6189,7 +6189,7 @@ void JSNApi::ModuleDeserialize(EcmaVM *vm, const uint32_t appVersion) } void JSNApi::SetHostResolveBufferTracker(EcmaVM *vm, - std::function cb) + std::function cb) { vm->SetResolveBufferCallback(cb); } @@ -6411,7 +6411,7 @@ Local JSNApi::GetExportObject(EcmaVM *vm, const std::string &file, co ModulePathHelper::ParseAbcPathAndOhmUrl(vm, entry, name, entry); std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, name, entry.c_str(), false, false, ecmascript::ExecuteTypes::STATIC); + thread, name, entry.c_str(), false, ecmascript::ExecuteTypes::STATIC); if (jsPandaFile == nullptr) { JSHandle exportObj(thread, JSTaggedValue::Null()); return JSNApiHelper::ToLocal(exportObj); @@ -6501,14 +6501,14 @@ Local JSNApi::GetModuleNameSpaceFromFile(EcmaVM *vm, const std::strin } Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std::string &file, - const std::string &module_path, bool isHybrid) + const std::string &module_path) { CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); ecmascript::ThreadManagedScope managedScope(thread); ecmascript::CString requestPath = file.c_str(); ecmascript::CString modulePath = module_path.c_str(); JSHandle nameSp = - ecmascript::NapiModuleLoader::LoadModuleNameSpace(vm, requestPath, modulePath, isHybrid); + ecmascript::NapiModuleLoader::LoadModuleNameSpace(vm, requestPath, modulePath); return JSNApiHelper::ToLocal(nameSp); } diff --git a/ecmascript/napi/test/ffi_workload.cpp b/ecmascript/napi/test/ffi_workload.cpp index cb40ea24c2..e4d5ad2112 100644 --- a/ecmascript/napi/test/ffi_workload.cpp +++ b/ecmascript/napi/test/ffi_workload.cpp @@ -3536,9 +3536,8 @@ HWTEST_F_L0(JSNApiSplTest, JSNApi_SetHostResolveBufferTracker) { LocalScope scope(vm_); CalculateForTime(); - std::function - cb = [](const std::string &inputPath, bool isHybrid, - uint8_t **buff, size_t *buffSize, std::string &errorMsg) -> bool { + std::function cb = + [](const std::string &inputPath, uint8_t **buff, size_t *buffSize, std::string &errorMsg) -> bool { if (inputPath.empty() || buff == nullptr || buffSize == nullptr) { return false; } diff --git a/ecmascript/napi/test/jsnapi_third_tests.cpp b/ecmascript/napi/test/jsnapi_third_tests.cpp index 23fc335d44..160c3cc6ae 100644 --- a/ecmascript/napi/test/jsnapi_third_tests.cpp +++ b/ecmascript/napi/test/jsnapi_third_tests.cpp @@ -697,7 +697,7 @@ HWTEST_F_L0(JSNApiTests, SetHostResolveBufferTracker) { LocalScope scope(vm_); JSNApi::SetHostResolveBufferTracker(vm_, - [&](std::string, bool, uint8_t **, size_t *, std::string &) -> bool { return true; }); + [&](std::string, uint8_t **, size_t *, std::string &) -> bool { return true; }); } /* diff --git a/ecmascript/patch/quick_fix_manager.cpp b/ecmascript/patch/quick_fix_manager.cpp index aac16b7587..0c03de0f2f 100644 --- a/ecmascript/patch/quick_fix_manager.cpp +++ b/ecmascript/patch/quick_fix_manager.cpp @@ -87,7 +87,7 @@ PatchErrorCode QuickFixManager::LoadPatch(JSThread *thread, const std::string &p } std::shared_ptr baseFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, baseFileName.c_str(), "", false, false, ExecuteTypes::STATIC); + thread, baseFileName.c_str(), "", false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, PatchErrorCode::FILE_NOT_FOUND); if (baseFile == nullptr) { LOG_ECMA(ERROR) << "find base jsPandafile failed"; @@ -96,7 +96,7 @@ PatchErrorCode QuickFixManager::LoadPatch(JSThread *thread, const std::string &p // The entry point is not work for merge abc. std::shared_ptr patchFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, patchFileName.c_str(), "", false, false, ExecuteTypes::STATIC); + thread, patchFileName.c_str(), "", false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, PatchErrorCode::FILE_NOT_FOUND); if (patchFile == nullptr) { LOG_ECMA(ERROR) << "load patch jsPandafile failed"; diff --git a/ecmascript/require/js_cjs_module.cpp b/ecmascript/require/js_cjs_module.cpp index cbd78169ae..f535398f65 100644 --- a/ecmascript/require/js_cjs_module.cpp +++ b/ecmascript/require/js_cjs_module.cpp @@ -160,7 +160,7 @@ void CjsModule::RequireExecution(JSThread *thread, const CString &mergedFilename { std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, mergedFilename, requestEntryPoint, false, false, ExecuteTypes::STATIC); + thread, mergedFilename, requestEntryPoint, false, ExecuteTypes::STATIC); RETURN_IF_ABRUPT_COMPLETION(thread); if (jsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << mergedFilename; diff --git a/test/fuzztest/jsnapisethostpromiserejectiontracker_fuzzer/jsnapisethostpromiserejectiontracker_fuzzer.cpp b/test/fuzztest/jsnapisethostpromiserejectiontracker_fuzzer/jsnapisethostpromiserejectiontracker_fuzzer.cpp index 79f69541de..206f697429 100644 --- a/test/fuzztest/jsnapisethostpromiserejectiontracker_fuzzer/jsnapisethostpromiserejectiontracker_fuzzer.cpp +++ b/test/fuzztest/jsnapisethostpromiserejectiontracker_fuzzer/jsnapisethostpromiserejectiontracker_fuzzer.cpp @@ -56,7 +56,7 @@ namespace OHOS { uint8_t* ptr = nullptr; ptr = const_cast(data); JSNApi::SetHostResolveBufferTracker(vm, - [&](std::string, bool, uint8_t **, size_t *, std::string &) -> bool { return true; }); + [&](std::string, uint8_t **, size_t *, std::string &) -> bool { return true; }); JSNApi::DestroyJSVM(vm); } -- Gitee From 5d0432cad91b7a62d1996c6cac690ed3c6c088e5 Mon Sep 17 00:00:00 2001 From: z00932658 Date: Sat, 21 Jun 2025 14:35:20 +0800 Subject: [PATCH 2/2] Fix isHybrid for ets_runtime Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICIBCU Signed-off-by: zhushihao Change-Id: Iaf85672f1cfa73c37504edc9c7349938c84078ba --- .../compiler/aot_file/tests/aot_file_test.cpp | 4 +- ecmascript/ecma_vm.h | 11 +++++ .../jspandafile/js_pandafile_manager.cpp | 15 +++++++ ecmascript/jspandafile/js_pandafile_manager.h | 4 +- ecmascript/module/napi_module_loader.cpp | 44 +++++++++++++++---- ecmascript/module/napi_module_loader.h | 8 +++- ecmascript/napi/include/jsnapi_expo.h | 12 +++++ ecmascript/napi/jsnapi_expo.cpp | 27 +++++++++++- 8 files changed, 110 insertions(+), 15 deletions(-) diff --git a/ecmascript/compiler/aot_file/tests/aot_file_test.cpp b/ecmascript/compiler/aot_file/tests/aot_file_test.cpp index dc311d04c3..cdc950e9c8 100644 --- a/ecmascript/compiler/aot_file/tests/aot_file_test.cpp +++ b/ecmascript/compiler/aot_file/tests/aot_file_test.cpp @@ -316,7 +316,7 @@ protected: // Ensure AOT file exists ASSERT_TRUE(AOTFileManager::AOTFileExist(testAotPath_, AOTFileManager::FILE_EXTENSION_AN)); std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - vm->GetJSThread(), CString(testAbcPath_.c_str()), testRecordName_, false, false, ExecuteTypes::STATIC); + vm->GetJSThread(), CString(testAbcPath_.c_str()), testRecordName_, false, ExecuteTypes::STATIC); ASSERT_TRUE(jsPandaFile != nullptr); // Perform binding vm->GetAOTFileManager()->BindPreloadedPandaFilesInAotFile(testRecordName_); @@ -368,7 +368,6 @@ protected: CString(testAbcPath.c_str()), testRecordName, false, - false, ExecuteTypes::STATIC); ASSERT_TRUE(jsPandaFile.get() != nullptr); // Test command-line mode branch @@ -401,7 +400,6 @@ protected: CString(testAbcPath.c_str()), testRecordName, false, - false, ExecuteTypes::STATIC); ASSERT_TRUE(jsPandaFile.get() != nullptr); // Verify WasAOTOutputFileSet is false diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index f427221a0d..f944146181 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -556,6 +556,16 @@ public: return resolveBufferCallback_; } + void SetResolveBufferCallbackForHybridApp(ResolveBufferCallback cb) + { + resolveBufferCallbackForHybridApp_ = cb; + } + + ResolveBufferCallback GetResolveBufferCallbackForHybridApp() const + { + return resolveBufferCallbackForHybridApp_; + } + void SetTimerTaskCallback(TimerTaskCallback callback) { timerTaskCallback_ = callback; @@ -1439,6 +1449,7 @@ private: // resolve path to get abc's buffer ResolveBufferCallback resolveBufferCallback_ {nullptr}; + ResolveBufferCallback resolveBufferCallbackForHybridApp_ {nullptr}; // set timer task to execute callback on time TimerTaskCallback timerTaskCallback_ {nullptr}; diff --git a/ecmascript/jspandafile/js_pandafile_manager.cpp b/ecmascript/jspandafile/js_pandafile_manager.cpp index 1c039b6840..7bc3bb51cf 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.cpp +++ b/ecmascript/jspandafile/js_pandafile_manager.cpp @@ -49,6 +49,7 @@ JSPandaFileManager::~JSPandaFileManager() * Typically return nullptr for JSPandafile load fail. Throw cppcrash if load hsp failed. * Specifically, return jscrash if napi load hsp failed. */ +template std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, const CString &filename, std::string_view entryPoint, bool needUpdate, const ExecuteTypes &executeType) { @@ -79,6 +80,9 @@ std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *threa if (!vm->IsBundlePack() && moduleManager->GetExecuteMode() == ModuleExecuteMode::ExecuteBufferMode && !vm->IsRestrictedWorkerThread()) { ResolveBufferCallback resolveBufferCallback = vm->GetResolveBufferCallback(); + if constexpr (isHybrid == ForHybridApp::Hybrid) { + resolveBufferCallback = vm->GetResolveBufferCallbackForHybridApp(); + } if (resolveBufferCallback == nullptr) { LoadJSPandaFileFailLog("[ArkRuntime Log] Importing shared package is not supported in the Previewer."); LOG_FULL(FATAL) << "resolveBufferCallback is nullptr"; @@ -130,6 +134,10 @@ std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *threa #endif return jsPandaFile; } +template std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, + const CString &filename, std::string_view entryPoint, bool needUpdate, const ExecuteTypes &executeType); +template std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, + const CString &filename, std::string_view entryPoint, bool needUpdate, const ExecuteTypes &executeType); // The security interface needs to be modified accordingly. std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, const CString &filename, @@ -552,6 +560,7 @@ std::shared_ptr JSPandaFileManager::GenerateJSPandaFile(JSThread *t /* * Check whether the file path can be loaded into pandafile, excluding bundle packaging and decompression paths */ +template bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName) { std::shared_ptr jsPandaFile = FindJSPandaFileUnlocked(fileName); @@ -562,6 +571,9 @@ bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName ModuleManager *moduleManager = thread->GetModuleManager(); if (!vm->IsBundlePack() && moduleManager->GetExecuteMode() == ModuleExecuteMode::ExecuteBufferMode) { ResolveBufferCallback resolveBufferCallback = vm->GetResolveBufferCallback(); + if constexpr (isHybrid == ForHybridApp::Hybrid) { + resolveBufferCallback = vm->GetResolveBufferCallbackForHybridApp(); + } if (resolveBufferCallback == nullptr) { LOG_FULL(ERROR) << "When checking file path, resolveBufferCallback is nullptr"; return false; @@ -579,6 +591,9 @@ bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName return true; } +template bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName); +template bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName); + std::shared_ptr JSPandaFileManager::GenerateJSPandafileFromBufferCache( JSThread *thread, const CString &filename, std::string_view entryPoint) { diff --git a/ecmascript/jspandafile/js_pandafile_manager.h b/ecmascript/jspandafile/js_pandafile_manager.h index 460ac1c5a4..bbdb83cd38 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.h +++ b/ecmascript/jspandafile/js_pandafile_manager.h @@ -33,6 +33,7 @@ public: JSHandle GenerateProgram(EcmaVM *vm, const JSPandaFile *jsPandaFile, std::string_view entryPoint); + template std::shared_ptr LoadJSPandaFile(JSThread *thread, const CString &filename, std::string_view entryPoint, bool needUpdate = false, const ExecuteTypes &executeType = ExecuteTypes::STATIC); @@ -58,7 +59,8 @@ public: DebugInfoExtractor *GetJSPtExtractorAndExtract(const JSPandaFile *jsPandaFile); DebugInfoExtractor *CpuProfilerGetJSPtExtractor(const JSPandaFile *jsPandaFile); - + + template bool CheckFilePath(JSThread *thread, const CString &fileName); // for debugger diff --git a/ecmascript/module/napi_module_loader.cpp b/ecmascript/module/napi_module_loader.cpp index f996390a7d..70839d928f 100644 --- a/ecmascript/module/napi_module_loader.cpp +++ b/ecmascript/module/napi_module_loader.cpp @@ -21,6 +21,7 @@ #include "ecmascript/jspandafile/js_pandafile_executor.h" namespace panda::ecmascript { +template JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(EcmaVM *vm, CString &requestPath, CString &modulePath, CString &abcFilePath) { @@ -29,8 +30,8 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(Ecma JSThread *thread = vm->GetJSThread(); std::shared_ptr curJsPandaFile; if (!modulePath.empty()) { - curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, abcFilePath, requestPath, false, - ExecuteTypes::NAPI); + curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, + abcFilePath, requestPath, false, ExecuteTypes::NAPI); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (curJsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << abcFilePath; @@ -46,7 +47,12 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(Ecma curJsPandaFile.get()); return nameSp; } +template JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(EcmaVM *vm, + CString &requestPath, CString &modulePath, CString &abcFilePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(EcmaVM *vm, + CString &requestPath, CString &modulePath, CString &abcFilePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, const CString &moduleName, CString &abcFilePath) { @@ -58,18 +64,24 @@ JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CStrin path += moduleName; CString recordNameStr = ModulePathHelper::TranslateNapiFileRequestPath(thread, path, requestPath); LOG_ECMA(DEBUG) << "NapiModuleLoader::LoadFilePathWithinModule: Concated recordName " << recordNameStr; - return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); + return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); } CString abcModuleName = ModulePathHelper::GetModuleNameWithBaseFile(abcFilePath); CString srcPrefix = base::ConcatToCString(abcModuleName, ModulePathHelper::PHYCICAL_FILE_PATH.data()); path += abcModuleName; // RequestPath starts with moduleName/src/main/xxx if (StringHelper::StringStartWith(requestPath, srcPrefix)) { - return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, path); + return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, path); } - return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, path, abcFilePath); + return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, path, abcFilePath); } +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, const CString& moduleName, CString& abcFilePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, const CString& moduleName, CString& abcFilePath); + +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, CString modulePath) { JSThread *thread = vm->GetJSThread(); @@ -78,11 +90,16 @@ JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CStrin CString srcPrefix = base::ConcatToCString(moduleName, ModulePathHelper::PHYCICAL_FILE_PATH.data()); // RequestPath starts with moduleName/src/main/xxx if (StringHelper::StringStartWith(requestPath, srcPrefix)) { - return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, modulePath); + return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, modulePath); } - return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, modulePath, abcFilePath); + return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, modulePath, abcFilePath); } +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, CString modulePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, CString modulePath); +template JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thread, const CString& abcFilePath, const CString& srcPrefix, const CString& requestPath, const CString& modulePath) { @@ -91,13 +108,17 @@ JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thr CString fileName = requestPath.substr(srcPrefix.size() + 1); CString recordNameStr = ModulePathHelper::TranslateNapiFileRequestPath(thread, modulePath, fileName); LOG_ECMA(DEBUG) << "NapiModuleLoader::LoadFilePathWithinModule: Concated recordName " << recordNameStr; - return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); + return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); } else { CString msg = "cannot find record '" + requestPath + "' in basefileName " + abcFilePath + "," + "from napi load module"; THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str()); } } +template JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thread, + const CString& abcFilePath, const CString& srcPrefix, const CString& requestPath, const CString& modulePath); +template JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thread, + const CString& abcFilePath, const CString& srcPrefix, const CString& requestPath, const CString& modulePath); JSHandle NapiModuleLoader::LoadModuleNameSpaceWithPath(JSThread *thread, CString &abcFilePath, const CString &requestPath, const CString &modulePath, const JSPandaFile *pandaFile) @@ -113,10 +134,11 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithPath(JSThread * return LoadModuleNameSpaceFromFile(thread, entryPoint, abcFilePath); } +template JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( JSThread *thread, const CString &entryPoint, const CString &abcFilePath) { - std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( + std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( thread, abcFilePath, entryPoint, false, ExecuteTypes::NAPI); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (jsPandaFile == nullptr) { @@ -139,6 +161,10 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( return ecmascript::NapiModuleLoader::GetModuleNameSpace( thread, entryPoint, abcFilePath); } +template JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( + JSThread *thread, const CString &entryPoint, const CString &abcFilePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( + JSThread *thread, const CString &entryPoint, const CString &abcFilePath); JSHandle NapiModuleLoader::GetModuleNameSpace(JSThread *thread, const CString &entryPoint, const CString &abcFilePath) diff --git a/ecmascript/module/napi_module_loader.h b/ecmascript/module/napi_module_loader.h index 3f6575ac13..fe702b5f2a 100644 --- a/ecmascript/module/napi_module_loader.h +++ b/ecmascript/module/napi_module_loader.h @@ -20,16 +20,21 @@ namespace panda::ecmascript { class NapiModuleLoader { public: + template static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, const CString &moduleName, CString &abcFilePath); + template static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, CString modulePath); static JSHandle GetModuleNameSpace(JSThread *thread, const CString &entryPoint, const CString &abcFilePath); + + template static JSHandle LoadModuleNameSpaceFromFile(JSThread *thread, const CString &entryPoint, const CString &abcFilePath); private: + template static JSHandle LoadModuleNameSpaceWithModuleInfo( EcmaVM *vm, CString &requestPath, CString &modulePath, CString &abcFilePath); @@ -37,7 +42,8 @@ private: static JSHandle LoadModuleNameSpaceWithPath( JSThread *thread, CString &abcFilePath, const CString &requestPath, const CString &modulePath, const JSPandaFile *pandaFile); - + + template static JSHandle LoadFilePathWithinModule( JSThread *thread, const CString &abcFilePath, const CString &srcPrefix, const CString &requestPath, const CString &modulePath); diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index c569a670c2..108959737f 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -90,6 +90,11 @@ enum class QueueType : uint8_t { } } // namespace ecmascript +enum class ForHybridApp { + Normal, + Hybrid +}; + struct HmsMap { std::string originalPath; std::string targetPath; @@ -1709,8 +1714,13 @@ public: static Local GetExportObjectFromOhmUrl(EcmaVM *vm, const std::string &ohmUrl, const std::string &key); static Local ExecuteNativeModule(EcmaVM *vm, const std::string &key); static Local GetModuleNameSpaceFromFile(EcmaVM *vm, const std::string &file); + template static Local GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std::string &file, const std::string &module_path); + static Local GetModuleNameSpaceWithModuleInfoForNormalApp(EcmaVM *vm, const std::string &file, + const std::string &module_path); + static Local GetModuleNameSpaceWithModuleInfoForHybridApp(EcmaVM *vm, const std::string &file, + const std::string &module_path); static Local GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path); static std::pair ResolveOhmUrl(std::string ohmUrl); @@ -1805,6 +1815,8 @@ public: static void PandaFileSerialize(const EcmaVM *vm); static void ModuleSerialize(const EcmaVM *vm); static void ModuleDeserialize(EcmaVM *vm, const uint32_t appVersion); + static void SetHostResolveBufferTrackerForHybridApp(EcmaVM *vm, std::function cb); static void SetUnloadNativeModuleCallback(EcmaVM *vm, const std::function &cb); static void SetNativePtrGetter(EcmaVM *vm, void* cb); static void SetSourceMapCallback(EcmaVM *vm, SourceMapCallback cb); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 1e4369306a..75ad5a5717 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -4691,6 +4691,7 @@ void JSNApi::SynchronizVMInfo(EcmaVM *vm, const EcmaVM *hostVM) hostVM->GetAssociatedJSThread()->GetModuleManager(); vmModuleManager->SetExecuteMode(hostVMModuleManager->GetExecuteMode()); vm->SetResolveBufferCallback(hostVM->GetResolveBufferCallback()); + vm->SetResolveBufferCallbackForHybridApp(hostVM->GetResolveBufferCallbackForHybridApp()); } bool JSNApi::IsProfiling(EcmaVM *vm) @@ -6194,6 +6195,13 @@ void JSNApi::SetHostResolveBufferTracker(EcmaVM *vm, vm->SetResolveBufferCallback(cb); } +void JSNApi::SetHostResolveBufferTrackerForHybridApp(EcmaVM *vm, + std::function cb) +{ + vm->SetResolveBufferCallbackForHybridApp(cb); +} + + void JSNApi::SetSearchHapPathTracker(EcmaVM *vm, std::function cb) { @@ -6500,6 +6508,8 @@ Local JSNApi::GetModuleNameSpaceFromFile(EcmaVM *vm, const std::strin return JSNApiHelper::ToLocal(moduleNamespace); } + +template Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std::string &file, const std::string &module_path) { @@ -6508,9 +6518,24 @@ Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std: ecmascript::CString requestPath = file.c_str(); ecmascript::CString modulePath = module_path.c_str(); JSHandle nameSp = - ecmascript::NapiModuleLoader::LoadModuleNameSpace(vm, requestPath, modulePath); + ecmascript::NapiModuleLoader::LoadModuleNameSpace(vm, requestPath, modulePath); return JSNApiHelper::ToLocal(nameSp); } +template Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, + const std::string &file, const std::string &module_path); +template Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, + const std::string &file, const std::string &module_path); + +Local JSNApi::GetModuleNameSpaceWithModuleInfoForNormalApp(EcmaVM *vm, const std::string &file, + const std::string &module_path) +{ + return JSNApi::GetModuleNameSpaceWithModuleInfo(vm, file, module_path); +} +Local JSNApi::GetModuleNameSpaceWithModuleInfoForHybridApp(EcmaVM *vm, const std::string &file, + const std::string &module_path) +{ + return JSNApi::GetModuleNameSpaceWithModuleInfo(vm, file, module_path); +} Local JSNApi::GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path) { -- Gitee