diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Reflect/preventExtensions')
12 files changed, 315 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/always-return-true-from-ordinary-object.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/always-return-true-from-ordinary-object.js new file mode 100644 index 0000000000..2fd5603e85 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/always-return-true-from-ordinary-object.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: 26.1.12 +description: > + Always returns true when target is an ordinary object. +info: | + 26.1.12 Reflect.preventExtensions ( target ) + + ... + 2. Return target.[[PreventExtensions]](). + + 9.1.4 [[PreventExtensions]] ( ) + + 1. Set the value of the [[Extensible]] internal slot of O to false. + 2. Return true. +features: [Reflect] +---*/ + +var o = {}; +assert.sameValue( + Reflect.preventExtensions(o), true, + 'returns true after preventing extentions on an object' +); +assert.sameValue( + Reflect.preventExtensions(o), true, + 'returns true even if the object already prevents extentions' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/browser.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/length.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/length.js new file mode 100644 index 0000000000..ee474224bf --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/length.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: 26.1.12 +description: > + Reflect.preventExtensions.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.preventExtensions.length, 1, + 'The value of `Reflect.preventExtensions.length` is `1`' +); + +verifyNotEnumerable(Reflect.preventExtensions, 'length'); +verifyNotWritable(Reflect.preventExtensions, 'length'); +verifyConfigurable(Reflect.preventExtensions, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/name.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/name.js new file mode 100644 index 0000000000..802a6efbb6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/name.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.12 +description: > + Reflect.preventExtensions.name value and property descriptor +info: | + 26.1.12 Reflect.preventExtensions ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.preventExtensions.name, 'preventExtensions', + 'The value of `Reflect.preventExtensions.name` is `"preventExtensions"`' +); + +verifyNotEnumerable(Reflect.preventExtensions, 'name'); +verifyNotWritable(Reflect.preventExtensions, 'name'); +verifyConfigurable(Reflect.preventExtensions, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/not-a-constructor.js new file mode 100644 index 0000000000..9157e1a265 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Reflect.preventExtensions does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Reflect, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Reflect.preventExtensions), + false, + 'isConstructor(Reflect.preventExtensions) must return false' +); + +assert.throws(TypeError, () => { + new Reflect.preventExtensions({}); +}, '`new Reflect.preventExtensions({})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/prevent-extensions.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/prevent-extensions.js new file mode 100644 index 0000000000..9a5d447f8c --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/prevent-extensions.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: 26.1.12 +description: > + Prevent extentions on target. +info: | + 26.1.12 Reflect.preventExtensions ( target ) + + ... + 2. Return target.[[PreventExtensions]](). + + 9.1.4 [[PreventExtensions]] ( ) + + 1. Set the value of the [[Extensible]] internal slot of O to false. + ... +features: [Reflect] +---*/ + +var o = {}; +Reflect.preventExtensions(o); +assert.sameValue(Object.isExtensible(o), false, 'object is not extensible'); + +assert.throws(TypeError, function() { + Object.defineProperty(o, 'y', {}); +}); +assert.throws(TypeError, function() { + Object.setPrototypeOf(o, Array.prototype); +}); + +Reflect.preventExtensions(o); +assert.sameValue( + Object.isExtensible(o), false, + 'object is still not extensible on exhausted calls' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/preventExtensions.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/preventExtensions.js new file mode 100644 index 0000000000..5a63258c7b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/preventExtensions.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: 26.1.12 +description: > + Reflect.preventExtensions is configurable, writable and not enumerable. +info: | + 26.1.12 Reflect.preventExtensions ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'preventExtensions'); +verifyWritable(Reflect, 'preventExtensions'); +verifyConfigurable(Reflect, 'preventExtensions'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/return-abrupt-from-result.js new file mode 100644 index 0000000000..9ea916dd77 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/return-abrupt-from-result.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.12 +description: > + Return abrupt result. +info: | + 26.1.12 Reflect.preventExtensions ( target ) + + ... + 2. Return target.[[PreventExtensions]](). +features: [Proxy, Reflect] +---*/ + +var o1 = {}; +var p = new Proxy(o1, { + preventExtensions: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.preventExtensions(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/return-boolean-from-proxy-object.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/return-boolean-from-proxy-object.js new file mode 100644 index 0000000000..e6429a5bcb --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/return-boolean-from-proxy-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.12 +description: > + Returns boolean from Proxy object. +info: | + 26.1.12 Reflect.preventExtensions ( target ) + + ... + 2. Return target.[[PreventExtensions]](). + + 9.5.4 [[PreventExtensions]] ( ) + + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + 9. ReturnIfAbrupt(booleanTrapResult). + 10. If booleanTrapResult is true, then + a. Let targetIsExtensible be target.[[IsExtensible]](). + b. ReturnIfAbrupt(targetIsExtensible). + c. If targetIsExtensible is true, throw a TypeError exception. + 11. Return booleanTrapResult. +features: [Proxy, Reflect] +---*/ + +var p1 = new Proxy({}, { + preventExtensions: function() { + return false; + } +}); + +assert.sameValue( + Reflect.preventExtensions(p1), false, + 'returns false from Proxy handler' +); + +var p2 = new Proxy({}, { + preventExtensions: function(target) { + Object.preventExtensions(target); + return true; + } +}); + +assert.sameValue( + Reflect.preventExtensions(p2), true, + 'returns true from Proxy handler' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/shell.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/target-is-not-object-throws.js new file mode 100644 index 0000000000..fda7759680 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/target-is-not-object-throws.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: 26.1.10 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.11 Reflect.preventExtensions ( target ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.preventExtensions(1); +}); + +assert.throws(TypeError, function() { + Reflect.preventExtensions(null); +}); + +assert.throws(TypeError, function() { + Reflect.preventExtensions(undefined); +}); + +assert.throws(TypeError, function() { + Reflect.preventExtensions(''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/preventExtensions/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/preventExtensions/target-is-symbol-throws.js new file mode 100644 index 0000000000..4fdb837c23 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/preventExtensions/target-is-symbol-throws.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.10 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.10 Reflect.isExtensible (target) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.isExtensible(Symbol(1)); +}); + +reportCompare(0, 0); |