diff --git a/ecmascript/js_object.cpp b/ecmascript/js_object.cpp index 471e8538c0ea7f5c4bc200a2d754fc26f702114b..dd0bfc6fc0365ad96d606cd1e92a2a054b289b78 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 c78542203c029be11311a8a748559da71e25f140..f0fd19f0ac261afc025e269a1c6a3892667ccd10 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()); \ No newline at end of file diff --git a/test/moduletest/arrayfrom/expect_output.txt b/test/moduletest/arrayfrom/expect_output.txt index c35827a3961af81b952b6c1ae6f99f28b33930e4..239d6cbca0c02125a9b40e6d627858e03df28fac 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