From d41bd036e278b3bd29571015774373b46400a793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=BA=91=E9=A3=9E?= Date: Mon, 18 Aug 2025 14:57:30 +0800 Subject: [PATCH] [Bug]: cherry pick !12834 to 5.0.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICTG0P?from=project-issue Signed-off-by: 杨云飞 --- ecmascript/js_object.cpp | 11 +++++++++++ test/moduletest/arrayfrom/arrayfrom.js | 15 +++++++++++++++ test/moduletest/arrayfrom/expect_output.txt | 1 + 3 files changed, 27 insertions(+) diff --git a/ecmascript/js_object.cpp b/ecmascript/js_object.cpp index e6609c36f6..b794a60770 100644 --- a/ecmascript/js_object.cpp +++ b/ecmascript/js_object.cpp @@ -24,6 +24,7 @@ #include "ecmascript/pgo_profiler/pgo_profiler.h" #include "ecmascript/property_accessor.h" #include "ecmascript/jspandafile/js_pandafile_manager.h" +#include "ecmascript/js_proxy.h" namespace panda::ecmascript { using PGOProfiler = pgo::PGOProfiler; @@ -1705,6 +1706,10 @@ bool JSObject::CreateDataProperty(JSThread *thread, const JSHandle &ob if (!JSHandle::Cast(obj)->IsJSShared()) { sCheckMode = SCheckMode::CHECK; } + if (UNLIKELY(obj->IsJSProxy())) { + PropertyDescriptor desc(thread, value, true, true, true); + return JSProxy::DefineOwnProperty(thread, JSHandle(obj), key, desc); + } auto result = ObjectFastOperator::SetPropertyByValue( thread, obj.GetTaggedValue(), key.GetTaggedValue(), value.GetTaggedValue(), sCheckMode); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -1719,6 +1724,12 @@ bool JSObject::CreateDataProperty(JSThread *thread, const JSHandle &ob const JSHandle &value, SCheckMode sCheckMode) { ASSERT_PRINT(obj->IsECMAObject(), "Obj is not a valid object"); + if (UNLIKELY(obj->IsJSProxy())) { + JSTaggedValue key(index); + JSHandle keyHandle(thread, key); + PropertyDescriptor desc(thread, value, true, true, true); + return JSProxy::DefineOwnProperty(thread, JSHandle(obj), keyHandle, desc); + } auto result = ObjectFastOperator::SetPropertyByIndex (thread, obj.GetTaggedValue(), index, value.GetTaggedValue()); if (!result.IsHole()) { diff --git a/test/moduletest/arrayfrom/arrayfrom.js b/test/moduletest/arrayfrom/arrayfrom.js index c78542203c..d8d3633e31 100644 --- a/test/moduletest/arrayfrom/arrayfrom.js +++ b/test/moduletest/arrayfrom/arrayfrom.js @@ -203,3 +203,18 @@ print(Array.from(v1.keys())) print(JSON.stringify(res)); } +function test() { + var set = []; + var a = []; + var p = new Proxy(a, { + set: function (o, k, v) { + set.push(k); + o[k] = v; + return true; + } + }); + Array.from.call(function () { return p; }, { length: 2, 0: 1, 1: 2 }); + return set + "" === "length"; +} + +print(test()); diff --git a/test/moduletest/arrayfrom/expect_output.txt b/test/moduletest/arrayfrom/expect_output.txt index c35827a396..239d6cbca0 100644 --- a/test/moduletest/arrayfrom/expect_output.txt +++ b/test/moduletest/arrayfrom/expect_output.txt @@ -87,3 +87,4 @@ get length get length [0,1,2,null,null,null,null,null,null,null] [1,2,3] +true -- Gitee