diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/Proxy/set/trap-is-missing-receiver-multiple-calls-index.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Proxy/set/trap-is-missing-receiver-multiple-calls-index.js')
-rw-r--r-- | js/src/tests/test262/built-ins/Proxy/set/trap-is-missing-receiver-multiple-calls-index.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/set/trap-is-missing-receiver-multiple-calls-index.js b/js/src/tests/test262/built-ins/Proxy/set/trap-is-missing-receiver-multiple-calls-index.js new file mode 100644 index 0000000000..37a7cac0e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/set/trap-is-missing-receiver-multiple-calls-index.js @@ -0,0 +1,81 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver +description: > + If "set" trap is missing, the call is properly forwarded to ordinary + [[Set]] that invokes [[GetOwnProperty]] and [[DefineOwnProperty]] methods + on receiver (that is a Proxy itself) every time it is called. + (integer index property name) +info: | + [[Set]] ( P, V, Receiver ) + + [...] + 6. Let trap be ? GetMethod(handler, "set"). + 7. If trap is undefined, then + a. Return ? target.[[Set]](P, V, Receiver). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 3. If IsDataDescriptor(ownDesc) is true, then + [...] + c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). + d. If existingDescriptor is not undefined, then + [...] + iii. Let valueDesc be the PropertyDescriptor { [[Value]]: V }. + iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc). + e. Else, + i. Assert: Receiver does not currently have a property P. + ii. Return ? CreateDataProperty(Receiver, P, V). + [...] + + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 9. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P, descObj »)). + [...] + 17. Return true. +features: [Proxy, Reflect] +includes: [compareArray.js] +---*/ + +var getOwnPropertyKeys = []; +var definePropertyKeys = []; + +var p = new Proxy({ + "0": null, +}, { + getOwnPropertyDescriptor: function(target, key) { + getOwnPropertyKeys.push(key); + return Reflect.getOwnPropertyDescriptor(target, key); + }, + defineProperty: function(target, key, desc) { + definePropertyKeys.push(key); + return Reflect.defineProperty(target, key, desc); + }, +}); + +p[0] = true; +p[0] = true; +p["0"] = true; + +assert.compareArray(getOwnPropertyKeys, ["0", "0", "0"], + "getOwnPropertyDescriptor: key present on [[ProxyTarget]]"); +assert.compareArray(definePropertyKeys, ["0", "0", "0"], + "defineProperty: key present on [[ProxyTarget]]"); + +getOwnPropertyKeys = []; +definePropertyKeys = []; + +p[22] = false; +p["22"] = false; +p[22] = false; + +assert.compareArray(getOwnPropertyKeys, ["22", "22", "22"], + "getOwnPropertyDescriptor: key absent on [[ProxyTarget]]"); +assert.compareArray(definePropertyKeys, ["22", "22", "22"], + "defineProperty: key absent on [[ProxyTarget]]"); + +reportCompare(0, 0); |