From cac576aa6a5bc9a7b277537230b727fcb5772321 Mon Sep 17 00:00:00 2001 From: yanzhiqi1 Date: Thu, 21 Aug 2025 17:04:57 +0800 Subject: [PATCH] fix bug in global value Issue: #ICU35K Signed-off-by: yanzhiqi1 Change-Id: I50a64cf04b3c0479feca5bc0597aa91337dcc813 --- ecmascript/debugger/debugger_api.cpp | 13 ++++++++----- ecmascript/debugger/debugger_api.h | 6 ++++-- ecmascript/debugger/js_debugger.h | 2 +- ecmascript/debugger/js_debugger_interface.h | 2 +- ecmascript/debugger/notification_manager.h | 4 ++-- ecmascript/dfx/tracing/tracing.cpp | 2 +- ecmascript/dfx/tracing/tracing.h | 2 +- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ecmascript/debugger/debugger_api.cpp b/ecmascript/debugger/debugger_api.cpp index 01962646c4..61b4ce858a 100644 --- a/ecmascript/debugger/debugger_api.cpp +++ b/ecmascript/debugger/debugger_api.cpp @@ -417,10 +417,12 @@ std::pair DebuggerApi::GetLevelSlot(const JSThread *thread, c return std::make_pair(-1, 0); } -Local DebuggerApi::GetGlobalValue(const EcmaVM *ecmaVm, Local name) +Local DebuggerApi::GetGlobalValue(const EcmaVM *ecmaVm, const FrameHandler *frameHandler, + Local name) { JSTaggedValue result; - JSTaggedValue globalObj = ecmaVm->GetGlobalEnv()->GetGlobalObject(); + Local globalEnv = GetCurrentGlobalEnv(ecmaVm, frameHandler); + JSHandle globalObj = JSNApiHelper::ToJSHandle(JSNApi::GetGlobalObject(ecmaVm, globalEnv)); JSThread *thread = ecmaVm->GetJSThread(); JSTaggedValue key = JSNApiHelper::ToJSTaggedValue(*name); @@ -431,18 +433,19 @@ Local DebuggerApi::GetGlobalValue(const EcmaVM *ecmaVm, Local(JSHandle(thread, result)); } - JSTaggedValue globalVar = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, key); + JSTaggedValue globalVar = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj.GetTaggedValue(), key); if (!globalVar.IsHole()) { return JSNApiHelper::ToLocal(JSHandle(thread, globalVar)); } else { - result = SlowRuntimeStub::TryLdGlobalByNameFromGlobalProto(thread, globalObj, key); + result = SlowRuntimeStub::TryLdGlobalByNameFromGlobalProto(thread, globalObj.GetTaggedValue(), key); return JSNApiHelper::ToLocal(JSHandle(thread, result)); } return Local(); } -bool DebuggerApi::SetGlobalValue(const EcmaVM *ecmaVm, Local name, Local value) +bool DebuggerApi::SetGlobalValue(const EcmaVM *ecmaVm, const FrameHandler *frameHandler, + Local name, Local value) { JSTaggedValue result; JSTaggedValue globalObj = ecmaVm->GetGlobalEnv()->GetGlobalObject(); diff --git a/ecmascript/debugger/debugger_api.h b/ecmascript/debugger/debugger_api.h index 2996f201e6..2f8dc38825 100644 --- a/ecmascript/debugger/debugger_api.h +++ b/ecmascript/debugger/debugger_api.h @@ -102,8 +102,10 @@ public: uint32_t slot, Local value); static std::pair GetLevelSlot(const JSThread *ecmaVm, const FrameHandler *frameHandler, std::string_view name); - static Local GetGlobalValue(const EcmaVM *ecmaVm, Local name); - static bool SetGlobalValue(const EcmaVM *ecmaVm, Local name, Local value); + static Local GetGlobalValue(const EcmaVM *ecmaVm, const FrameHandler *frameHandler, + Local name); + static bool SetGlobalValue(const EcmaVM *ecmaVm, const FrameHandler *frameHandler, + Local name, Local value); static Local GetCurrentGlobalEnv(const EcmaVM *ecmaVm, const FrameHandler *frameHandler = nullptr); // JSThread diff --git a/ecmascript/debugger/js_debugger.h b/ecmascript/debugger/js_debugger.h index 508fc36043..e8d9e2c3d2 100644 --- a/ecmascript/debugger/js_debugger.h +++ b/ecmascript/debugger/js_debugger.h @@ -199,7 +199,7 @@ public: } } - void SetDebuggerAccessor(JSHandle &globalEnv) override + void SetDebuggerAccessor(const JSHandle &globalEnv) override { if (hooks_ == nullptr) { return; diff --git a/ecmascript/debugger/js_debugger_interface.h b/ecmascript/debugger/js_debugger_interface.h index ddcc83e704..0e137d3223 100644 --- a/ecmascript/debugger/js_debugger_interface.h +++ b/ecmascript/debugger/js_debugger_interface.h @@ -104,7 +104,7 @@ public: virtual void GenerateAsyncFrames(std::shared_ptr asyncStack, bool skipTopFrame) = 0; - virtual void SetDebuggerAccessor(JSHandle &globalEnv) = 0; + virtual void SetDebuggerAccessor(const JSHandle &globalEnv) = 0; /** * \brief called by the ecmavm when symbolic breakpoint hits. Thread where symbolic breakpoint hits is stopped until diff --git a/ecmascript/debugger/notification_manager.h b/ecmascript/debugger/notification_manager.h index fe80966987..5cae456b64 100644 --- a/ecmascript/debugger/notification_manager.h +++ b/ecmascript/debugger/notification_manager.h @@ -44,7 +44,7 @@ public: virtual void MethodEntry(JSHandle method, JSHandle envHandle) = 0; virtual void MethodExit(JSHandle method) = 0; virtual void GenerateAsyncFrames(std::shared_ptr asyncStack, bool skipTopFrame) = 0; - virtual void SetDebuggerAccessor(JSHandle &globalEnv) = 0; + virtual void SetDebuggerAccessor(const JSHandle &globalEnv) = 0; }; class NotificationManager { @@ -144,7 +144,7 @@ public: } } - void SetDebuggerAccessorEvent(JSHandle &globalEnv) const + void SetDebuggerAccessorEvent(const JSHandle &globalEnv) const { for (auto it: listeners_) { it->SetDebuggerAccessor(globalEnv); diff --git a/ecmascript/dfx/tracing/tracing.cpp b/ecmascript/dfx/tracing/tracing.cpp index 99ac031e78..3d4a4ffbfc 100755 --- a/ecmascript/dfx/tracing/tracing.cpp +++ b/ecmascript/dfx/tracing/tracing.cpp @@ -315,7 +315,7 @@ void Tracing::MethodExit([[maybe_unused]] JSHandle method) return; } -void Tracing::SetDebuggerAccessor([[maybe_unused]] JSHandle &globalEnv) +void Tracing::SetDebuggerAccessor([[maybe_unused]] const JSHandle &globalEnv) { return; } diff --git a/ecmascript/dfx/tracing/tracing.h b/ecmascript/dfx/tracing/tracing.h index 01b3f59bc8..3e501c8dd2 100755 --- a/ecmascript/dfx/tracing/tracing.h +++ b/ecmascript/dfx/tracing/tracing.h @@ -117,7 +117,7 @@ public: void MethodEntry(JSHandle method, JSHandle envHandle) override; void MethodExit(JSHandle method) override; void GenerateAsyncFrames(std::shared_ptr asyncStack, bool skipTopFrame) override; - void SetDebuggerAccessor(JSHandle &globalEnv) override; + void SetDebuggerAccessor(const JSHandle &globalEnv) override; bool IsTracing() { -- Gitee