diff --git a/ecmascript/js_object.cpp b/ecmascript/js_object.cpp index eff1d84cd1e535f2049f0daa63967f7184be173a..6703d3901b96c607bd37a99f29d669a361ada0fc 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; @@ -1796,6 +1797,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); @@ -1810,6 +1815,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 d5f08298686da1688493e9b21f100c43731fbf1c..e8cac97821573e21c6c87b5cf226d73f835e1642 100644 --- a/test/moduletest/arrayfrom/arrayfrom.js +++ b/test/moduletest/arrayfrom/arrayfrom.js @@ -378,4 +378,20 @@ print(Array.from(v1.keys())) let float64Array = new Float64Array([1, 2, 3, 4, 5, 6]); let res = Array.from(float64Array, mapFunc); print(JSON.stringify(res)); -} \ No newline at end of file +} + +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 45db17cdba485c4df8b456b1a16b4171ebe8765f..1201bec729fa84f5c06bc8371034b13e3af6a783 100644 --- a/test/moduletest/arrayfrom/expect_output.txt +++ b/test/moduletest/arrayfrom/expect_output.txt @@ -111,3 +111,4 @@ result check successfully [2,4,6,8,10,12] [2,4,6,8,10,12] [2,4,6,8,10,12] +true