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/get | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Proxy/get')
21 files changed, 619 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/get/accessor-get-is-undefined-throws.js b/js/src/tests/test262/built-ins/Proxy/get/accessor-get-is-undefined-throws.js new file mode 100644 index 0000000000..422a7a60aa --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/accessor-get-is-undefined-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + if trap result is not undefined, then proxy must report the same value for a + non-configurable accessor property with an undefined get. +info: | + 13. If targetDesc is not undefined, then + b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] + is false and targetDesc.[[Get]] is undefined, then + i. If trapResult is not undefined, throw a TypeError exception. + +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + get: undefined +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p['attr']; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/browser.js b/js/src/tests/test262/built-ins/Proxy/get/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/browser.js diff --git a/js/src/tests/test262/built-ins/Proxy/get/call-parameters.js b/js/src/tests/test262/built-ins/Proxy/get/call-parameters.js new file mode 100644 index 0000000000..538815bd4b --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/call-parameters.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). +info: | + 6.1.7.2 Object Internal Methods and Internal Slots + + (...) Receiver is used as the this value when evaluating the code +features: [Proxy] +---*/ + +var _target, _handler, _prop, _receiver; +var target = { + attr: 1 +}; +var handler = { + get: function(t, prop, receiver) { + _handler = this; + _target = t; + _prop = prop; + _receiver = receiver; + } +}; +var p = new Proxy(target, handler); + +p.attr; + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_prop, "attr"); +assert.sameValue(_receiver, p, "receiver is the Proxy object"); + +_prop = null; +p["attr"]; +assert.sameValue( + _prop, "attr", + "trap is triggered both by p.attr and p['attr']" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js b/js/src/tests/test262/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js new file mode 100644 index 0000000000..790bf1997d --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + Throws if proxy return has not the same value for a non-writable, + non-configurable property +info: | + [[Get]] (P, Receiver) + + 13. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a + TypeError exception. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 1 +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p['attr']; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/null-handler.js b/js/src/tests/test262/built-ins/Proxy/get/null-handler.js new file mode 100644 index 0000000000..a5b4716301 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/null-handler.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 2. If handler is null, throw a TypeError exception. +features: [Proxy] +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + p.proxy.attr; +}); + +assert.throws(TypeError, function() { + p.proxy['attr']; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-is-abrupt.js b/js/src/tests/test262/built-ins/Proxy/get/return-is-abrupt.js new file mode 100644 index 0000000000..03bfe37967 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-is-abrupt.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + Trap returns abrupt. +info: | + [[Get]] (P, Receiver) + + 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). + 10. ReturnIfAbrupt(trapResult). +features: [Proxy] +---*/ + +var p = new Proxy({}, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + p.attr; +}); + +assert.throws(Test262Error, function() { + p["attr"]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-accessor-property.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-accessor-property.js new file mode 100644 index 0000000000..3c6b8c685e --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-accessor-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + get: function() { + return 1; + } +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js new file mode 100644 index 0000000000..fae30cd0ff --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: true, + value: 1 +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js new file mode 100644 index 0000000000..03598c2187 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: true, + get: undefined +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js new file mode 100644 index 0000000000..f24884412f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: true, + writable: false, + value: 1 +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js new file mode 100644 index 0000000000..852873df97 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + Proxy must report the same value for a non-writable, non-configurable + property. +info: | + [[Get]] (P, Receiver) + + 13. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a + TypeError exception. + ... + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 1; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 1 +}); + +assert.sameValue(p.attr, 1); +assert.sameValue(p['attr'], 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result.js new file mode 100644 index 0000000000..f953d77ebe --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p.foo, 2); + +assert.sameValue(p['attr'], 2); +assert.sameValue(p['foo'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/shell.js b/js/src/tests/test262/built-ins/Proxy/get/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/shell.js diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-missing-target-is-proxy.js new file mode 100644 index 0000000000..effefcacdb --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-missing-target-is-proxy.js @@ -0,0 +1,33 @@ +// 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-get-p-receiver +description: > + If "get" trap is null or undefined, [[Get]] call is properly + forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Get]] ( P, Receiver ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "get"). + 7. If trap is undefined, then + a. Return ? target.[[Get]](P, Receiver). +features: [Proxy, Symbol.match] +---*/ + +var regExp = /(?:)/i; +var regExpTarget = new Proxy(regExp, {}); +var regExpProxy = new Proxy(regExpTarget, {}); + +assert.sameValue(Object.create(regExpProxy).lastIndex, 0); +assert.sameValue(regExpProxy[Symbol.match], RegExp.prototype[Symbol.match]); + + +var functionTarget = new Proxy(function(_arg) {}, {}); +var functionProxy = new Proxy(functionTarget, {}); + +assert.sameValue(Object.create(functionProxy).length, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable-realm.js new file mode 100644 index 0000000000..a9e4cb115c --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable-realm.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. 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-get-p-receiver +description: > + Throws if trap is not callable (honoring the Realm of the current execution + context) +info: | + [[Get]] (P, Receiver) + + 6. Let trap be GetMethod(handler, "get"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var p = new OProxy({}, { + get: {} +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p["attr"]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable.js new file mode 100644 index 0000000000..f0b1d975e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + Trap is not callable. +info: | + [[Get]] (P, Receiver) + + 6. Let trap be GetMethod(handler, "get"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + get: {} +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p["attr"]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-null-target-is-proxy.js new file mode 100644 index 0000000000..6d9b09e759 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-null-target-is-proxy.js @@ -0,0 +1,50 @@ +// 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-get-p-receiver +description: > + If "get" trap is null or undefined, [[Get]] call is properly + forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Get]] ( P, Receiver ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "get"). + 7. If trap is undefined, then + a. Return ? target.[[Get]](P, Receiver). +features: [Proxy, Symbol] +---*/ + +var stringTarget = new Proxy(new String("str"), {}); +var stringProxy = new Proxy(stringTarget, { + get: null, +}); + +assert.sameValue(stringProxy.length, 3); +assert.sameValue(stringProxy[0], "s"); +assert.sameValue(stringProxy[4], undefined); + + +var sym = Symbol(); +var target = new Proxy({}, { + get: function(_target, key) { + switch (key) { + case sym: return 1; + case "10": return 2; + case "foo": return 3; + } + }, +}); + +var proxy = new Proxy(target, { + get: null, +}); + +assert.sameValue(proxy[sym], 1); +assert.sameValue(proxy[10], 2); +assert.sameValue(Object.create(proxy).foo, 3); +assert.sameValue(proxy.bar, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-no-property.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-no-property.js new file mode 100644 index 0000000000..6a5dd05f1a --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-no-property.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 8. If trap is undefined, then return target.[[Get]](P, Receiver). +features: [Proxy] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(p.attr, 1, 'return target.attr'); +assert.sameValue(p.foo, undefined, 'return target.foo'); +assert.sameValue(p['attr'], 1, 'return target.attr'); +assert.sameValue(p['foo'], undefined, 'return target.foo'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-receiver.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-receiver.js new file mode 100644 index 0000000000..b714484819 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-receiver.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 Aleksey 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-get-p-receiver +description: > + Pass to target's [[Get]] correct receiver if trap is missing +info: | + [[Get]] (P, Receiver) + + 7. If trap is undefined, then + a. Return ? target.[[Get]](P, Receiver). +features: [Proxy] +---*/ + +var target = { + get attr() { + return this; + } +}; + +var p = new Proxy(target, { + get: null +}); +assert.sameValue(p.attr, p); + +var pParent = Object.create(new Proxy(target, {})); +assert.sameValue(pParent.attr, pParent); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-target-is-proxy.js new file mode 100644 index 0000000000..a8e627d2e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-target-is-proxy.js @@ -0,0 +1,47 @@ +// 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-get-p-receiver +description: > + If "get" trap is null or undefined, [[Get]] call is properly + forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Get]] ( P, Receiver ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "get"). + 7. If trap is undefined, then + a. Return ? target.[[Get]](P, Receiver). +features: [Proxy] +includes: [compareArray.js] +---*/ + +var plainObject = { + get 0() { + return 1; + }, + foo: 2, + set bar(_value) {}, +}; + +var plainObjectTarget = new Proxy(plainObject, {}); +var plainObjectProxy = new Proxy(plainObjectTarget, { + get: undefined, +}); + +assert.sameValue(Object.create(plainObjectProxy)[0], 1); +assert.sameValue(plainObjectProxy.foo, 2); +assert.sameValue(plainObjectProxy.bar, undefined); + + +var array = [1, 2, 3]; +var arrayTarget = new Proxy(array, {}); +var arrayProxy = new Proxy(arrayTarget, { + get: undefined, +}); + +assert.compareArray(arrayProxy, array); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined.js new file mode 100644 index 0000000000..03bb20a99f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.8 +description: > + [[Get]] (P, Receiver) + + 8. If trap is undefined, then return target.[[Get]](P, Receiver). + +features: [Proxy] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: undefined +}); + +assert.sameValue(p.attr, 1, 'return target.attr'); +assert.sameValue(p.foo, undefined, 'return target.foo'); + +reportCompare(0, 0); |