From 35e1e980080437177009b647897dd5c34a673ddc Mon Sep 17 00:00:00 2001 From: Roland Takacs <1487864+rtakacs@users.noreply.github.com> Date: Thu, 9 Jul 2020 10:23:43 +0200 Subject: [PATCH] Fix Object.assign to call [[GetOwnProperty]] Proxy handler only once (#3988) Removed the enumerable option when listing properties to prevent an extra [[GetOwnProperty]] function call for Proxy objects. In this case all the property names are collected, but the Object.assign() implementation has already taken care of the enumerable property filtering. JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs@inf.u-szeged.hu --- .../ecma/builtin-objects/ecma-builtin-object.c | 1 - .../es.next/proxy_get_own_property_descriptor.js | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-object.c b/jerry-core/ecma/builtin-objects/ecma-builtin-object.c index 6035255c3..3c3dd2565 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-object.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-object.c @@ -1053,7 +1053,6 @@ ecma_builtin_object_object_assign (ecma_object_t *target_p, /**< target object * /* 5.b.iii */ ecma_collection_t *props_p = ecma_op_object_get_property_names (from_obj_p, ECMA_LIST_CONVERT_FAST_ARRAYS - | ECMA_LIST_ENUMERABLE | ECMA_LIST_SYMBOLS); #if ENABLED (JERRY_BUILTIN_PROXY) if (props_p == NULL) diff --git a/tests/jerry/es.next/proxy_get_own_property_descriptor.js b/tests/jerry/es.next/proxy_get_own_property_descriptor.js index 432187281..aa8f2919f 100644 --- a/tests/jerry/es.next/proxy_get_own_property_descriptor.js +++ b/tests/jerry/es.next/proxy_get_own_property_descriptor.js @@ -268,3 +268,17 @@ try { } // Step 17: See (Inv-2) above. + +var result = []; +var proxy = new Proxy({foo: 1, bar: 2}, { + getOwnPropertyDescriptor: function(o, v) { + result.push(v); + return Object.getOwnPropertyDescriptor(o, v); + } +}); + +Object.assign({}, proxy); + +assert(result.length === 2); +assert(result[0] === "foo"); +assert(result[1] === "bar");