diff --git a/ecmascript/module/js_module_manager.cpp b/ecmascript/module/js_module_manager.cpp index 7e3df3b1309fb2984ee775ee40ca5b6d6613e7bf..6817f1cc838d21bb4f05447603b2c1af89bfd67f 100644 --- a/ecmascript/module/js_module_manager.cpp +++ b/ecmascript/module/js_module_manager.cpp @@ -14,6 +14,7 @@ */ #include "ecmascript/module/js_module_manager.h" +#include "ecmascript/debugger/js_debugger_manager.h" #include "ecmascript/interpreter/frame_handler.h" #include "ecmascript/jspandafile/js_pandafile_executor.h" #include "ecmascript/module/js_shared_module_manager.h" @@ -193,8 +194,30 @@ bool ModuleManager::NeedExecuteModule(const CString &referencing) void ModuleManager::Iterate(RootVisitor &v) { + if (vm_->GetJsDebuggerManager() != nullptr && vm_->GetJsDebuggerManager()->IsDebugMode()) { + LOG_ECMA(INFO) << "Debugmode Enable"; + resolvedModules_.ForEach( + [&v](auto iter) { iter->second.VisitRoot([&v](ObjectSlot slot) { v.VisitRoot(Root::ROOT_VM, slot); }); }); + return; + } + JSThread *thread = vm_->GetJSThread(); + ModuleLogger *modulelogger = thread->GetModuleLogger(); + if (modulelogger != nullptr) { + LOG_ECMA(INFO) << "ModuleLogger Enable"; + resolvedModules_.ForEach( + [&v](auto iter) { iter->second.VisitRoot([&v](ObjectSlot slot) { v.VisitRoot(Root::ROOT_VM, slot); }); }); + return; + } + JSTaggedValue undefinedValue = thread->GlobalConstants()->GetUndefined(); resolvedModules_.ForEach( - [&v](auto iter) { iter->second.VisitRoot([&v](ObjectSlot slot) { v.VisitRoot(Root::ROOT_VM, slot); }); }); + [&v, thread, undefinedValue](auto iter) { + iter->second.VisitRoot([&v, thread, undefinedValue](ObjectSlot slot) { v.VisitRoot(Root::ROOT_VM, slot); }); + SourceTextModule *module = SourceTextModule::Cast(iter->second.Read().GetTaggedObject()); + if (module->GetStatus() >= ModuleStatus::EVALUATED) { + module->SetImportEntries(thread, undefinedValue); + } + } + ); } CString ModuleManager::GetRecordName(const JSThread *thread, JSTaggedValue module) diff --git a/ecmascript/patch/quick_fix_manager.cpp b/ecmascript/patch/quick_fix_manager.cpp index 6049db4529291981f3325db7c08c6fac671a7719..049bb68ff99c7cda0e2ba114742a8e6966c76475 100644 --- a/ecmascript/patch/quick_fix_manager.cpp +++ b/ecmascript/patch/quick_fix_manager.cpp @@ -43,9 +43,9 @@ void QuickFixManager::LoadPatchIfNeeded(JSThread *thread, const JSPandaFile *bas std::string patchFileName; uint8_t *patchBuffer = nullptr; size_t patchSize = 0; - CString baseFileName = baseFile->GetJSPandaFileDesc(); + const CString &baseFileName = baseFile->GetJSPandaFileDesc(); if (checkedFiles_.find(baseFileName) != checkedFiles_.end()) { - LOG_ECMA(DEBUG) << "Do not need check " << baseFileName << " has patch again"; + LOG_ECMA(DEBUG) << "Skipping patch check for" << baseFileName << ", already checked"; return; } checkedFiles_.insert(baseFileName); @@ -74,7 +74,7 @@ void QuickFixManager::LoadPatchIfNeeded(JSThread *thread, const JSPandaFile *bas return; } thread->GetEcmaVM()->SetStageOfColdReload(StageOfColdReload::IS_COLD_RELOAD); - methodInfos_.emplace(baseFileName, patchInfo); + methodInfos_.emplace(baseFileName, std::move(patchInfo)); } PatchErrorCode QuickFixManager::LoadPatch(JSThread *thread, const std::string &patchFileName, @@ -197,7 +197,7 @@ JSTaggedValue QuickFixManager::CheckAndGetPatch(JSThread *thread, const JSPandaF return JSTaggedValue::Hole(); } - PatchInfo patchInfo = iter->second; + PatchInfo &patchInfo = iter->second; MethodLiteral *patchMethodLiteral = PatchLoader::FindSameMethod(patchInfo, baseFile, baseMethodId, baseClassInfo_); if (patchMethodLiteral == nullptr) { return JSTaggedValue::Hole(); @@ -208,13 +208,12 @@ JSTaggedValue QuickFixManager::CheckAndGetPatch(JSThread *thread, const JSPandaF } // Generate patch constpool. - CString patchFileName = patchInfo.patchFileName; + const CString &patchFileName = patchInfo.patchFileName; std::shared_ptr patchFile = JSPandaFileManager::GetInstance()->FindJSPandaFile(patchFileName); ASSERT(patchFile != nullptr); EcmaVM *vm = thread->GetEcmaVM(); - JSHandle method; - method = vm->GetFactory()->NewSMethod(patchMethodLiteral); + JSHandle method = vm->GetFactory()->NewSMethod(patchMethodLiteral); JSHandle newConstpool = vm->FindOrCreateConstPool( patchFile.get(), patchMethodLiteral->GetMethodId()); method->SetConstantPool(thread, newConstpool);