diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/built-ins/Proxy/deleteProperty | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Proxy/deleteProperty')
19 files changed, 534 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.js new file mode 100644 index 0000000000..5addc7638b --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.js @@ -0,0 +1,34 @@ +// 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.10 +description: > + [[Delete]] (P) + + The result is a Boolean value. +features: [Proxy, Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + deleteProperty: function() { + return 0; + } +}); + +Object.defineProperties(target, { + isConfigurable: { + value: 1, + configurable: true + }, + notConfigurable: { + value: 1, + configurable: false + } +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), false); +assert.sameValue(Reflect.deleteProperty(p, "isConfigurable"), false); +assert.sameValue(Reflect.deleteProperty(p, "notConfigurable"), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js new file mode 100644 index 0000000000..85c873e173 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js @@ -0,0 +1,20 @@ +// 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.10 +description: > + [[Delete]] (P) + + The result is a Boolean value. +features: [Proxy, Reflect] +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return 1; + } +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/browser.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/browser.js diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/call-parameters.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/call-parameters.js new file mode 100644 index 0000000000..5f5c585a94 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/call-parameters.js @@ -0,0 +1,36 @@ +// 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.10 +description: > + [[Delete]] (P) + + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). +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 _handler, _target, _prop; +var target = { + attr: 1 +}; +var handler = { + deleteProperty: function(t, prop) { + _handler = this; + _target = t; + _prop = prop; + return delete t[prop]; + } +}; +var p = new Proxy(target, handler); + +delete p.attr; + +assert.sameValue(_handler, handler, "handler object as the trap context"); +assert.sameValue(_target, target, "first argument is the target object"); +assert.sameValue(_prop, "attr", "second argument is the property name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/null-handler.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/null-handler.js new file mode 100644 index 0000000000..012a8aec02 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/null-handler.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.10 +description: > + [[Delete]] (P) + + 3. If handler is null, throw a TypeError exception. +features: [Proxy] +---*/ + +var p = Proxy.revocable({ + attr: 1 +}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + delete p.proxy.attr; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/return-false-not-strict.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/return-false-not-strict.js new file mode 100644 index 0000000000..c6209578fc --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/return-false-not-strict.js @@ -0,0 +1,21 @@ +// 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.10 +description: > + [[Delete]] (P) + + 11. If booleanTrapResult is false, return false. +flags: [noStrict] +features: [Proxy] +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return false; + } +}); + +assert.sameValue(delete p.attr, false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/return-false-strict-strict.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/return-false-strict-strict.js new file mode 100644 index 0000000000..ae528d4416 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/return-false-strict-strict.js @@ -0,0 +1,22 @@ +'use strict'; +// 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.10 +description: > + [[Delete]] (P) + + 11. If booleanTrapResult is false, return false. +flags: [onlyStrict] +features: [Proxy, Reflect] +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return false; + } +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/return-is-abrupt.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/return-is-abrupt.js new file mode 100644 index 0000000000..e325aea4e8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/return-is-abrupt.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.10 +description: > + Trap return is an abrupt. +info: | + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). + 10. ReturnIfAbrupt(booleanTrapResult). +features: [Proxy] +---*/ + +var p = new Proxy({}, { + deleteProperty: function(t, prop) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + delete p.attr; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/shell.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/shell.js diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/targetdesc-is-configurable-target-is-not-extensible.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/targetdesc-is-configurable-target-is-not-extensible.js new file mode 100644 index 0000000000..4662f2ca04 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/targetdesc-is-configurable-target-is-not-extensible.js @@ -0,0 +1,35 @@ +// Copyright (C) 2019 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-delete-p +description: > + Throw a TypeError exception if trap result is true, targetDesc is configurable, + and target is not extensible. +info: | + [[Delete]] (P) + + ... + 13. Let extensibleTarget be ? IsExtensible(target). + 14. If extensibleTarget is false, throw a TypeError exception. + ... +features: [Proxy, Reflect, proxy-missing-checks] +---*/ + +var trapCalls = 0; +var p = new Proxy({prop: 1}, { + deleteProperty: function(t, prop) { + Object.preventExtensions(t); + trapCalls++; + return true; + }, +}); + +assert.throws(TypeError, function() { + Reflect.deleteProperty(p, "prop"); +}); +assert.sameValue(trapCalls, 1); + +assert(Reflect.deleteProperty(p, "nonExistent")); +assert.sameValue(trapCalls, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/targetdesc-is-not-configurable.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/targetdesc-is-not-configurable.js new file mode 100644 index 0000000000..9b6f079ad5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/targetdesc-is-not-configurable.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.10 +description: > + [[Delete]] (P) + + A property cannot be reported as deleted, if it exists as a non-configurable + own property of the target object. +info: | + 14. If targetDesc.[[Configurable]] is false, throw a TypeError exception. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + deleteProperty: function() { + return true; + } +}); + +Object.defineProperty(target, "attr", { + configurable: false, + value: 1 +}); + +assert.throws(TypeError, function() { + delete p.attr; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js new file mode 100644 index 0000000000..62b5ca1872 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js @@ -0,0 +1,20 @@ +// 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.10 +description: > + [[Delete]] (P) + + 14. If targetDesc is undefined, return true. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return true; + } +}); + +assert.sameValue(delete p.attr, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-missing-target-is-proxy.js new file mode 100644 index 0000000000..8516740202 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-missing-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-delete-p +description: > + If "deleteProperty" trap is null or undefined, [[Delete]] call is + properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Delete]] ( P ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "deleteProperty"). + 7. If trap is undefined, then + a. Return ? target.[[Delete]](P). +features: [Proxy, Reflect] +---*/ + +var plainObject = { + get foo() {}, +}; + +Object.defineProperty(plainObject, "bar", { + configurable: false, +}); + +var plainObjectTarget = new Proxy(plainObject, {}); +var plainObjectProxy = new Proxy(plainObjectTarget, {}); + +assert(delete plainObjectProxy.foo); +assert(!plainObject.hasOwnProperty("foo")); + +assert(!Reflect.deleteProperty(plainObjectProxy, "bar")); +assert(plainObject.hasOwnProperty("bar")); + + +var func = function() {}; +var funcTarget = new Proxy(func, {}); +var funcProxy = new Proxy(funcTarget, {}); + +assert(delete funcProxy.length); +assert(!func.hasOwnProperty("length")); + +assert.throws(TypeError, function() { + "use strict"; + delete funcProxy.prototype; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-not-callable-realm.js new file mode 100644 index 0000000000..ac5a7a11c1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-not-callable-realm.js @@ -0,0 +1,29 @@ +// 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-delete-p +description: > + Throws when trap is not callable. (honoring the Realm of the current + execution context) +info: | + 9.5.10 [[Delete]] (P) + + 6. Let trap be GetMethod(handler, "deleteProperty"). + ... + + 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({}, { + deleteProperty: {} +}); + +assert.throws(TypeError, function() { + delete p.attr; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-not-callable.js new file mode 100644 index 0000000000..c6994fc13b --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-not-callable.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.10 +description: > + Throws when trap is not callable. +info: | + 9.5.10 [[Delete]] (P) + + 6. Let trap be GetMethod(handler, "deleteProperty"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + deleteProperty: {} +}); + +assert.throws(TypeError, function() { + delete p.attr; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-null-target-is-proxy.js new file mode 100644 index 0000000000..3ba8d7b741 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-null-target-is-proxy.js @@ -0,0 +1,43 @@ +// 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-delete-p +description: > + If "deleteProperty" trap is null or undefined, [[Delete]] call is + properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Delete]] ( P ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "deleteProperty"). + 7. If trap is undefined, then + a. Return ? target.[[Delete]](P). +features: [Proxy, Reflect] +---*/ + +var stringTarget = new Proxy(new String("str"), {}); +var stringProxy = new Proxy(stringTarget, { + deleteProperty: null, +}); + +assert(!Reflect.deleteProperty(stringProxy, "length")); +assert.throws(TypeError, function() { + "use strict"; + delete stringProxy[0]; +}); + + +var regExpTarget = new Proxy(/(?:)/g, {}); +var regExpProxy = new Proxy(regExpTarget, { + deleteProperty: null, +}); + +assert(delete regExpProxy.foo); +assert.throws(TypeError, function() { + "use strict"; + delete regExpProxy.lastIndex; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.js new file mode 100644 index 0000000000..f31c9a0e35 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.js @@ -0,0 +1,33 @@ +// 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.10 +description: > + [[Delete]] (P) + + 8. If trap is undefined, then Return target.[[Delete]](P). +flags: [noStrict] +features: [Proxy] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(delete p.attr, true); +assert.sameValue(delete p.notThere, true); +assert.sameValue( + Object.getOwnPropertyDescriptor(target, "attr"), + undefined +); + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: 1 +}); + +assert.sameValue(delete p.attr, false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-undefined-strict-strict.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-undefined-strict-strict.js new file mode 100644 index 0000000000..39195e7b89 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-undefined-strict-strict.js @@ -0,0 +1,34 @@ +'use strict'; +// 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.10 +description: > + [[Delete]] (P) + + 8. If trap is undefined, then Return target.[[Delete]](P). +flags: [onlyStrict] +features: [Proxy, Reflect] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(delete p.attr, true); +assert.sameValue(delete p.notThere, true); +assert.sameValue( + Object.getOwnPropertyDescriptor(target, "attr"), + undefined +); + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: 1 +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-undefined-target-is-proxy.js new file mode 100644 index 0000000000..2195deca63 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/deleteProperty/trap-is-undefined-target-is-proxy.js @@ -0,0 +1,54 @@ +// 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-delete-p +description: > + If "deleteProperty" trap is null or undefined, [[Delete]] call is + properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Delete]] ( P ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "deleteProperty"). + 7. If trap is undefined, then + a. Return ? target.[[Delete]](P). +features: [Proxy, Reflect] +---*/ + +var array = [1]; +var arrayTarget = new Proxy(array, {}); +var arrayProxy = new Proxy(arrayTarget, { + deleteProperty: undefined, +}); + +assert(delete arrayProxy[0]); +assert(!array.hasOwnProperty("0")); + +assert(!Reflect.deleteProperty(arrayProxy, "length")); +assert.sameValue(array.length, 1); + + +var trapCalls = 0; +var target = new Proxy({}, { + deleteProperty: function(_target, key) { + trapCalls++; + return key === "foo"; + }, +}); + +var proxy = new Proxy(target, { + deleteProperty: undefined, +}); + +assert(delete proxy.foo); +assert.sameValue(trapCalls, 1); + +assert.throws(TypeError, function() { + "use strict"; + delete proxy.bar; +}); +assert.sameValue(trapCalls, 2); + +reportCompare(0, 0); |