From 77c5601ddf6bb09c06c774aac1d51e90a55ea19b Mon Sep 17 00:00:00 2001 From: yang-19970325 Date: Mon, 19 Dec 2022 10:18:26 +0800 Subject: [PATCH] add import variables to module scope Issue:#I66MU9 Signed-off-by: yang-19970325 Change-Id: I51688fe313fd870ca9c1e859091b9fd9defdf350 --- tooling/agent/debugger_impl.cpp | 6 ++++-- tooling/backend/debugger_executor.cpp | 18 ++++++++++++++++-- .../test/testcases/js_module_variable_test.h | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index e61c2816..cd1108f6 100644 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -957,7 +957,7 @@ bool DebuggerImpl::GenerateCallFrame(CallFrame *callFrame, std::vector> scopeChain; scopeChain.emplace_back(GetLocalScopeChain(frameHandler, &thisObj)); - if (jsPandaFile != nullptr && !jsPandaFile->IsBundlePack()) { + if (jsPandaFile != nullptr && !jsPandaFile->IsBundlePack() && jsPandaFile->IsNewVersion()) { scopeChain.emplace_back(GetModuleScopeChain()); } scopeChain.emplace_back(GetGlobalScopeChain()); @@ -1037,7 +1037,9 @@ 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 = JSHandle(thread, DebuggerApi::GetCurrentModule(vm_)); + DebuggerApi::GetExportVariables(vm_, moduleObj, currentModule.GetTaggedValue()); + DebuggerApi::GetImportVariables(vm_, moduleObj, currentModule.GetTaggedValue()); return moduleScope; } diff --git a/tooling/backend/debugger_executor.cpp b/tooling/backend/debugger_executor.cpp index b1ae45a2..d753f99d 100644 --- a/tooling/backend/debugger_executor.cpp +++ b/tooling/backend/debugger_executor.cpp @@ -205,7 +205,14 @@ Local DebuggerExecutor::GetModuleValue(const EcmaVM *vm, const Frame { Local result; std::string varName = name->ToString(); - result = DebuggerApi::GetModuleValue(vm, frameHandler, varName); + Method *method = DebuggerApi::GetMethod(frameHandler); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + if (jsPandaFile != nullptr && (jsPandaFile->IsBundlePack() || !jsPandaFile->IsNewVersion())) { + return result; + } + + JSTaggedValue currentModule = DebuggerApi::GetCurrentModule(vm); + result = DebuggerApi::GetModuleValue(vm, currentModule, varName); return result; } @@ -213,7 +220,14 @@ bool DebuggerExecutor::SetModuleValue(const EcmaVM *vm, const FrameHandler *fram Local name, Local value) { std::string varName = name->ToString(); - DebuggerApi::SetModuleValue(vm, frameHandler, varName, value); + Method *method = DebuggerApi::GetMethod(frameHandler); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + if (jsPandaFile != nullptr && (jsPandaFile->IsBundlePack() || !jsPandaFile->IsNewVersion())) { + return false; + } + + JSTaggedValue currentModule = DebuggerApi::GetCurrentModule(vm); + DebuggerApi::SetModuleValue(vm, currentModule, varName, value); return true; } } // namespace panda::ecmascript::tooling diff --git a/tooling/test/testcases/js_module_variable_test.h b/tooling/test/testcases/js_module_variable_test.h index 45be2259..7243cbe2 100644 --- a/tooling/test/testcases/js_module_variable_test.h +++ b/tooling/test/testcases/js_module_variable_test.h @@ -111,7 +111,7 @@ private: auto frame = paused->GetCallFrames()->at(0).get(); ASSERT_EQ(frame->GetFunctionName(), "foo"); auto scopes = frame->GetScopeChain(); - ASSERT_EQ(scopes->size(), 3U); // 2: contain local and global + ASSERT_EQ(scopes->size(), 3U); // 3: contain local module and global for (uint32_t i = 0; i < scopes->size(); i++) { auto scope = scopes->at(i).get(); if (scope->GetType() != Scope::Type::Module()) { -- Gitee