From 5ad002d076ca7e8127186e528fde09f3ee2e8dc0 Mon Sep 17 00:00:00 2001 From: Robert Fancsik Date: Mon, 11 May 2020 12:32:58 +0200 Subject: [PATCH] Fix apply receiver operation for Proxy objects JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu --- jerry-core/ecma/operations/ecma-objects.c | 10 +++++++ .../jerry/es2015/proxy_set_apply_receiver.js | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/jerry/es2015/proxy_set_apply_receiver.js diff --git a/jerry-core/ecma/operations/ecma-objects.c b/jerry-core/ecma/operations/ecma-objects.c index 3cf7181aea..6497648718 100644 --- a/jerry-core/ecma/operations/ecma-objects.c +++ b/jerry-core/ecma/operations/ecma-objects.c @@ -1194,6 +1194,16 @@ ecma_op_object_put_apply_receiver (ecma_value_t receiver, /**< receiver */ return result; } +#if ENABLED (JERRY_ES2015_BUILTIN_PROXY) + if (ECMA_OBJECT_IS_PROXY (receiver_obj_p)) + { + ecma_property_descriptor_t desc; + desc.flags = ECMA_NAME_DATA_PROPERTY_DESCRIPTOR_BITS; + desc.value = value; + return ecma_proxy_object_define_own_property (receiver_obj_p, property_name_p, &desc); + } +#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */ + if (JERRY_UNLIKELY (ecma_op_object_is_fast_array (receiver_obj_p))) { ecma_fast_array_convert_to_normal (receiver_obj_p); diff --git a/tests/jerry/es2015/proxy_set_apply_receiver.js b/tests/jerry/es2015/proxy_set_apply_receiver.js new file mode 100644 index 0000000000..25d7da1338 --- /dev/null +++ b/tests/jerry/es2015/proxy_set_apply_receiver.js @@ -0,0 +1,30 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var get = []; +var p = new Proxy({ + exec: function() { + return null; + } +}, { + get: function(o, k) { + get.push(k); + return o[k]; + } +}); +RegExp.prototype[Symbol.match].call(p); +p.global = true; +RegExp.prototype[Symbol.match].call(p); + +assert(get + '' === "global,exec,global,unicode,exec");