diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index 88bf11293f96b8f2c0a252c0986dfbd6921d9be9..0779fe70993f2e66c4468c59dc237ec29c55dec3 100644 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -973,11 +973,12 @@ bool DebuggerImpl::GenerateCallFrame(CallFrame *callFrame, std::unique_ptr thisObj = std::make_unique(); thisObj->SetType(ObjectType::Undefined); + JSThread *thread = vm_->GetJSThread(); std::vector> scopeChain; scopeChain.emplace_back(GetLocalScopeChain(frameHandler, &thisObj)); if (jsPandaFile != nullptr && !jsPandaFile->IsBundlePack() && jsPandaFile->IsNewVersion()) { - JSTaggedValue currentModule = DebuggerApi::GetCurrentModule(vm_); - if (currentModule.IsSourceTextModule()) { + JSHandle currentModule(thread, DebuggerApi::GetCurrentModule(vm_)); + if (currentModule->IsSourceTextModule()) { // CJS module is string scopeChain.emplace_back(GetModuleScopeChain()); } } @@ -1056,7 +1057,10 @@ std::unique_ptr DebuggerImpl::GetModuleScopeChain() moduleScope->SetType(Scope::Type::Module()).SetObject(std::move(module)); runtime_->properties_[runtime_->curObjectId_++] = Global(vm_, moduleObj); JSThread *thread = vm_->GetJSThread(); - DebuggerApi::GetModuleVariables(vm_, moduleObj, thread); + JSHandle currentModule(thread, DebuggerApi::GetCurrentModule(vm_)); + DebuggerApi::GetLocalExportVariables(vm_, moduleObj, currentModule, false); + DebuggerApi::GetIndirectExportVariables(vm_, moduleObj, currentModule); + DebuggerApi::GetImportVariables(vm_, moduleObj, currentModule); return moduleScope; } diff --git a/tooling/backend/debugger_executor.cpp b/tooling/backend/debugger_executor.cpp index 02e85449bfdd19b7432037252b474c2e3126c7eb..d56afec093872a6cb714bf0bab17c6c1778bad4e 100644 --- a/tooling/backend/debugger_executor.cpp +++ b/tooling/backend/debugger_executor.cpp @@ -96,6 +96,10 @@ Local DebuggerExecutor::GetValue(const EcmaVM *vm, const FrameHandle if (!value.IsEmpty()) { return value; } + value = GetModuleValue(vm, frameHandler, name); + if (!value.IsEmpty()) { + return value; + } value = GetGlobalValue(vm, name); if (!value.IsEmpty()) { return value; @@ -113,6 +117,9 @@ bool DebuggerExecutor::SetValue(const EcmaVM *vm, FrameHandler *frameHandler, if (SetLexicalValue(vm, frameHandler, name, value)) { return true; } + if (SetModuleValue(vm, frameHandler, name, value)) { + return true; + } if (SetGlobalValue(vm, name, value)) { return true; } @@ -192,4 +199,35 @@ bool DebuggerExecutor::SetGlobalValue(const EcmaVM *vm, Local name, L { return DebuggerApi::SetGlobalValue(vm, name, value); } + +Local DebuggerExecutor::GetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler, + Local name) +{ + Local result; + std::string varName = name->ToString(); + Method *method = DebuggerApi::GetMethod(frameHandler); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + if (jsPandaFile != nullptr && (jsPandaFile->IsBundlePack() || !jsPandaFile->IsNewVersion())) { + return result; + } + JSThread *thread = vm->GetJSThread(); + JSHandle currentModule(thread, DebuggerApi::GetCurrentModule(vm)); + result = DebuggerApi::GetModuleValue(vm, currentModule, varName); + return result; +} + +bool DebuggerExecutor::SetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler, + Local name, Local value) +{ + std::string varName = name->ToString(); + Method *method = DebuggerApi::GetMethod(frameHandler); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + if (jsPandaFile != nullptr && (jsPandaFile->IsBundlePack() || !jsPandaFile->IsNewVersion())) { + return false; + } + JSThread *thread = vm->GetJSThread(); + JSHandle currentModule(thread, DebuggerApi::GetCurrentModule(vm)); + DebuggerApi::SetModuleValue(vm, currentModule, varName, value); + return true; +} } // namespace panda::ecmascript::tooling diff --git a/tooling/backend/debugger_executor.h b/tooling/backend/debugger_executor.h index 491cc3dedea75a8be6befac9110753e80ac295bd..b8acb51c16f551bb2354a8f146bcf2feaa147c51 100644 --- a/tooling/backend/debugger_executor.h +++ b/tooling/backend/debugger_executor.h @@ -44,12 +44,15 @@ private: static Local GetLocalValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local name); static Local GetLexicalValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local name); + static Local GetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local name); static Local GetGlobalValue(const EcmaVM *vm, Local name); static bool SetLocalValue(const EcmaVM *vm, FrameHandler *frameHandler, Local name, Local value); static bool SetLexicalValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local name, Local value); + static bool SetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler, + Local name, Local value); static bool SetGlobalValue(const EcmaVM *vm, Local name, Local value); constexpr static uint32_t NUM_ARGS = 2;