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/preventExtensions | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.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/preventExtensions')
14 files changed, 329 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/browser.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/browser.js diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/call-parameters.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/call-parameters.js new file mode 100644 index 0000000000..77dd0b70b9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/call-parameters.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.4 +description: > + Trap is called with handler on its context and target as the first + parameter. +info: | + [[PreventExtensions]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + ... +features: [Proxy] +---*/ + +var _target, _handler; +var target = {}; +var handler = { + preventExtensions: function(t) { + _handler = this; + _target = t; + + return Object.preventExtensions(target); + } +}; +var p = new Proxy(target, handler); + +Object.preventExtensions(p); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/null-handler.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/null-handler.js new file mode 100644 index 0000000000..695808bb19 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/null-handler.js @@ -0,0 +1,18 @@ +// 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.4 +description: > + Throws a TypeError exception if handler is null. +features: [Proxy] +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.preventExtensions(p.proxy); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-false.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-false.js new file mode 100644 index 0000000000..a15f57b7fe --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-false.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.4 +description: > + If boolean trap result if false, return false. +features: [Proxy, Reflect] +---*/ + +var target = {}; +var p = new Proxy({}, { + preventExtensions: function(t) { + return 0; + } +}); + +assert.sameValue(Reflect.preventExtensions(p), false); + +Object.preventExtensions(target); + +assert.sameValue(Reflect.preventExtensions(p), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-is-abrupt.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-is-abrupt.js new file mode 100644 index 0000000000..a120c3685c --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-is-abrupt.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.4 +description: > + Trap returns abrupt. +info: | + [[PreventExtensions]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + 9. ReturnIfAbrupt(booleanTrapResult). + ... +features: [Proxy] +---*/ + +var p = new Proxy({}, { + preventExtensions: function(t) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.preventExtensions(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.js new file mode 100644 index 0000000000..3e0614d18a --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.js @@ -0,0 +1,30 @@ +// 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.4 +description: > + Throws a TypeError exception if boolean trap result is true and target is + extensible. +info: | + [[PreventExtensions]] ( ) + + ... + 10. If booleanTrapResult is true, then + ... + c. If targetIsExtensible is true, throw a TypeError exception. + 11. Return booleanTrapResult. + ... +features: [Proxy] +---*/ + +var p = new Proxy({}, { + preventExtensions: function(t) { + return true; + } +}); + +assert.throws(TypeError, function() { + Object.preventExtensions(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.js new file mode 100644 index 0000000000..35966b8acc --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.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.4 +description: > + Return boolean trap result if its true and target is not extensible. +features: [Proxy, Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + preventExtensions: function(t) { + return 1; + } +}); + +Object.preventExtensions(target); + +assert(Reflect.preventExtensions(p)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/shell.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/shell.js diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-missing-target-is-proxy.js new file mode 100644 index 0000000000..908029e0a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-missing-target-is-proxy.js @@ -0,0 +1,32 @@ +// 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-preventextensions +description: > + If "preventExtensions" trap is null or undefined, [[PreventExtensions]] call + is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[PreventExtensions]] ( ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Let trap be ? GetMethod(handler, "preventExtensions"). + 6. If trap is undefined, then + a. Return ? target.[[PreventExtensions]](). +features: [Proxy] +---*/ + +var target = new Proxy({}, { + preventExtensions: function(_target) { + return false; + }, +}); + +var proxy = new Proxy(target, {}); + +assert.throws(TypeError, function() { + Object.preventExtensions(proxy); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-not-callable-realm.js new file mode 100644 index 0000000000..f08292862d --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/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-preventextensions +description: > + Throws if trap is not callable (honoring the Realm of the current execution + context) +info: | + [[PreventExtensions]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let trap be GetMethod(handler, "preventExtensions"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(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({}, { + preventExtensions: {} +}); + +assert.throws(TypeError, function() { + Object.preventExtensions(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-not-callable.js new file mode 100644 index 0000000000..e6d23e969b --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-not-callable.js @@ -0,0 +1,32 @@ +// 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.4 +description: > + Throws a TypeError exception if trap is not callable. +info: | + [[PreventExtensions]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let trap be GetMethod(handler, "preventExtensions"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + preventExtensions: {} +}); + +assert.throws(TypeError, function() { + Object.preventExtensions(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-null-target-is-proxy.js new file mode 100644 index 0000000000..c35cf085b1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-null-target-is-proxy.js @@ -0,0 +1,29 @@ +// 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-preventextensions +description: > + If "preventExtensions" trap is null or undefined, [[PreventExtensions]] call + is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[PreventExtensions]] ( ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Let trap be ? GetMethod(handler, "preventExtensions"). + 6. If trap is undefined, then + a. Return ? target.[[PreventExtensions]](). +features: [Proxy] +---*/ + +var plainObject = {}; +var plainObjectTarget = new Proxy(plainObject, {}); +var plainObjectProxy = new Proxy(plainObjectTarget, { + preventExtensions: null, +}); + +Object.preventExtensions(plainObjectProxy); +assert(!Object.isExtensible(plainObject)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-undefined-target-is-proxy.js new file mode 100644 index 0000000000..4eda6cef6b --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-undefined-target-is-proxy.js @@ -0,0 +1,35 @@ +// |reftest| module +// 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-preventextensions +description: > + If "preventExtensions" trap is null or undefined, [[PreventExtensions]] call + is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[PreventExtensions]] ( ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Let trap be ? GetMethod(handler, "preventExtensions"). + 6. If trap is undefined, then + a. Return ? target.[[PreventExtensions]](). + + [[PreventExtensions]] ( ) + + 1. Return true. +features: [Proxy, Reflect] +flags: [module] +---*/ + +import * as ns from "./trap-is-undefined-target-is-proxy.js"; + +var nsTarget = new Proxy(ns, {}); +var nsProxy = new Proxy(nsTarget, { + preventExtensions: undefined, +}); + +assert(Reflect.preventExtensions(nsProxy)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-undefined.js new file mode 100644 index 0000000000..234bb0945f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/preventExtensions/trap-is-undefined.js @@ -0,0 +1,15 @@ +// 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.4 +description: > + Return target.[[PreventExtensions]]() if target is undefined. +features: [Proxy, Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, {}); + +assert.sameValue(Reflect.preventExtensions(p), true); + +reportCompare(0, 0); |