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/Reflect | |
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/Reflect')
183 files changed, 5045 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Reflect/Symbol.toStringTag.js b/js/src/tests/test262/built-ins/Reflect/Symbol.toStringTag.js new file mode 100644 index 0000000000..8a0c5297d3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/Symbol.toStringTag.js @@ -0,0 +1,23 @@ +// Copyright (C) 2020 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "Reflect". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag, Reflect] +---*/ + +verifyProperty(Reflect, Symbol.toStringTag, { + value: 'Reflect', + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/apply.js b/js/src/tests/test262/built-ins/Reflect/apply/apply.js new file mode 100644 index 0000000000..cb06ed6808 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/apply.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.1 +description: > + Reflect.apply is configurable, writable and not enumerable. +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'apply'); +verifyWritable(Reflect, 'apply'); +verifyConfigurable(Reflect, 'apply'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js b/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js new file mode 100644 index 0000000000..b275eb80b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js @@ -0,0 +1,82 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-reflect.apply +description: > + Return abrupt if argumentsList is not an ArrayLike object. +info: | + Reflect.apply ( target, thisArgument, argumentsList ) + + ... + Let args be ? CreateListFromArrayLike(argumentsList). + + + CreateListFromArrayLike (obj [, elementTypes] ) + + ... + If Type(obj) is not Object, throw a TypeError exception. + Let len be ? LengthOfArrayLike(obj). + Let list be a new empty List. + Let index be 0. + Repeat, while index < len, + Let indexName be ! ToString(index). + Let next be ? Get(obj, indexName). + If Type(next) is not an element of elementTypes, throw a TypeError exception. + Append next as the last element of list. + Set index to index + 1. + Return list. +includes: [compareArray.js] +features: [Reflect, arrow-function, Symbol] +---*/ + +let count = 0; + +function fn(...args) { + count++; + return args; +} + +let f_unction = new Function(); + +Object.defineProperty(f_unction, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, f_unction), [undefined]); + +let object = new Object(); + +Object.defineProperty(object, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, object), [undefined]); + +let number = new Number(); + +Object.defineProperty(number, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, number), [undefined]); + +let boolean = new Boolean(); + +Object.defineProperty(boolean, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, boolean), [undefined]); + +assert.sameValue(count, 4, 'The value of `count` is 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like.js b/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like.js new file mode 100644 index 0000000000..0213686fc0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like.js @@ -0,0 +1,75 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-reflect.apply +description: > + Return abrupt if argumentsList is not an ArrayLike object. +info: | + Reflect.apply ( target, thisArgument, argumentsList ) + + ... + Let args be ? CreateListFromArrayLike(argumentsList). + + + CreateListFromArrayLike (obj [, elementTypes] ) + + ... + If Type(obj) is not Object, throw a TypeError exception. +features: [Reflect, arrow-function, Symbol] +---*/ + +let count = 0; + +function fn() { + count++; +} + +assert.throws(Test262Error, () => { + Reflect.apply(fn, null, { + get length() { + throw new Test262Error(); + } + }); +}, '`Reflect.apply(fn, null, {get length() {throw new Test262Error();}})` throws a Test262Error exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null /* empty */); +}, '`Reflect.apply(fn, null /* empty */)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, Symbol()); +}, '`Reflect.apply(fn, null, Symbol())` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, 1); +}, '`Reflect.apply(fn, null, 1)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, Infinity); +}, '`Reflect.apply(fn, null, Infinity)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, null); +}, '`Reflect.apply(fn, null, null)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, undefined); +}, '`Reflect.apply(fn, null, undefined)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, false); +}, '`Reflect.apply(fn, null, false)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, true); +}, '`Reflect.apply(fn, null, true)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, NaN); +}, '`Reflect.apply(fn, null, NaN)` throws a TypeError exception'); + + +assert.sameValue(count, 0, 'The value of `count` is 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/browser.js b/js/src/tests/test262/built-ins/Reflect/apply/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/apply/call-target.js b/js/src/tests/test262/built-ins/Reflect/apply/call-target.js new file mode 100644 index 0000000000..390d394776 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/call-target.js @@ -0,0 +1,38 @@ +// 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.1 +description: > + Call target with thisArgument and argumentsList +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + ... + 4. Perform PrepareForTailCall(). + 5. Return Call(target, thisArgument, args). +features: [Reflect] +---*/ + +var o = {}; +var count = 0; +var results, args; + +function fn() { + count++; + results = { + thisArg: this, + args: arguments + }; +} + +Reflect.apply(fn, o, ['arg1', 2, , null]); + +assert.sameValue(count, 1, 'Called target once'); +assert.sameValue(results.thisArg, o, 'Called target with `o` as `this` object'); +assert.sameValue(results.args.length, 4, 'Called target with 4 arguments'); +assert.sameValue(results.args[0], 'arg1'); +assert.sameValue(results.args[1], 2); +assert.sameValue(results.args[2], undefined); +assert.sameValue(results.args[3], null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/length.js b/js/src/tests/test262/built-ins/Reflect/apply/length.js new file mode 100644 index 0000000000..3499bc3355 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/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.1 +description: > + Reflect.apply.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.apply.length, 3, + 'The value of `Reflect.apply.length` is `3`' +); + +verifyNotEnumerable(Reflect.apply, 'length'); +verifyNotWritable(Reflect.apply, 'length'); +verifyConfigurable(Reflect.apply, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/name.js b/js/src/tests/test262/built-ins/Reflect/apply/name.js new file mode 100644 index 0000000000..5da83c4d24 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/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.1 +description: > + Reflect.apply.name value and property descriptor +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.apply.name, 'apply', + 'The value of `Reflect.apply.name` is `"apply"`' +); + +verifyNotEnumerable(Reflect.apply, 'name'); +verifyNotWritable(Reflect.apply, 'name'); +verifyConfigurable(Reflect.apply, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/apply/not-a-constructor.js new file mode 100644 index 0000000000..4e4aa65254 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.apply 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.apply), false, 'isConstructor(Reflect.apply) must return false'); + +assert.throws(TypeError, () => { + new Reflect.apply(() => {}, undefined, []); +}, '`new Reflect.apply(() => {}, undefined, [])` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/return-target-call-result.js b/js/src/tests/test262/built-ins/Reflect/apply/return-target-call-result.js new file mode 100644 index 0000000000..a577540e1b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/return-target-call-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.1 +description: > + Return target result +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + ... + 4. Perform PrepareForTailCall(). + 5. Return Call(target, thisArgument, args). +features: [Reflect] +---*/ + +var o = {}; + +function fn() { + return o; +} + +var result = Reflect.apply(fn, 1, []); + +assert.sameValue(result, o); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/shell.js b/js/src/tests/test262/built-ins/Reflect/apply/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/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/apply/target-is-not-callable-throws.js b/js/src/tests/test262/built-ins/Reflect/apply/target-is-not-callable-throws.js new file mode 100644 index 0000000000..b795a5bdc4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/target-is-not-callable-throws.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: 26.1.1 +description: > + Throws a TypeError if `target` is not callable. +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + 1. If IsCallable(target) is false, throw a TypeError exception. + ... + + 7.2.3 IsCallable ( argument ) + + 1. ReturnIfAbrupt(argument). + 2. If Type(argument) is not Object, return false. + 3. If argument has a [[Call]] internal method, return true. + 4. Return false. +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.apply(1, 1, []); +}); + +assert.throws(TypeError, function() { + Reflect.apply(null, 1, []); +}); + +assert.throws(TypeError, function() { + Reflect.apply({}, 1, []); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/browser.js b/js/src/tests/test262/built-ins/Reflect/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/construct/arguments-list-is-not-array-like.js b/js/src/tests/test262/built-ins/Reflect/construct/arguments-list-is-not-array-like.js new file mode 100644 index 0000000000..d22af4b5d9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/arguments-list-is-not-array-like.js @@ -0,0 +1,42 @@ +// 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.2 +description: > + Return abrupt if argumentsList is not an ArrayLike object. +info: | + 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) + + ... + 4. Let args be CreateListFromArrayLike(argumentsList). + 5. ReturnIfAbrupt(args). + ... + + 7.3.17 CreateListFromArrayLike (obj [, elementTypes] ) + + ... + 3. If Type(obj) is not Object, throw a TypeError exception. + 4. Let len be ToLength(Get(obj, "length")). + 5. ReturnIfAbrupt(len). + ... +features: [Reflect, Reflect.construct] +---*/ + +function fn() {} +var o = {}; + +Object.defineProperty(o, 'length', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.construct(fn, o); +}); + +assert.throws(TypeError, function() { + Reflect.construct(fn, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/construct/browser.js b/js/src/tests/test262/built-ins/Reflect/construct/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/construct/construct.js b/js/src/tests/test262/built-ins/Reflect/construct/construct.js new file mode 100644 index 0000000000..f3e7d1c158 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/construct.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.2 +description: > + Reflect.construct is configurable, writable and not enumerable. +info: | + 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'construct'); +verifyWritable(Reflect, 'construct'); +verifyConfigurable(Reflect, 'construct'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/construct/length.js b/js/src/tests/test262/built-ins/Reflect/construct/length.js new file mode 100644 index 0000000000..72e142753f --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/length.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: 26.1.2 +description: > + Reflect.construct.length value and property descriptor +info: | + 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) + + The length property of the construct function is 2. +includes: [propertyHelper.js] +features: [Reflect, Reflect.construct] +---*/ + +assert.sameValue( + Reflect.construct.length, 2, + 'The value of `Reflect.construct.length` is `2`' +); + +verifyNotEnumerable(Reflect.construct, 'length'); +verifyNotWritable(Reflect.construct, 'length'); +verifyConfigurable(Reflect.construct, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/construct/name.js b/js/src/tests/test262/built-ins/Reflect/construct/name.js new file mode 100644 index 0000000000..ff1d6c51c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/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.2 +description: > + Reflect.construct.name value and property descriptor +info: | + 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect, Reflect.construct] +---*/ + +assert.sameValue( + Reflect.construct.name, 'construct', + 'The value of `Reflect.construct.name` is `"construct"`' +); + +verifyNotEnumerable(Reflect.construct, 'name'); +verifyNotWritable(Reflect.construct, 'name'); +verifyConfigurable(Reflect.construct, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/construct/newtarget-is-not-constructor-throws.js b/js/src/tests/test262/built-ins/Reflect/construct/newtarget-is-not-constructor-throws.js new file mode 100644 index 0000000000..e5e892488d --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/newtarget-is-not-constructor-throws.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: 26.1.2 +description: > + Throws a TypeError if `newTarget` is not a constructor. +info: | + 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) + + ... + 2. If newTarget is not present, let newTarget be target. + 3. Else, if IsConstructor(newTarget) is false, throw a TypeError exception. + ... +features: [Reflect, Reflect.construct] +---*/ + +assert.throws(TypeError, function() { + Reflect.construct(function() {}, [], 1); +}); + +assert.throws(TypeError, function() { + Reflect.construct(function() {}, [], null); +}); + +assert.throws(TypeError, function() { + Reflect.construct(function() {}, [], {}); +}); + +assert.throws(TypeError, function() { + Reflect.construct(function() {}, [], Date.now); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/construct/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/construct/not-a-constructor.js new file mode 100644 index 0000000000..16b99500a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.construct 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.construct), false, 'isConstructor(Reflect.construct) must return false'); + +assert.throws(TypeError, () => { + new Reflect.construct(Function, [], Function); +}, '`new Reflect.construct(Function, [], Function)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/construct/return-with-newtarget-argument.js b/js/src/tests/test262/built-ins/Reflect/construct/return-with-newtarget-argument.js new file mode 100644 index 0000000000..e478817771 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/return-with-newtarget-argument.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: 26.1.2 +description: > + Return target result using newTarget argument. +info: | + 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) + + ... + 2. If newTarget is not present, let newTarget be target. + ... + 6. Return Construct(target, args, newTarget). +features: [Reflect, Reflect.construct] +---*/ + +var o = {}; +var internPrototype; + +function fn() { + this.o = o; + internPrototype = Object.getPrototypeOf(this); +} + +var result = Reflect.construct(fn, [], Array); +assert.sameValue(Object.getPrototypeOf(result), Array.prototype); +assert.sameValue( + internPrototype, Array.prototype, + 'prototype of this from within the constructor function is Array.prototype' +); +assert.sameValue(result.o, o); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/construct/return-without-newtarget-argument.js b/js/src/tests/test262/built-ins/Reflect/construct/return-without-newtarget-argument.js new file mode 100644 index 0000000000..1c9106865d --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/return-without-newtarget-argument.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: 26.1.2 +description: > + Return target result +info: | + 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) + + ... + 2. If newTarget is not present, let newTarget be target. + ... + 6. Return Construct(target, args, newTarget). +features: [Reflect, Reflect.construct] +---*/ + +var o = {}; + +function fn() { + this.o = o; +} + +var result = Reflect.construct(fn, []); + +assert.sameValue(result.o, o); +assert(result instanceof fn); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/construct/shell.js b/js/src/tests/test262/built-ins/Reflect/construct/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/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/construct/target-is-not-constructor-throws.js b/js/src/tests/test262/built-ins/Reflect/construct/target-is-not-constructor-throws.js new file mode 100644 index 0000000000..77aff79960 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/target-is-not-constructor-throws.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.2 +description: > + Throws a TypeError if `target` is not a constructor. +info: | + 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) + + 1. If IsConstructor(target) is false, throw a TypeError exception. +features: [Reflect, Reflect.construct] +---*/ + +assert.throws(TypeError, function() { + Reflect.construct(1, []); +}); + +assert.throws(TypeError, function() { + Reflect.construct(null, []); +}); + +assert.throws(TypeError, function() { + Reflect.construct({}, []); +}); + +assert.throws(TypeError, function() { + Reflect.construct(Date.now, []); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/construct/use-arguments-list.js b/js/src/tests/test262/built-ins/Reflect/construct/use-arguments-list.js new file mode 100644 index 0000000000..6ef71bddf2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/construct/use-arguments-list.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: 26.1.2 +description: > + Construct with given argumentsList +info: | + 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) + + ... + 2. If newTarget is not present, let newTarget be target. + ... + 6. Return Construct(target, args, newTarget). +features: [Reflect, Reflect.construct] +---*/ + +function fn() { + this.args = arguments; +} + +var result = Reflect.construct(fn, [42, 'Mike', 'Leo']); + +assert.sameValue(result.args.length, 3, 'result.args.length'); +assert.sameValue(result.args[0], 42); +assert.sameValue(result.args[1], 'Mike'); +assert.sameValue(result.args[2], 'Leo'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/browser.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/define-properties.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/define-properties.js new file mode 100644 index 0000000000..70db2bfc03 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/define-properties.js @@ -0,0 +1,42 @@ +// 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.3 +description: > + Define properties from the attributes object. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 6. Return target.[[DefineOwnProperty]](key, desc). +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +var o = {}; +var desc; + +Reflect.defineProperty(o, 'p1', { + value: 42, + writable: true, + enumerable: true +}); + +assert.sameValue(o.p1, 42); + +verifyWritable(o, 'p1'); +verifyNotConfigurable(o, 'p1'); +verifyEnumerable(o, 'p1'); + +var f1 = function() {}; +var f2 = function() {}; +Reflect.defineProperty(o, 'p2', { + get: f1, + set: f2 +}); + +desc = Object.getOwnPropertyDescriptor(o, 'p2'); +assert.sameValue(desc.get, f1); +assert.sameValue(desc.set, f2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/define-symbol-properties.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/define-symbol-properties.js new file mode 100644 index 0000000000..06ce6e3145 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/define-symbol-properties.js @@ -0,0 +1,55 @@ +// 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.3 +description: > + Define symbol properties. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + ... + + 7.1.14 ToPropertyKey ( argument ) + + ... + 3. If Type(key) is Symbol, then + a. Return key. + ... +features: [Reflect, Symbol] +---*/ + +var o = {}; +var desc; + +var s1 = Symbol('1'); + +Reflect.defineProperty(o, s1, { + value: 42, + writable: true, + enumerable: true +}); + +assert.sameValue(o[s1], 42); + +desc = Object.getOwnPropertyDescriptor(o, s1); + +assert.sameValue(desc.writable, true); +assert.sameValue(desc.configurable, false); +assert.sameValue(desc.enumerable, true); + +var s2 = Symbol('2'); + +var f1 = function() {}; +var f2 = function() {}; +Reflect.defineProperty(o, s2, { + get: f1, + set: f2 +}); + +desc = Object.getOwnPropertyDescriptor(o, s2); +assert.sameValue(desc.get, f1); +assert.sameValue(desc.set, f2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/defineProperty.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/defineProperty.js new file mode 100644 index 0000000000..ddcd54b03a --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/defineProperty.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.3 +description: > + Reflect.defineProperty is configurable, writable and not enumerable. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'defineProperty'); +verifyWritable(Reflect, 'defineProperty'); +verifyConfigurable(Reflect, 'defineProperty'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/length.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/length.js new file mode 100644 index 0000000000..2b5b742918 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/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.3 +description: > + Reflect.defineProperty.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.defineProperty.length, 3, + 'The value of `Reflect.defineProperty.length` is `3`' +); + +verifyNotEnumerable(Reflect.defineProperty, 'length'); +verifyNotWritable(Reflect.defineProperty, 'length'); +verifyConfigurable(Reflect.defineProperty, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/name.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/name.js new file mode 100644 index 0000000000..5315b9d272 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/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.3 +description: > + Reflect.defineProperty.name value and property descriptor +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.defineProperty.name, 'defineProperty', + 'The value of `Reflect.defineProperty.name` is `"defineProperty"`' +); + +verifyNotEnumerable(Reflect.defineProperty, 'name'); +verifyNotWritable(Reflect.defineProperty, 'name'); +verifyConfigurable(Reflect.defineProperty, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/not-a-constructor.js new file mode 100644 index 0000000000..c878ad4756 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/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.defineProperty 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.defineProperty), + false, + 'isConstructor(Reflect.defineProperty) must return false' +); + +assert.throws(TypeError, () => { + new Reflect.defineProperty({}, ''); +}, '`new Reflect.defineProperty({}, \'\')` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-attributes.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-attributes.js new file mode 100644 index 0000000000..0d7b06651a --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-attributes.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: 26.1.3 +description: > + Return abrupt from ToPropertyDescriptor(attributes). +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 4. Let desc be ToPropertyDescriptor(attributes). + 5. ReturnIfAbrupt(desc). + ... +features: [Reflect] +---*/ + +var attributes = {}; + +Object.defineProperty(attributes, 'enumerable', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.defineProperty({}, 'a', attributes); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-property-key.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-property-key.js new file mode 100644 index 0000000000..445091d121 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-property-key.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: 26.1.3 +description: > + Return abrupt from ToPropertyKey(propertyKey) +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + 3. ReturnIfAbrupt(key). + ... +features: [Reflect] +---*/ + +var p = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Reflect.defineProperty({}, p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-result.js new file mode 100644 index 0000000000..9e63455414 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-result.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: 26.1.3 +description: > + Return abrupt result on defining a property. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 6. Return target.[[DefineOwnProperty]](key, desc). + ... + + 9.1.6.1 OrdinaryDefineOwnProperty (O, P, Desc) + + 1. Let current be O.[[GetOwnProperty]](P). + 2. ReturnIfAbrupt(current). + ... +features: [Proxy, Reflect] +---*/ + +var o = {}; +var p = new Proxy(o, { + defineProperty: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.defineProperty(p, 'p1', {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/return-boolean.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-boolean.js new file mode 100644 index 0000000000..897788f299 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-boolean.js @@ -0,0 +1,41 @@ +// 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.3 +description: > + Return boolean result of the property definition. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 6. Return target.[[DefineOwnProperty]](key, desc). +features: [Reflect] +---*/ + +var o = {}; + +o.p1 = 'foo'; +assert.sameValue(Reflect.defineProperty(o, 'p1', {}), true); +assert.sameValue(o.hasOwnProperty('p1'), true); + +assert.sameValue(Reflect.defineProperty(o, 'p2', { + value: 42 +}), true); +assert.sameValue(o.hasOwnProperty('p2'), true); + +Object.freeze(o); + +assert.sameValue(Reflect.defineProperty(o, 'p2', { + value: 43 +}), false); +assert.sameValue(o.p2, 42); + +assert.sameValue(Reflect.defineProperty(o, 'p3', {}), false); +assert.sameValue(o.hasOwnProperty('p4'), false); + +assert.sameValue(Reflect.defineProperty(o, 'p4', { + value: 1 +}), false); +assert.sameValue(o.hasOwnProperty('p4'), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/shell.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/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/defineProperty/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/target-is-not-object-throws.js new file mode 100644 index 0000000000..37013cb696 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/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.3 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.defineProperty(1, 'p', {}); +}); + +assert.throws(TypeError, function() { + Reflect.defineProperty(null, 'p', {}); +}); + +assert.throws(TypeError, function() { + Reflect.defineProperty(undefined, 'p', {}); +}); + +assert.throws(TypeError, function() { + Reflect.defineProperty('', 'p', {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/target-is-symbol-throws.js new file mode 100644 index 0000000000..1cf53974d1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/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.3 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.defineProperty(Symbol(1), 'p', {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/browser.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/delete-properties.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/delete-properties.js new file mode 100644 index 0000000000..9e3dd1d19a --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/delete-properties.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: 26.1.4 +description: > + Delete property. +info: | + 26.1.4 Reflect.deleteProperty ( target, propertyKey ) + + ... + 4. Return target.[[Delete]](key). +features: [Reflect] +---*/ + +var o = { + prop: 42 +}; + +Reflect.deleteProperty(o, 'prop'); + +assert.sameValue(o.hasOwnProperty('prop'), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/delete-symbol-properties.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/delete-symbol-properties.js new file mode 100644 index 0000000000..a2c933074d --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/delete-symbol-properties.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: 26.1.4 +description: > + Delete a symbol property. +info: | + 26.1.4 Reflect.deleteProperty ( target, propertyKey ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + ... + + 7.1.14 ToPropertyKey ( argument ) + + ... + 3. If Type(key) is Symbol, then + a. Return key. + ... +features: [Reflect, Symbol] +---*/ + +var s = Symbol('1'); +var o = {}; +o[s] = 42; + +Reflect.deleteProperty(o, s); + +assert.sameValue(o.hasOwnProperty(s), false); +assert.sameValue(o[s], undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/deleteProperty.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/deleteProperty.js new file mode 100644 index 0000000000..6f6a9fa1e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/deleteProperty.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.4 +description: > + Reflect.deleteProperty is configurable, writable and not enumerable. +info: | + 26.1.4 Reflect.deleteProperty ( target, propertyKey ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'deleteProperty'); +verifyWritable(Reflect, 'deleteProperty'); +verifyConfigurable(Reflect, 'deleteProperty'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/length.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/length.js new file mode 100644 index 0000000000..f340de07b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/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.4 +description: > + Reflect.deleteProperty.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.deleteProperty.length, 2, + 'The value of `Reflect.deleteProperty.length` is `2`' +); + +verifyNotEnumerable(Reflect.deleteProperty, 'length'); +verifyNotWritable(Reflect.deleteProperty, 'length'); +verifyConfigurable(Reflect.deleteProperty, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/name.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/name.js new file mode 100644 index 0000000000..8f6a2ead5b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/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.4 +description: > + Reflect.deleteProperty.name value and property descriptor +info: | + 26.1.4 Reflect.deleteProperty ( target, propertyKey ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.deleteProperty.name, 'deleteProperty', + 'The value of `Reflect.deleteProperty.name` is `"deleteProperty"`' +); + +verifyNotEnumerable(Reflect.deleteProperty, 'name'); +verifyNotWritable(Reflect.deleteProperty, 'name'); +verifyConfigurable(Reflect.deleteProperty, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/not-a-constructor.js new file mode 100644 index 0000000000..afbc5ae119 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/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.deleteProperty 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.deleteProperty), + false, + 'isConstructor(Reflect.deleteProperty) must return false' +); + +assert.throws(TypeError, () => { + new Reflect.deleteProperty({}, ''); +}, '`new Reflect.deleteProperty({}, \'\')` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/return-abrupt-from-property-key.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/return-abrupt-from-property-key.js new file mode 100644 index 0000000000..538adf082b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/return-abrupt-from-property-key.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: 26.1.4 +description: > + Return abrupt from ToPropertyKey(propertyKey) +info: | + 26.1.4 Reflect.deleteProperty ( target, propertyKey ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + 3. ReturnIfAbrupt(key). + ... +features: [Reflect] +---*/ + +var p = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Reflect.deleteProperty({}, p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/return-abrupt-from-result.js new file mode 100644 index 0000000000..7a217bd3d9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/return-abrupt-from-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: 26.1.4 +description: > + Return abrupt result from deleting a property. +info: | + 26.1.4 Reflect.deleteProperty ( target, propertyKey ) + + ... + 6. Return target.[[DefineOwnProperty]](key, desc). + ... +features: [Proxy, Reflect] +---*/ + +var o = {}; +var p = new Proxy(o, { + deleteProperty: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.deleteProperty(p, 'p1'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/return-boolean.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/return-boolean.js new file mode 100644 index 0000000000..88631bfdee --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/return-boolean.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.4 +description: > + Return boolean result. +info: | + 26.1.4 Reflect.deleteProperty ( target, propertyKey ) + + ... + 4. Return target.[[Delete]](key). +features: [Reflect] +---*/ + +var o = {}; + +o.p1 = 'foo'; +assert.sameValue(Reflect.deleteProperty(o, 'p1'), true); +assert.sameValue(o.hasOwnProperty('p1'), false); + +o.p2 = 'foo'; +Object.freeze(o); +assert.sameValue(Reflect.deleteProperty(o, 'p2'), false); +assert.sameValue(o.hasOwnProperty('p2'), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/shell.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/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/deleteProperty/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/target-is-not-object-throws.js new file mode 100644 index 0000000000..658422d575 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/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.4 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.4 Reflect.deleteProperty ( target, propertyKey ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.deleteProperty(1, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.deleteProperty(null, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.deleteProperty(undefined, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.deleteProperty('', 'p'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/deleteProperty/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/deleteProperty/target-is-symbol-throws.js new file mode 100644 index 0000000000..987c39364f --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/deleteProperty/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.4 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.4 Reflect.deleteProperty ( target, propertyKey ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.deleteProperty(Symbol(1), 'p'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/enumerate/browser.js b/js/src/tests/test262/built-ins/Reflect/enumerate/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/enumerate/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/enumerate/shell.js b/js/src/tests/test262/built-ins/Reflect/enumerate/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/enumerate/shell.js diff --git a/js/src/tests/test262/built-ins/Reflect/enumerate/undefined.js b/js/src/tests/test262/built-ins/Reflect/enumerate/undefined.js new file mode 100644 index 0000000000..3769a357ad --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/enumerate/undefined.js @@ -0,0 +1,13 @@ +// 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-reflect-object +description: > + Reflect.enumerate was removed and it's not a function anymore +features: [Reflect] +---*/ + +assert.sameValue(Reflect.hasOwnProperty("enumerate"), false); +assert.sameValue(Reflect.enumerate, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/browser.js b/js/src/tests/test262/built-ins/Reflect/get/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/get/get.js b/js/src/tests/test262/built-ins/Reflect/get/get.js new file mode 100644 index 0000000000..ea85d09962 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/get.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.6 +description: > + Reflect.get is configurable, writable and not enumerable. +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'get'); +verifyWritable(Reflect, 'get'); +verifyConfigurable(Reflect, 'get'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/length.js b/js/src/tests/test262/built-ins/Reflect/get/length.js new file mode 100644 index 0000000000..615f35d6cc --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/length.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: 26.1.6 +description: > + Reflect.get.length value and property descriptor +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + The length property of the get function is 2. +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.get.length, 2, + 'The value of `Reflect.get.length` is `2`' +); + +verifyNotEnumerable(Reflect.get, 'length'); +verifyNotWritable(Reflect.get, 'length'); +verifyConfigurable(Reflect.get, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/name.js b/js/src/tests/test262/built-ins/Reflect/get/name.js new file mode 100644 index 0000000000..d474d98e0f --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/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.6 +description: > + Reflect.get.name value and property descriptor +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.get.name, 'get', + 'The value of `Reflect.get.name` is `"get"`' +); + +verifyNotEnumerable(Reflect.get, 'name'); +verifyNotWritable(Reflect.get, 'name'); +verifyConfigurable(Reflect.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/get/not-a-constructor.js new file mode 100644 index 0000000000..73635058ff --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.get 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.get), false, 'isConstructor(Reflect.get) must return false'); + +assert.throws(TypeError, () => { + new Reflect.get({}, ''); +}, '`new Reflect.get({}, \'\')` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/return-abrupt-from-property-key.js b/js/src/tests/test262/built-ins/Reflect/get/return-abrupt-from-property-key.js new file mode 100644 index 0000000000..0fa8115530 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/return-abrupt-from-property-key.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: 26.1.6 +description: > + Return abrupt from ToPropertyKey(propertyKey) +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + ... + 2. Let key be ToPropertyKey(propertyKey). + 3. ReturnIfAbrupt(key). + ... +features: [Reflect] +---*/ + +var p = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Reflect.get({}, p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/get/return-abrupt-from-result.js new file mode 100644 index 0000000000..10a86ac487 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/return-abrupt-from-result.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: 26.1.6 +description: > + Return abrupt result from get a property value. +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + ... + 5. Return target.[[Get]](key, receiver). +features: [Reflect] +---*/ + +var o1 = {}; +Object.defineProperty(o1, 'p1', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.get(o1, 'p1'); +}); + +// Abrupt from the prototype property +var o2 = Object.create(o1); +assert.throws(Test262Error, function() { + Reflect.get(o2, 'p1'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/return-value-from-receiver.js b/js/src/tests/test262/built-ins/Reflect/get/return-value-from-receiver.js new file mode 100644 index 0000000000..fd5ece4ad9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/return-value-from-receiver.js @@ -0,0 +1,54 @@ +// 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.6 +description: > + Return value from a receiver. +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Get]](key, receiver). + + 9.1.8 [[Get]] (P, Receiver) + + ... + 2. Let desc be O.[[GetOwnProperty]](P). + 3. ReturnIfAbrupt(desc). + 4. If desc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is null, return undefined. + d. Return parent.[[Get]](P, Receiver). + 5. If IsDataDescriptor(desc) is true, return desc.[[Value]]. + 6. Otherwise, IsAccessorDescriptor(desc) must be true so, let getter be + desc.[[Get]]. + 7. If getter is undefined, return undefined. + 8. Return Call(getter, Receiver). +features: [Reflect] +---*/ + +var o1 = {}; +var receiver = { + y: 42 +}; + +Object.defineProperty(o1, 'x', { + get: function() { + return this.y; + } +}); +assert.sameValue( + Reflect.get(o1, 'x', receiver), 42, + 'Return own property value using a receiver' +); + +var o2 = Object.create(o1); +assert.sameValue( + Reflect.get(o2, 'x', receiver), 42, + 'Return prototype property value using a receiver' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/return-value-from-symbol-key.js b/js/src/tests/test262/built-ins/Reflect/get/return-value-from-symbol-key.js new file mode 100644 index 0000000000..7e1ddc25ad --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/return-value-from-symbol-key.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: 26.1.6 +description: > + Return value where property key is a symbol. +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + ... + 2. Let key be ToPropertyKey(propertyKey). + ... + + 7.1.14 ToPropertyKey ( argument ) + + ... + 3. If Type(key) is Symbol, then + a. Return key. + ... +features: [Reflect, Symbol] +---*/ + +var o = {}; +var s = Symbol('1'); +o[s] = 42; + +assert.sameValue(Reflect.get(o, s), 42); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/return-value.js b/js/src/tests/test262/built-ins/Reflect/get/return-value.js new file mode 100644 index 0000000000..0c4869cd4c --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/return-value.js @@ -0,0 +1,72 @@ +// 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.6 +description: > + Return value. +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Get]](key, receiver). + + 9.1.8 [[Get]] (P, Receiver) + + ... + 2. Let desc be O.[[GetOwnProperty]](P). + 3. ReturnIfAbrupt(desc). + 4. If desc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is null, return undefined. + d. Return parent.[[Get]](P, Receiver). + 5. If IsDataDescriptor(desc) is true, return desc.[[Value]]. + 6. Otherwise, IsAccessorDescriptor(desc) must be true so, let getter be + desc.[[Get]]. + 7. If getter is undefined, return undefined. + 8. Return Call(getter, Receiver). +features: [Reflect] +---*/ + +var o = {}; + +o.p1 = 'value 1'; +assert.sameValue( + Reflect.get(o, 'p1'), 'value 1', + 'Return value from data descriptor' +); + +Object.defineProperty(o, 'p2', { + get: undefined +}); +assert.sameValue( + Reflect.get(o, 'p2'), undefined, + 'Return undefined if getter is undefined' +); + +Object.defineProperty(o, 'p3', { + get: function() { + return 'foo'; + } +}); +assert.sameValue( + Reflect.get(o, 'p3'), 'foo', + 'Return Call(getter, Receiver)' +); + +var o2 = Object.create({ + p: 42 +}); +assert.sameValue( + Reflect.get(o2, 'p'), 42, + 'Return value from prototype without own property.' +); + +assert.sameValue( + Reflect.get(o2, 'u'), undefined, + 'Return undefined without property on the object and its prototype' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/shell.js b/js/src/tests/test262/built-ins/Reflect/get/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/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/get/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/get/target-is-not-object-throws.js new file mode 100644 index 0000000000..ea13d84414 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/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.6 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.get(1, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.get(null, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.get(undefined, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.get('', 'p'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/get/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/get/target-is-symbol-throws.js new file mode 100644 index 0000000000..de683778ad --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/get/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.6 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.get(Symbol(1), 'p'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/browser.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/getOwnPropertyDescriptor.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/getOwnPropertyDescriptor.js new file mode 100644 index 0000000000..48c2268874 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/getOwnPropertyDescriptor.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.7 +description: > + Reflect.getOwnPropertyDescriptor is configurable, writable and not enumerable. +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'getOwnPropertyDescriptor'); +verifyWritable(Reflect, 'getOwnPropertyDescriptor'); +verifyConfigurable(Reflect, 'getOwnPropertyDescriptor'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/length.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/length.js new file mode 100644 index 0000000000..47bc4d2b9b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/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.7 +description: > + Reflect.getOwnPropertyDescriptor.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.getOwnPropertyDescriptor.length, 2, + 'The value of `Reflect.getOwnPropertyDescriptor.length` is `2`' +); + +verifyNotEnumerable(Reflect.getOwnPropertyDescriptor, 'length'); +verifyNotWritable(Reflect.getOwnPropertyDescriptor, 'length'); +verifyConfigurable(Reflect.getOwnPropertyDescriptor, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/name.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/name.js new file mode 100644 index 0000000000..521736be82 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/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.7 +description: > + Reflect.getOwnPropertyDescriptor.name value and property descriptor +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.getOwnPropertyDescriptor.name, 'getOwnPropertyDescriptor', + 'The value of `Reflect.getOwnPropertyDescriptor.name` is `"getOwnPropertyDescriptor"`' +); + +verifyNotEnumerable(Reflect.getOwnPropertyDescriptor, 'name'); +verifyNotWritable(Reflect.getOwnPropertyDescriptor, 'name'); +verifyConfigurable(Reflect.getOwnPropertyDescriptor, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/not-a-constructor.js new file mode 100644 index 0000000000..62c4d5511e --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/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.getOwnPropertyDescriptor 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.getOwnPropertyDescriptor), + false, + 'isConstructor(Reflect.getOwnPropertyDescriptor) must return false' +); + +assert.throws(TypeError, () => { + new Reflect.getOwnPropertyDescriptor({}, ''); +}, '`new Reflect.getOwnPropertyDescriptor({}, \'\')` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-property-key.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-property-key.js new file mode 100644 index 0000000000..61a47cc036 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-property-key.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: 26.1.7 +description: > + Return abrupt from ToPropertyKey(propertyKey) +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + 3. ReturnIfAbrupt(key). + ... +features: [Reflect] +---*/ + +var p = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Reflect.getOwnPropertyDescriptor({}, p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-result.js new file mode 100644 index 0000000000..a5af7f65c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-result.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: 26.1.7 +description: > + Return abrupt result from getting the property descriptor. +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + ... + 4. Let desc be target.[[GetOwnProperty]](key). + 5. ReturnIfAbrupt(desc). + ... +features: [Proxy, Reflect] +---*/ + +var o1 = {}; +var p = new Proxy(o1, { + getOwnPropertyDescriptor: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.getOwnPropertyDescriptor(p, 'p1'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-from-accessor-descriptor.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-from-accessor-descriptor.js new file mode 100644 index 0000000000..e4200db1c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-from-accessor-descriptor.js @@ -0,0 +1,57 @@ +// 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.7 +description: > + Return a property descriptor object as an accessor descriptor. +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + ... + 4. Let desc be target.[[GetOwnProperty]](key). + 5. ReturnIfAbrupt(desc). + 6. Return FromPropertyDescriptor(desc). + + 6.2.4.4 FromPropertyDescriptor ( Desc ) + + ... + 2. Let obj be ObjectCreate(%ObjectPrototype%). + ... + 4. If Desc has a [[Value]] field, then + a. Perform CreateDataProperty(obj, "value", Desc.[[Value]]). + 5. If Desc has a [[Writable]] field, then + a. Perform CreateDataProperty(obj, "writable", Desc.[[Writable]]). + 6. If Desc has a [[Get]] field, then + a. Perform CreateDataProperty(obj, "get", Desc.[[Get]]). + 7. If Desc has a [[Set]] field, then + a. Perform CreateDataProperty(obj, "set", Desc.[[Set]]) + 8. If Desc has an [[Enumerable]] field, then + a. Perform CreateDataProperty(obj, "enumerable", Desc.[[Enumerable]]). + 9. If Desc has a [[Configurable]] field, then + a. Perform CreateDataProperty(obj , "configurable", Desc.[[Configurable]]). + ... + 11. Return obj. + +includes: [compareArray.js] +features: [Reflect] +---*/ + +var o1 = {}; +var fn = function() {}; +Object.defineProperty(o1, 'p', { + get: fn, + configurable: true +}); + +var result = Reflect.getOwnPropertyDescriptor(o1, 'p'); + +assert.compareArray( + Object.getOwnPropertyNames(result), + ['get', 'set', 'enumerable', 'configurable'] +); +assert.sameValue(result.enumerable, false); +assert.sameValue(result.configurable, true); +assert.sameValue(result.get, fn); +assert.sameValue(result.set, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-from-data-descriptor.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-from-data-descriptor.js new file mode 100644 index 0000000000..6acc6cdcff --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/return-from-data-descriptor.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: 26.1.7 +description: > + Return a property descriptor object as a data descriptor. +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + ... + 4. Let desc be target.[[GetOwnProperty]](key). + 5. ReturnIfAbrupt(desc). + 6. Return FromPropertyDescriptor(desc). +includes: [compareArray.js] +features: [Reflect] +---*/ + +var o1 = { + p: 'foo' +}; + +var result = Reflect.getOwnPropertyDescriptor(o1, 'p'); + +assert.compareArray( + Object.getOwnPropertyNames(result), + ['value', 'writable', 'enumerable', 'configurable'] +); +assert.sameValue(result.value, 'foo'); +assert.sameValue(result.enumerable, true); +assert.sameValue(result.configurable, true); +assert.sameValue(result.writable, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/shell.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/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/getOwnPropertyDescriptor/symbol-property.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/symbol-property.js new file mode 100644 index 0000000000..ed4956702d --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/symbol-property.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: 26.1.7 +description: > + Use a symbol value on property key. +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + ... + + 7.1.14 ToPropertyKey ( argument ) + + ... + 3. If Type(key) is Symbol, then + a. Return key. + ... +includes: [compareArray.js] +features: [Reflect, Symbol] +---*/ + +var o = {}; +var s = Symbol('42'); +o[s] = 42; + +var result = Reflect.getOwnPropertyDescriptor(o, s); + +assert.compareArray( + Object.getOwnPropertyNames(result), + ['value', 'writable', 'enumerable', 'configurable'] +); +assert.sameValue(result.value, 42); +assert.sameValue(result.enumerable, true); +assert.sameValue(result.configurable, true); +assert.sameValue(result.writable, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/target-is-not-object-throws.js new file mode 100644 index 0000000000..597cbd22ee --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/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.7 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.getOwnPropertyDescriptor(1, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.getOwnPropertyDescriptor(null, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.getOwnPropertyDescriptor(undefined, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.getOwnPropertyDescriptor('', 'p'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/target-is-symbol-throws.js new file mode 100644 index 0000000000..426385becf --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/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.7 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.getOwnPropertyDescriptor(Symbol(1), 'p'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/undefined-own-property.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/undefined-own-property.js new file mode 100644 index 0000000000..5328c41105 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/undefined-own-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 Leonardo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.7 +description: > + Return undefined for an non existing own property. +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + ... + 4. Let desc be target.[[GetOwnProperty]](key). + 5. ReturnIfAbrupt(desc). + 6. Return FromPropertyDescriptor(desc). + + 6.2.4.4 FromPropertyDescriptor ( Desc ) + + 1. If Desc is undefined, return undefined. +features: [Reflect] +---*/ + +var o = Object.create({ + p: 1 +}); + +var result = Reflect.getOwnPropertyDescriptor(o, 'p'); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/undefined-property.js b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/undefined-property.js new file mode 100644 index 0000000000..3eff63118f --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getOwnPropertyDescriptor/undefined-property.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: 26.1.7 +description: > + Return undefined for an undefined property. +info: | + 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) + + ... + 4. Let desc be target.[[GetOwnProperty]](key). + 5. ReturnIfAbrupt(desc). + 6. Return FromPropertyDescriptor(desc). + + 6.2.4.4 FromPropertyDescriptor ( Desc ) + + 1. If Desc is undefined, return undefined. +features: [Reflect] +---*/ + +var result = Reflect.getOwnPropertyDescriptor({}, undefined); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/browser.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/getPrototypeOf.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/getPrototypeOf.js new file mode 100644 index 0000000000..f23002326a --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/getPrototypeOf.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.8 +description: > + Reflect.getPrototypeOf is configurable, writable and not enumerable. +info: | + 26.1.8 Reflect.getPrototypeOf ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'getPrototypeOf'); +verifyWritable(Reflect, 'getPrototypeOf'); +verifyConfigurable(Reflect, 'getPrototypeOf'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/length.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/length.js new file mode 100644 index 0000000000..30e3ba0e5d --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/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.8 +description: > + Reflect.getPrototypeOf.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.getPrototypeOf.length, 1, + 'The value of `Reflect.getPrototypeOf.length` is `1`' +); + +verifyNotEnumerable(Reflect.getPrototypeOf, 'length'); +verifyNotWritable(Reflect.getPrototypeOf, 'length'); +verifyConfigurable(Reflect.getPrototypeOf, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/name.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/name.js new file mode 100644 index 0000000000..6d6e1df287 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/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.8 +description: > + Reflect.getPrototypeOf.name value and property descriptor +info: | + 26.1.8 Reflect.getPrototypeOf ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.getPrototypeOf.name, 'getPrototypeOf', + 'The value of `Reflect.getPrototypeOf.name` is `"getPrototypeOf"`' +); + +verifyNotEnumerable(Reflect.getPrototypeOf, 'name'); +verifyNotWritable(Reflect.getPrototypeOf, 'name'); +verifyConfigurable(Reflect.getPrototypeOf, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/not-a-constructor.js new file mode 100644 index 0000000000..6ce18c7913 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/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.getPrototypeOf 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.getPrototypeOf), + false, + 'isConstructor(Reflect.getPrototypeOf) must return false' +); + +assert.throws(TypeError, () => { + new Reflect.getPrototypeOf({}); +}, '`new Reflect.getPrototypeOf({})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/null-prototype.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/null-prototype.js new file mode 100644 index 0000000000..1f2536d2af --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/null-prototype.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: 26.1.8 +description: > + Return null prototype. +info: | + 26.1.8 Reflect.getPrototypeOf ( target ) + + ... + 2. Return target.[[GetPrototypeOf]](). +features: [Reflect] +---*/ + +var o = Object.create(null); +assert.sameValue(Reflect.getPrototypeOf(o), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/return-abrupt-from-result.js new file mode 100644 index 0000000000..607cba81a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/return-abrupt-from-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: 26.1.8 +description: > + Return abrupt result from getting the prototype. +info: | + 26.1.8 Reflect.getPrototypeOf ( target ) + + ... + 2. Return target.[[GetPrototypeOf]](). + ... +features: [Proxy, Reflect] +---*/ + +var o1 = {}; +var p = new Proxy(o1, { + getPrototypeOf: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.getPrototypeOf(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/return-prototype.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/return-prototype.js new file mode 100644 index 0000000000..beee511462 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/return-prototype.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: 26.1.8 +description: > + Returns the internal [[Prototype]] object. +info: | + 26.1.8 Reflect.getPrototypeOf ( target ) + + ... + 2. Return target.[[GetPrototypeOf]](). +features: [Reflect] +---*/ + +var o = {}; +assert.sameValue( + Reflect.getPrototypeOf(o), Object.prototype, + 'return default prototypes' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/shell.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/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/getPrototypeOf/skip-own-properties.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/skip-own-properties.js new file mode 100644 index 0000000000..63bb4f1fdb --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/skip-own-properties.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: 26.1.8 +description: > + Skip own properties to return the internal [[Prototype]] object. +info: | + 26.1.8 Reflect.getPrototypeOf ( target ) + + ... + 2. Return target.[[GetPrototypeOf]](). +features: [Reflect] +---*/ + +var valid = {}; +var o = Object.create(valid, { + prototype: { + value: 'invalid', + enumerable: true + } +}); + +assert.sameValue( + Reflect.getPrototypeOf(o), valid, + 'skip own properties' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/target-is-not-object-throws.js new file mode 100644 index 0000000000..7339dcea9e --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/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.8 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.8 Reflect.getPrototypeOf ( target ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(1); +}); + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(null); +}); + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(undefined); +}); + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/target-is-symbol-throws.js new file mode 100644 index 0000000000..7cb8466bb9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/getPrototypeOf/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.8 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.8 Reflect.getPrototypeOf ( target ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(Symbol(1)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/browser.js b/js/src/tests/test262/built-ins/Reflect/has/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/has/has.js b/js/src/tests/test262/built-ins/Reflect/has/has.js new file mode 100644 index 0000000000..d0de62ffec --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/has.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.9 +description: > + Reflect.has is configurable, writable and not enumerable. +info: | + 26.1.9 Reflect.has ( target, propertyKey ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'has'); +verifyWritable(Reflect, 'has'); +verifyConfigurable(Reflect, 'has'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/length.js b/js/src/tests/test262/built-ins/Reflect/has/length.js new file mode 100644 index 0000000000..a5a0fc4a0b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/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.9 +description: > + Reflect.has.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.has.length, 2, + 'The value of `Reflect.has.length` is `2`' +); + +verifyNotEnumerable(Reflect.has, 'length'); +verifyNotWritable(Reflect.has, 'length'); +verifyConfigurable(Reflect.has, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/name.js b/js/src/tests/test262/built-ins/Reflect/has/name.js new file mode 100644 index 0000000000..62e68d8983 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/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.9 +description: > + Reflect.has.name value and property descriptor +info: | + 26.1.9 Reflect.has ( target, propertyKey ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.has.name, 'has', + 'The value of `Reflect.has.name` is `"has"`' +); + +verifyNotEnumerable(Reflect.has, 'name'); +verifyNotWritable(Reflect.has, 'name'); +verifyConfigurable(Reflect.has, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/has/not-a-constructor.js new file mode 100644 index 0000000000..714c8ef861 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.has 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.has), false, 'isConstructor(Reflect.has) must return false'); + +assert.throws(TypeError, () => { + new Reflect.has(); +}, '`new Reflect.has()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/return-abrupt-from-property-key.js b/js/src/tests/test262/built-ins/Reflect/has/return-abrupt-from-property-key.js new file mode 100644 index 0000000000..70d1f66c89 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/return-abrupt-from-property-key.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: 26.1.9 +description: > + Return abrupt from ToPropertyKey(propertyKey) +info: | + 26.1.9 Reflect.has ( target, propertyKey ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + 3. ReturnIfAbrupt(key). + ... +features: [Reflect] +---*/ + +var p = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Reflect.has({}, p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/has/return-abrupt-from-result.js new file mode 100644 index 0000000000..600b2072f8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/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.9 +description: > + Return abrupt result. +info: | + 26.1.9 Reflect.has ( target, propertyKey ) + + ... + 4. Return target.[[HasProperty]](key). +features: [Proxy, Reflect] +---*/ + +var o = {}; +var p = new Proxy(o, { + has: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.has(p, 'p1'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/return-boolean.js b/js/src/tests/test262/built-ins/Reflect/has/return-boolean.js new file mode 100644 index 0000000000..b051ae2b8f --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/return-boolean.js @@ -0,0 +1,42 @@ +// 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.9 +description: > + Return boolean value. +info: | + 26.1.9 Reflect.has ( target, propertyKey ) + + ... + 4. Return target.[[HasProperty]](key). + + + 9.1.7.1 OrdinaryHasProperty (O, P) + + ... + 2. Let hasOwn be OrdinaryGetOwnProperty(O, P). + 3. If hasOwn is not undefined, return true. + 4. Let parent be O.[[GetPrototypeOf]](). + 5. ReturnIfAbrupt(parent). + 6. If parent is not null, then + a. Return parent.[[HasProperty]](P). + 7. Return false. +features: [Reflect] +---*/ + +var o1 = { + p: 42 +}; + +assert.sameValue(Reflect.has(o1, 'p'), true, 'true from own property'); +assert.sameValue( + Reflect.has(o1, 'z'), false, + 'false when property is not present' +); + +var o2 = Object.create({ + p: 42 +}); +assert.sameValue(Reflect.has(o2, 'p'), true, 'true from a prototype property'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/shell.js b/js/src/tests/test262/built-ins/Reflect/has/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/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/has/symbol-property.js b/js/src/tests/test262/built-ins/Reflect/has/symbol-property.js new file mode 100644 index 0000000000..49754ec000 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/symbol-property.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: 26.1.9 +description: > + Return boolean value from a projectKey as a Symbol +info: | + 26.1.9 Reflect.has ( target, propertyKey ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + ... + + 7.1.14 ToPropertyKey ( argument ) + + ... + 3. If Type(key) is Symbol, then + a. Return key. + ... +features: [Reflect, Symbol] +---*/ + +var o = {}; +var s1 = Symbol('1'); +o[s1] = 42; + +var s2 = Symbol('1'); + + +assert.sameValue(Reflect.has(o, s1), true, 'true from own property'); +assert.sameValue( + Reflect.has(o, s2), false, + 'false when property is not present' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/has/target-is-not-object-throws.js new file mode 100644 index 0000000000..e0c87d8708 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/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.9 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.9 Reflect.has ( target, propertyKey ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.has(1, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.has(null, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.has(undefined, 'p'); +}); + +assert.throws(TypeError, function() { + Reflect.has('', 'p'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/has/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/has/target-is-symbol-throws.js new file mode 100644 index 0000000000..8529334f18 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/has/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.9 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.9 Reflect.has ( target, propertyKey ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.has(Symbol(1), 'p'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/isExtensible/browser.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/isExtensible/isExtensible.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/isExtensible.js new file mode 100644 index 0000000000..1e5587696b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/isExtensible.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.10 +description: > + Reflect.isExtensible is configurable, writable and not enumerable. +info: | + 26.1.10 Reflect.isExtensible (target) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'isExtensible'); +verifyWritable(Reflect, 'isExtensible'); +verifyConfigurable(Reflect, 'isExtensible'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/isExtensible/length.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/length.js new file mode 100644 index 0000000000..31dd4d802a --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/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.10 +description: > + Reflect.isExtensible.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.isExtensible.length, 1, + 'The value of `Reflect.isExtensible.length` is `1`' +); + +verifyNotEnumerable(Reflect.isExtensible, 'length'); +verifyNotWritable(Reflect.isExtensible, 'length'); +verifyConfigurable(Reflect.isExtensible, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/isExtensible/name.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/name.js new file mode 100644 index 0000000000..04ba531667 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/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.10 +description: > + Reflect.isExtensible.name value and property descriptor +info: | + 26.1.10 Reflect.isExtensible (target) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.isExtensible.name, 'isExtensible', + 'The value of `Reflect.isExtensible.name` is `"isExtensible"`' +); + +verifyNotEnumerable(Reflect.isExtensible, 'name'); +verifyNotWritable(Reflect.isExtensible, 'name'); +verifyConfigurable(Reflect.isExtensible, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/isExtensible/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/not-a-constructor.js new file mode 100644 index 0000000000..e45a445b84 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.isExtensible 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.isExtensible), false, 'isConstructor(Reflect.isExtensible) must return false'); + +assert.throws(TypeError, () => { + new Reflect.isExtensible({}); +}, '`new Reflect.isExtensible({})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/isExtensible/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/return-abrupt-from-result.js new file mode 100644 index 0000000000..0928e57d07 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/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.10 +description: > + Return abrupt result. +info: | + 26.1.10 Reflect.isExtensible (target) + + ... + 2. Return target.[[IsExtensible]](). +features: [Proxy, Reflect] +---*/ + +var o1 = {}; +var p = new Proxy(o1, { + isExtensible: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.isExtensible(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/isExtensible/return-boolean.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/return-boolean.js new file mode 100644 index 0000000000..fbf4df41c9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/return-boolean.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: 26.1.10 +description: > + Returns the boolean result. +info: | + 26.1.10 Reflect.isExtensible (target) + + ... + 2. Return target.[[IsExtensible]](). +features: [Reflect] +---*/ + +var o = {}; +assert.sameValue(Reflect.isExtensible(o), true); + +Object.preventExtensions(o); +assert.sameValue(Reflect.isExtensible(o), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/isExtensible/shell.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/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/isExtensible/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/target-is-not-object-throws.js new file mode 100644 index 0000000000..dfe224d4ef --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/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.10 Reflect.isExtensible (target) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.isExtensible(1); +}); + +assert.throws(TypeError, function() { + Reflect.isExtensible(null); +}); + +assert.throws(TypeError, function() { + Reflect.isExtensible(undefined); +}); + +assert.throws(TypeError, function() { + Reflect.isExtensible(''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/isExtensible/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/isExtensible/target-is-symbol-throws.js new file mode 100644 index 0000000000..4fdb837c23 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/isExtensible/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); diff --git a/js/src/tests/test262/built-ins/Reflect/object-prototype.js b/js/src/tests/test262/built-ins/Reflect/object-prototype.js new file mode 100644 index 0000000000..46a3dfafd0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/object-prototype.js @@ -0,0 +1,17 @@ +// 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 +description: > + The value of the [[Prototype]] internal slot of the Reflect object + is the intrinsic object %ObjectPrototype% (19.1.3). +features: [Reflect] +---*/ + +assert.sameValue( + Object.getPrototypeOf(Reflect), + Object.prototype, + '`Object.getPrototypeOf(Reflect)` returns `Object.prototype`' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/browser.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/length.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/length.js new file mode 100644 index 0000000000..7f84f0b49a --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/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.11 +description: > + Reflect.ownKeys.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.ownKeys.length, 1, + 'The value of `Reflect.ownKeys.length` is `1`' +); + +verifyNotEnumerable(Reflect.ownKeys, 'length'); +verifyNotWritable(Reflect.ownKeys, 'length'); +verifyConfigurable(Reflect.ownKeys, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/name.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/name.js new file mode 100644 index 0000000000..77a757dfc5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/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.11 +description: > + Reflect.ownKeys.name value and property descriptor +info: | + 26.1.11 Reflect.ownKeys ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.ownKeys.name, 'ownKeys', + 'The value of `Reflect.ownKeys.name` is `"ownKeys"`' +); + +verifyNotEnumerable(Reflect.ownKeys, 'name'); +verifyNotWritable(Reflect.ownKeys, 'name'); +verifyConfigurable(Reflect.ownKeys, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/not-a-constructor.js new file mode 100644 index 0000000000..9419d7cdd5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.ownKeys 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.ownKeys), false, 'isConstructor(Reflect.ownKeys) must return false'); + +assert.throws(TypeError, () => { + new Reflect.ownKeys({}); +}, '`new Reflect.ownKeys({})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/order-after-define-property.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/order-after-define-property.js new file mode 100644 index 0000000000..3d19d6e760 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/order-after-define-property.js @@ -0,0 +1,52 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-reflect.ownkeys +description: > + Property names are returned in ascending chronological order of creation + that is unaffected by [[DefineOwnProperty]]. +info: | + Reflect.ownKeys ( target ) + + [...] + 2. Let keys be ? target.[[OwnPropertyKeys]](). + 3. Return CreateArrayFromList(keys). + + OrdinaryOwnPropertyKeys ( O ) + + [...] + 4. For each own property key P of O that is a Symbol, in ascending + chronological order of property creation, do + a. Add P as the last element of keys. + 5. Return keys. + + [[OwnPropertyKeys]] ( ) + + [...] + 7. For each own property key P of O such that Type(P) is String and P is not + an array index, in ascending chronological order of property creation, do + a. Add P as the last element of keys. + [...] + 9. Return keys. +features: [Symbol, Reflect] +includes: [compareArray.js] +---*/ + +var obj = {}; +var symA = Symbol("a"); +var symB = Symbol("b"); +obj[symA] = 1; +obj[symB] = 2; +Object.defineProperty(obj, symA, {configurable: false}); +assert.compareArray(Reflect.ownKeys(obj), [symA, symB]); + +var str = new String(""); +str.a = 1; +str.b = 2; +Object.defineProperty(str, "a", { + get: function() {}, +}); +assert.compareArray(Reflect.ownKeys(str), ["length", "a", "b"]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/ownKeys.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/ownKeys.js new file mode 100644 index 0000000000..e647a73392 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/ownKeys.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.11 +description: > + Reflect.ownKeys is configurable, writable and not enumerable. +info: | + 26.1.11 Reflect.ownKeys ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'ownKeys'); +verifyWritable(Reflect, 'ownKeys'); +verifyConfigurable(Reflect, 'ownKeys'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-abrupt-from-result.js new file mode 100644 index 0000000000..1f289fc732 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-abrupt-from-result.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: 26.1.11 +description: > + Return abrupt result from target.[[OwnPropertyKeys]]() +info: | + 26.1.11 Reflect.ownKeys ( target ) + + ... + 2. Let keys be target.[[OwnPropertyKeys]](). + 3. ReturnIfAbrupt(keys). + ... +features: [Proxy, Reflect] +---*/ + +var o = {}; +var p = new Proxy(o, { + ownKeys: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.ownKeys(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/return-array-with-own-keys-only.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-array-with-own-keys-only.js new file mode 100644 index 0000000000..1d23fd7b32 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-array-with-own-keys-only.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: 26.1.11 +description: > + Returns target's own property keys only, ignore prototype keys. +info: | + 26.1.11 Reflect.ownKeys ( target ) + + ... + 2. Let keys be target.[[OwnPropertyKeys]](). + 3. ReturnIfAbrupt(keys). + 4. Return CreateArrayFromList(keys). +includes: [compareArray.js] +features: [Reflect] +---*/ + +var proto = { + foo: 1 +}; + +var o = Object.create(proto); +o.p1 = 42; +o.p2 = 43; +o.p3 = 44; +assert.compareArray(Reflect.ownKeys(o), ['p1', 'p2', 'p3'], 'return object own keys'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/return-empty-array.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-empty-array.js new file mode 100644 index 0000000000..a43aadca9e --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-empty-array.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.11 +description: > + Returns empty array when target has no own properties. +info: | + 26.1.11 Reflect.ownKeys ( target ) + + ... + 2. Let keys be target.[[OwnPropertyKeys]](). + 3. ReturnIfAbrupt(keys). + 4. Return CreateArrayFromList(keys). +includes: [compareArray.js] +features: [Reflect] +---*/ + +assert.compareArray(Reflect.ownKeys({}), []); + +var o = { + d: 42 +}; +delete o.d; +assert.compareArray(Reflect.ownKeys(o), []); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/return-non-enumerable-keys.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-non-enumerable-keys.js new file mode 100644 index 0000000000..10c4ee2d70 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-non-enumerable-keys.js @@ -0,0 +1,38 @@ +// 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.11 +description: > + Returns target's own non enumerable property keys. +info: | + 26.1.11 Reflect.ownKeys ( target ) + + ... + 2. Let keys be target.[[OwnPropertyKeys]](). + 3. ReturnIfAbrupt(keys). + 4. Return CreateArrayFromList(keys). +includes: [compareArray.js] +features: [Reflect] +---*/ + +assert.compareArray( + Reflect.ownKeys([]), + ['length'], + 'return non enumerable `length` from empty array' +); + +assert.compareArray(Reflect.ownKeys([, , 2]), ['2', 'length'], 'return array keys'); + +var o = {}; +Object.defineProperty(o, 'p1', { + value: 42, + enumerable: false +}); +Object.defineProperty(o, 'p2', { + get: function() {}, + enumerable: false +}); + +assert.compareArray(Reflect.ownKeys(o), ['p1', 'p2']); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/return-on-corresponding-order-large-index.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-on-corresponding-order-large-index.js new file mode 100644 index 0000000000..70ea65de92 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-on-corresponding-order-large-index.js @@ -0,0 +1,82 @@ +// Copyright (C) 2018 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-ordinaryownpropertykeys +description: > + Returns keys in their corresponding order. +info: | + 26.1.11 Reflect.ownKeys ( target ) + + ... + 2. Let keys be target.[[OwnPropertyKeys]](). + 3. ReturnIfAbrupt(keys). + 4. Return CreateArrayFromList(keys). + + 9.1.12 [[OwnPropertyKeys]] ( ) + + 1. Let keys be a new empty List. + 2. For each own property key P of O that is an array index, in ascending + numeric index order + a. Add P as the last element of keys. + 3. For each own property key P of O that is a String but is not an array + index, in property creation order + a. Add P as the last element of keys. + 4. For each own property key P of O that is a Symbol, in property creation + order + a. Add P as the last element of keys. + 5. Return keys. +features: [computed-property-names, Reflect, Symbol] +---*/ + +var o1 = { + 12345678900: true, + b: true, + 1: true, + a: true, + [Number.MAX_SAFE_INTEGER]: true, + [Symbol.for('z')]: true, + 12345678901: true, + 4294967294: true, + 4294967295: true, +}; + +var result = Reflect.ownKeys(o1); + +assert.sameValue(result.length, 9); +assert.sameValue(result[0], '1'); +assert.sameValue(result[1], '4294967294'); +assert.sameValue(result[2], '12345678900'); +assert.sameValue(result[3], 'b'); +assert.sameValue(result[4], 'a'); +assert.sameValue(result[5], String(Number.MAX_SAFE_INTEGER)); +assert.sameValue(result[6], '12345678901'); +assert.sameValue(result[7], '4294967295'); +assert.sameValue(result[8], Symbol.for('z')); + +var o2 = {}; + +o2[12345678900] = true; +o2.b = true; +o2[1] = true; +o2.a = true; +o2[Number.MAX_SAFE_INTEGER] = true; +o2[Symbol.for('z')] = true; +o2[12345678901] = true; +o2[4294967294] = true; +o2[4294967295] = true; + + +result = Reflect.ownKeys(o2); + +assert.sameValue(result.length, 9); +assert.sameValue(result[0], '1'); +assert.sameValue(result[1], '4294967294'); +assert.sameValue(result[2], '12345678900'); +assert.sameValue(result[3], 'b'); +assert.sameValue(result[4], 'a'); +assert.sameValue(result[5], String(Number.MAX_SAFE_INTEGER)); +assert.sameValue(result[6], '12345678901'); +assert.sameValue(result[7], '4294967295'); +assert.sameValue(result[8], Symbol.for('z')); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/return-on-corresponding-order.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-on-corresponding-order.js new file mode 100644 index 0000000000..5285fcf35a --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/return-on-corresponding-order.js @@ -0,0 +1,56 @@ +// 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.11 +description: > + Returns keys in their corresponding order. +info: | + 26.1.11 Reflect.ownKeys ( target ) + + ... + 2. Let keys be target.[[OwnPropertyKeys]](). + 3. ReturnIfAbrupt(keys). + 4. Return CreateArrayFromList(keys). + + 9.1.12 [[OwnPropertyKeys]] ( ) + + 1. Let keys be a new empty List. + 2. For each own property key P of O that is an integer index, in ascending + numeric index order + a. Add P as the last element of keys. + 3. For each own property key P of O that is a String but is not an integer + index, in property creation order + a. Add P as the last element of keys. + 4. For each own property key P of O that is a Symbol, in property creation + order + a. Add P as the last element of keys. + 5. Return keys. +features: [Reflect, Symbol] +---*/ + + +var o = {}; +o.p1 = 42; +o.p2 = 43; + +var s1 = Symbol('1'); +var s2 = Symbol('a'); +o[s1] = 44; +o[s2] = 45; + +o[2] = 46; +o[0] = 47; +o[1] = 48; + +var result = Reflect.ownKeys(o); + +assert.sameValue(result.length, 7); +assert.sameValue(result[0], '0'); +assert.sameValue(result[1], '1'); +assert.sameValue(result[2], '2'); +assert.sameValue(result[3], 'p1'); +assert.sameValue(result[4], 'p2'); +assert.sameValue(result[5], s1); +assert.sameValue(result[6], s2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/shell.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/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/ownKeys/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/target-is-not-object-throws.js new file mode 100644 index 0000000000..f894d475df --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/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.11 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.11 Reflect.ownKeys ( target ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.ownKeys(1); +}); + +assert.throws(TypeError, function() { + Reflect.ownKeys(null); +}); + +assert.throws(TypeError, function() { + Reflect.ownKeys(undefined); +}); + +assert.throws(TypeError, function() { + Reflect.ownKeys(''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/ownKeys/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/ownKeys/target-is-symbol-throws.js new file mode 100644 index 0000000000..b033e21e08 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/ownKeys/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.11 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.11 Reflect.ownKeys ( target ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.ownKeys(Symbol(1)); +}); + +reportCompare(0, 0); 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); diff --git a/js/src/tests/test262/built-ins/Reflect/prop-desc.js b/js/src/tests/test262/built-ins/Reflect/prop-desc.js new file mode 100644 index 0000000000..ea2160b3d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/prop-desc.js @@ -0,0 +1,43 @@ +// 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-reflect-object +description: > + Property descriptor of Reflect +info: | + The Reflect Object + + ... + The Reflect object does not have a [[Construct]] internal method; + it is not possible to use the Reflect object as a constructor with the new operator. + + The Reflect object does not have a [[Call]] internal method; + it is not possible to invoke the Reflect object as a function. + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue(typeof Reflect, "object"); + +assert.throws(TypeError, function() { + Reflect(); +}, "no [[Call]]"); + +assert.throws(TypeError, function() { + new Reflect(); +}, "no [[Construct]]"); + +verifyProperty(this, "Reflect", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/browser.js b/js/src/tests/test262/built-ins/Reflect/set/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/set/call-prototype-property-set.js b/js/src/tests/test262/built-ins/Reflect/set/call-prototype-property-set.js new file mode 100644 index 0000000000..39f11387f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/call-prototype-property-set.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.13 +description: > + Call accessor's set from target's prototype. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 4. If ownDesc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is not null, then + i. Return parent.[[Set]](P, V, Receiver). + ... + 11. Return true. +features: [Reflect, Reflect.set] +---*/ + +var args; +var count = 0; +var _this; +var proto = {}; +Object.defineProperty(proto, 'p', { + set: function() { + _this = this; + args = arguments; + count++; + } +}); + +var target = Object.create(proto); +var result = Reflect.set(target, 'p', 42); +assert.sameValue(result, true, 'returns true'); +assert.sameValue(args.length, 1, 'prototype `set` called with 1 argument'); +assert.sameValue(args[0], 42, 'prototype `set` called with 42'); +assert.sameValue(_this, target, 'prototype `set` called with target as `this`'); +assert.sameValue(count, 1, 'prototype `set` called once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/creates-a-data-descriptor.js b/js/src/tests/test262/built-ins/Reflect/set/creates-a-data-descriptor.js new file mode 100644 index 0000000000..10a80f2dcf --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/creates-a-data-descriptor.js @@ -0,0 +1,80 @@ +// 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.13 +description: > + Creates a property data descriptor. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 4. If ownDesc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is not null, then + i. Return parent.[[Set]](P, V, Receiver). + d. Else, + ii. Let ownDesc be the PropertyDescriptor{[[Value]]: undefined, + [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}. + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + c. Let existingDescriptor be Receiver.[[GetOwnProperty]](P). + d. ReturnIfAbrupt(existingDescriptor). + e. If existingDescriptor is not undefined, then + i. If IsAccessorDescriptor(existingDescriptor) is true, return false. + ii. If existingDescriptor.[[Writable]] is false, return false. + iii. Let valueDesc be the PropertyDescriptor{[[Value]]: V}. + iv. Return Receiver.[[DefineOwnProperty]](P, valueDesc). + f. Else Receiver does not currently have a property P, + i. Return CreateDataProperty(Receiver, P, V). + 6. Assert: IsAccessorDescriptor(ownDesc) is true. + 7. Let setter be ownDesc.[[Set]]. + 8. If setter is undefined, return false. + ... + 11. Return true. +includes: [propertyHelper.js] +features: [Reflect, Reflect.set] +---*/ + +var o1 = {}; +var result = Reflect.set(o1, 'p', 42); +assert.sameValue(result, true, 'returns true on a successful setting'); +var desc = Object.getOwnPropertyDescriptor(o1, 'p'); +assert.sameValue( + desc.value, 42, + 'sets a data descriptor to set a new property' +); +verifyWritable(o1, 'p'); +verifyEnumerable(o1, 'p'); +verifyConfigurable(o1, 'p'); + +var o2 = {}; +var receiver = {}; +result = Reflect.set(o2, 'p', 43, receiver); +assert.sameValue( + result, true, + 'returns true on a successful setting with a receiver' +); +desc = Object.getOwnPropertyDescriptor(o2, 'p'); +assert.sameValue( + desc, undefined, + 'does not set a data descriptor on target if receiver is given' +); +desc = Object.getOwnPropertyDescriptor(receiver, 'p'); +assert.sameValue( + desc.value, 43, + 'sets a data descriptor on the receiver object to set a new property' +); +verifyWritable(receiver, 'p'); +verifyEnumerable(receiver, 'p'); +verifyConfigurable(receiver, 'p'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/different-property-descriptors.js b/js/src/tests/test262/built-ins/Reflect/set/different-property-descriptors.js new file mode 100644 index 0000000000..1c70154f08 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/different-property-descriptors.js @@ -0,0 +1,70 @@ +// 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.13 +description: > + Return false if target property turns to a data descriptor and receiver + property is an accessor descriptor. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 4. If ownDesc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is not null, then + i. Return parent.[[Set]](P, V, Receiver). + d. Else, + ii. Let ownDesc be the PropertyDescriptor{[[Value]]: undefined, + [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}. + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + c. Let existingDescriptor be Receiver.[[GetOwnProperty]](P). + d. ReturnIfAbrupt(existingDescriptor). + e. If existingDescriptor is not undefined, then + i. If IsAccessorDescriptor(existingDescriptor) is true, return false. + ... +features: [Reflect, Reflect.set] +---*/ + +var receiver = {}; +var fn = function() {}; +Object.defineProperty(receiver, 'p', { + set: fn +}); + +var o1 = {}; +var result = Reflect.set(o1, 'p', 42, receiver); +assert.sameValue( + result, false, + 'target has no own `p` and receiver.p has an accessor descriptor' +); +assert.sameValue( + Object.getOwnPropertyDescriptor(receiver, 'p').set, fn, + 'receiver.p is not changed' +); +assert.sameValue(o1.hasOwnProperty('p'), false, 'target.p is not set'); + +var o2 = { + p: 43 +}; +result = Reflect.set(o2, 'p', 42, receiver); +assert.sameValue( + result, false, + 'target.p has a data descriptor and receiver.p has an accessor descriptor' +); +assert.sameValue( + Object.getOwnPropertyDescriptor(receiver, 'p').set, fn, + 'receiver.p is not changed' +); +assert.sameValue(o2.p, 43, 'target.p is not changed'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/length.js b/js/src/tests/test262/built-ins/Reflect/set/length.js new file mode 100644 index 0000000000..e8e0d537c7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/length.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: 26.1.13 +description: > + Reflect.set.length value and property descriptor +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + The length property of the set function is 3. +includes: [propertyHelper.js] +features: [Reflect, Reflect.set] +---*/ + +assert.sameValue( + Reflect.set.length, 3, + 'The value of `Reflect.set.length` is `3`' +); + +verifyNotEnumerable(Reflect.set, 'length'); +verifyNotWritable(Reflect.set, 'length'); +verifyConfigurable(Reflect.set, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/name.js b/js/src/tests/test262/built-ins/Reflect/set/name.js new file mode 100644 index 0000000000..999e652586 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/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.13 +description: > + Reflect.set.name value and property descriptor +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect, Reflect.set] +---*/ + +assert.sameValue( + Reflect.set.name, 'set', + 'The value of `Reflect.set.name` is `"set"`' +); + +verifyNotEnumerable(Reflect.set, 'name'); +verifyNotWritable(Reflect.set, 'name'); +verifyConfigurable(Reflect.set, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/set/not-a-constructor.js new file mode 100644 index 0000000000..c632ce534f --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.set 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, Reflect.set, arrow-function] +---*/ + +assert.sameValue(isConstructor(Reflect.set), false, 'isConstructor(Reflect.set) must return false'); + +assert.throws(TypeError, () => { + new Reflect.set({}); +}, '`new Reflect.set({})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/receiver-is-not-object.js b/js/src/tests/test262/built-ins/Reflect/set/receiver-is-not-object.js new file mode 100644 index 0000000000..30f2436869 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/receiver-is-not-object.js @@ -0,0 +1,46 @@ +// 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.13 +description: > + Return false if receiver is not an object. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 4. If ownDesc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is not null, then + i. Return parent.[[Set]](P, V, Receiver). + d. Else, + ii. Let ownDesc be the PropertyDescriptor{[[Value]]: undefined, + [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}. + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + ... +features: [Reflect, Reflect.set] +---*/ + +var o1 = { + p: 42 +}; +var receiver = 'receiver is a string'; +var result = Reflect.set(o1, 'p', 43, receiver); + +assert.sameValue(result, false, 'returns false'); +assert.sameValue(o1.p, 42, 'does not set a value'); +assert.sameValue( + receiver.hasOwnProperty('p'), false, + 'does not set a new property on receiver if it is not an object' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/return-abrupt-from-property-key.js b/js/src/tests/test262/built-ins/Reflect/set/return-abrupt-from-property-key.js new file mode 100644 index 0000000000..72712d21a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/return-abrupt-from-property-key.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: 26.1.13 +description: > + Return abrupt from ToPropertyKey(propertyKey) +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + 3. ReturnIfAbrupt(key). + ... +features: [Reflect, Reflect.set] +---*/ + +var p = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Reflect.set({}, p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/set/return-abrupt-from-result.js new file mode 100644 index 0000000000..f44011c5de --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/return-abrupt-from-result.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: 26.1.13 +description: > + Return abrupt result from get a property value. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 5. Return target.[[Set]](key, V, receiver). +features: [Reflect, Reflect.set] +---*/ + +var o1 = {}; +Object.defineProperty(o1, 'p1', { + set: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.set(o1, 'p1', 42); +}); + +// Abrupt from the prototype property +var o2 = Object.create(o1); +assert.throws(Test262Error, function() { + Reflect.set(o2, 'p1', 42); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/return-false-if-receiver-is-not-writable.js b/js/src/tests/test262/built-ins/Reflect/set/return-false-if-receiver-is-not-writable.js new file mode 100644 index 0000000000..34a9fdd7b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/return-false-if-receiver-is-not-writable.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: 26.1.13 +description: > + Return false if receiver is not writable. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + ... +features: [Reflect, Reflect.set] +---*/ + +var o1 = {}; + +Object.defineProperty(o1, 'p', { + writable: false, + value: 42 +}); +var result = Reflect.set(o1, 'p', 43); +assert.sameValue(result, false, 'returns false'); +assert.sameValue(o1.p, 42, 'does not set a new value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/return-false-if-target-is-not-writable.js b/js/src/tests/test262/built-ins/Reflect/set/return-false-if-target-is-not-writable.js new file mode 100644 index 0000000000..19a0a5ef24 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/return-false-if-target-is-not-writable.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: 26.1.13 +description: > + Return false if target is not writable. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + c. Let existingDescriptor be Receiver.[[GetOwnProperty]](P). + d. ReturnIfAbrupt(existingDescriptor). + e. If existingDescriptor is not undefined, then + i. If IsAccessorDescriptor(existingDescriptor) is true, return false. + ii. If existingDescriptor.[[Writable]] is false, return false. + ... +features: [Reflect, Reflect.set] +---*/ + +var o1 = {}; +var receiver = {}; +Object.defineProperty(receiver, 'p', { + writable: false, + value: 42 +}); +var result = Reflect.set(o1, 'p', 43, receiver); +assert.sameValue(result, false, 'returns false'); +assert.sameValue(receiver.p, 42, 'does not set a new value on receiver'); +assert.sameValue( + o1.hasOwnProperty('p'), false, + 'does not set a new value on target' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/set-value-on-accessor-descriptor-with-receiver.js b/js/src/tests/test262/built-ins/Reflect/set/set-value-on-accessor-descriptor-with-receiver.js new file mode 100644 index 0000000000..42d36f4964 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/set-value-on-accessor-descriptor-with-receiver.js @@ -0,0 +1,54 @@ +// 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.13 +description: > + Set value on an accessor descriptor property with receiver as `this`. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 6. Assert: IsAccessorDescriptor(ownDesc) is true. + 7. Let setter be ownDesc.[[Set]]. + 8. If setter is undefined, return false. + 9. Let setterResult be Call(setter, Receiver, «V»). + 10. ReturnIfAbrupt(setterResult). + 11. Return true. +features: [Reflect, Reflect.set] +---*/ + +var args; +var count = 0 +var o1 = {}; +var receiver = {}; +var _receiver; +Object.defineProperty(o1, 'p', { + set: function(a) { + count++; + args = arguments; + _receiver = this; + return false; + } +}); + +var result = Reflect.set(o1, 'p', 42, receiver); +assert.sameValue( + result, true, + 'returns true if target.p has an accessor descriptor' +); +assert.sameValue(args.length, 1, 'target.p set is called with 1 argument'); +assert.sameValue(args[0], 42, 'target.p set is called with V'); +assert.sameValue(count, 1, 'target.p set is called once'); +assert.sameValue( + _receiver, receiver, + 'target.p set is called with receiver as `this`' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/set-value-on-accessor-descriptor.js b/js/src/tests/test262/built-ins/Reflect/set/set-value-on-accessor-descriptor.js new file mode 100644 index 0000000000..63fe98d832 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/set-value-on-accessor-descriptor.js @@ -0,0 +1,47 @@ +// 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.13 +description: > + Set value on an accessor descriptor property. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 6. Assert: IsAccessorDescriptor(ownDesc) is true. + 7. Let setter be ownDesc.[[Set]]. + 8. If setter is undefined, return false. + 9. Let setterResult be Call(setter, Receiver, «V»). + 10. ReturnIfAbrupt(setterResult). + 11. Return true. +features: [Reflect, Reflect.set] +---*/ + +var args; +var count = 0 +var o1 = {}; +Object.defineProperty(o1, 'p', { + set: function(a) { + count++; + args = arguments; + return false; + } +}); + +var result = Reflect.set(o1, 'p', 42); +assert.sameValue( + result, true, + 'returns true if target.p has an accessor descriptor' +); +assert.sameValue(args.length, 1, 'target.p set is called with 1 argument'); +assert.sameValue(args[0], 42, 'target.p set is called with V'); +assert.sameValue(count, 1, 'target.p set is called once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/set-value-on-data-descriptor.js b/js/src/tests/test262/built-ins/Reflect/set/set-value-on-data-descriptor.js new file mode 100644 index 0000000000..4ad03c926b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/set-value-on-data-descriptor.js @@ -0,0 +1,55 @@ +// 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.13 +description: > + Sets the new value. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + c. Let existingDescriptor be Receiver.[[GetOwnProperty]](P). + d. ReturnIfAbrupt(existingDescriptor). + e. If existingDescriptor is not undefined, then + i. If IsAccessorDescriptor(existingDescriptor) is true, return false. + ii. If existingDescriptor.[[Writable]] is false, return false. + iii. Let valueDesc be the PropertyDescriptor{[[Value]]: V}. + iv. Return Receiver.[[DefineOwnProperty]](P, valueDesc). + f. Else Receiver does not currently have a property P, + i. Return CreateDataProperty(Receiver, P, V). + ... +features: [Reflect, Reflect.set] +---*/ + +var o1 = { + p: 43 +}; +var result = Reflect.set(o1, 'p', 42); +assert.sameValue(result, true, 'returns true on a successful setting'); +assert.sameValue( + o1.p, 42, + 'sets the new value' +); + +var o2 = { + p: 43 +}; +var receiver = { + p: 44 +}; +var result = Reflect.set(o2, 'p', 42, receiver); +assert.sameValue(result, true, 'returns true on a successful setting'); +assert.sameValue(o2.p, 43, 'with a receiver, does not set a value on target'); +assert.sameValue(receiver.p, 42, 'sets the new value on the receiver'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/set.js b/js/src/tests/test262/built-ins/Reflect/set/set.js new file mode 100644 index 0000000000..8f7428b27f --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/set.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.13 +description: > + Reflect.set is configurable, writable and not enumerable. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'set'); +verifyWritable(Reflect, 'set'); +verifyConfigurable(Reflect, 'set'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/shell.js b/js/src/tests/test262/built-ins/Reflect/set/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/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/set/symbol-property.js b/js/src/tests/test262/built-ins/Reflect/set/symbol-property.js new file mode 100644 index 0000000000..d6a5857ce7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/symbol-property.js @@ -0,0 +1,38 @@ +// 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.13 +description: > + Sets the new value. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + ... + + 7.1.14 ToPropertyKey ( argument ) + + ... + 3. If Type(key) is Symbol, then + a. Return key. + ... +features: [Reflect, Reflect.set, Symbol] +---*/ + +var o1 = {}; +var s = Symbol('1'); +var result = Reflect.set(o1, s, 42); +assert.sameValue(result, true, 'returns true on a successful setting'); +assert.sameValue(o1[s], 42, 'sets the new value'); + +var o2 = {}; +o2[s] = 43; +var receiver = {}; +receiver[s] = 44; +var result = Reflect.set(o2, s, 42, receiver); +assert.sameValue(result, true, 'returns true on a successful setting'); +assert.sameValue(o2[s], 43, 'with a receiver, does not set a value on target'); +assert.sameValue(receiver[s], 42, 'sets the new value on the receiver'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/set/target-is-not-object-throws.js new file mode 100644 index 0000000000..21018943ff --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/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.13 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Reflect.set] +---*/ + +assert.throws(TypeError, function() { + Reflect.set(1, 'p', 42); +}); + +assert.throws(TypeError, function() { + Reflect.set(null, 'p', 42); +}); + +assert.throws(TypeError, function() { + Reflect.set(undefined, 'p', 42); +}); + +assert.throws(TypeError, function() { + Reflect.set('', 'p', 42); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/set/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/set/target-is-symbol-throws.js new file mode 100644 index 0000000000..b4bba97e83 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/set/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.13 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Reflect.set, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.set(Symbol(1), 'p', 42); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/browser.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/length.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/length.js new file mode 100644 index 0000000000..51e4fff9c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/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.14 +description: > + Reflect.setPrototypeOf.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect, Reflect.setPrototypeOf] +---*/ + +assert.sameValue( + Reflect.setPrototypeOf.length, 2, + 'The value of `Reflect.setPrototypeOf.length` is `2`' +); + +verifyNotEnumerable(Reflect.setPrototypeOf, 'length'); +verifyNotWritable(Reflect.setPrototypeOf, 'length'); +verifyConfigurable(Reflect.setPrototypeOf, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/name.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/name.js new file mode 100644 index 0000000000..bbbca0a855 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/name.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: 26.1.14 +description: > + Reflect.setPrototypeOf.name value and property descriptor +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Reflect, Reflect.setPrototypeOf] +---*/ + +assert.sameValue( + Reflect.setPrototypeOf.name, 'setPrototypeOf', + 'The value of `Reflect.setPrototypeOf.name` is `"setPrototypeOf"`' +); + +verifyNotEnumerable(Reflect.setPrototypeOf, 'name'); +verifyNotWritable(Reflect.setPrototypeOf, 'name'); +verifyConfigurable(Reflect.setPrototypeOf, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/not-a-constructor.js new file mode 100644 index 0000000000..e7e1f90120 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/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.setPrototypeOf 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, Reflect.setPrototypeOf, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Reflect.setPrototypeOf), + false, + 'isConstructor(Reflect.setPrototypeOf) must return false' +); + +assert.throws(TypeError, () => { + new Reflect.setPrototypeOf({}, {}); +}, '`new Reflect.setPrototypeOf({}, {})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/proto-is-not-object-and-not-null-throws.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/proto-is-not-object-and-not-null-throws.js new file mode 100644 index 0000000000..1c6c6e7066 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/proto-is-not-object-and-not-null-throws.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: 26.1.14 +description: > + Throws a TypeError if proto is not Object or proto is not null. +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 2. If Type(proto) is not Object and proto is not null, throw a TypeError + exception + ... +features: [Reflect, Reflect.setPrototypeOf] +---*/ + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, undefined); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, 1); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, 'string'); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/proto-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/proto-is-symbol-throws.js new file mode 100644 index 0000000000..c9a5078753 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/proto-is-symbol-throws.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: 26.1.14 +description: > + Throws a TypeError if proto is a Symbol +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 2. If Type(proto) is not Object and proto is not null, throw a TypeError + exception + ... +features: [Reflect, Reflect.setPrototypeOf, Symbol] +---*/ + +var s = Symbol(1); +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-abrupt-from-result.js new file mode 100644 index 0000000000..fdbeaa7248 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/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.14 +description: > + Return abrupt result. +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). +features: [Proxy, Reflect, Reflect.setPrototypeOf] +---*/ + +var target = {}; +var p = new Proxy(target, { + setPrototypeOf: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.setPrototypeOf(p, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-false-if-target-and-proto-are-the-same.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-false-if-target-and-proto-are-the-same.js new file mode 100644 index 0000000000..f923461c81 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-false-if-target-and-proto-are-the-same.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: 26.1.14 +description: > + Return false if target and proto are the same, without setting a new prototype. +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 8. Repeat while done is false, + a. If p is null, let done be true. + b. Else, if SameValue(p, O) is true, return false. + ... +features: [Reflect, Reflect.setPrototypeOf] +---*/ + +var o1 = {}; +assert.sameValue(Reflect.setPrototypeOf(o1, o1), false); +assert.sameValue(Object.getPrototypeOf(o1), Object.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-not-extensible.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-not-extensible.js new file mode 100644 index 0000000000..e85ec69508 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-not-extensible.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: 26.1.14 +description: > + Return false if target is not extensible, without changing the prototype. +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 5. If extensible is false, return false. + ... +features: [Reflect, Reflect.setPrototypeOf] +---*/ + +var o1 = {}; +Object.preventExtensions(o1); +assert.sameValue(Reflect.setPrototypeOf(o1, {}), false); +assert.sameValue(Object.getPrototypeOf(o1), Object.prototype); + +var o2 = {}; +Object.preventExtensions(o2); +assert.sameValue(Reflect.setPrototypeOf(o2, null), false); +assert.sameValue(Object.getPrototypeOf(o2), Object.prototype); + +var o3 = Object.create(null); +Object.preventExtensions(o3); +assert.sameValue(Reflect.setPrototypeOf(o3, {}), false); +assert.sameValue(Object.getPrototypeOf(o3), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-prototype-of-proto.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-prototype-of-proto.js new file mode 100644 index 0000000000..3b403b187b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-prototype-of-proto.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: 26.1.14 +description: > + Return false if target is found as a prototype of proto, without setting. +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 8. Repeat while done is false, + a. If p is null, let done be true. + b. Else, if SameValue(p, O) is true, return false. + c. Else, + i. If the [[GetPrototypeOf]] internal method of p is not the ordinary + object internal method defined in 9.1.1, let done be true. + ii. Else, let p be the value of p’s [[Prototype]] internal slot. + ... +features: [Reflect, Reflect.setPrototypeOf] +---*/ + +var target = {}; +var proto = Object.create(target); +assert.sameValue(Reflect.setPrototypeOf(target, proto), false); +assert.sameValue(Object.getPrototypeOf(target), Object.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-true-if-new-prototype-is-set.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-true-if-new-prototype-is-set.js new file mode 100644 index 0000000000..e4dc305f5e --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-true-if-new-prototype-is-set.js @@ -0,0 +1,35 @@ +// 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.14 +description: > + Return true if the new prototype is set. +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 9. Set the value of the [[Prototype]] internal slot of O to V. + 10. Return true. + ... +features: [Reflect, Reflect.setPrototypeOf] +---*/ + +var o1 = {}; +assert.sameValue(Reflect.setPrototypeOf(o1, null), true); +assert.sameValue(Object.getPrototypeOf(o1), null); + +var o2 = Object.create(null); +assert.sameValue(Reflect.setPrototypeOf(o2, Object.prototype), true); +assert.sameValue(Object.getPrototypeOf(o2), Object.prototype); + +var o3 = {}; +var proto = {}; +assert.sameValue(Reflect.setPrototypeOf(o3, proto), true); +assert.sameValue(Object.getPrototypeOf(o3), proto); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-true-if-proto-is-current.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-true-if-proto-is-current.js new file mode 100644 index 0000000000..279c270ed9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/return-true-if-proto-is-current.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: 26.1.14 +description: > + Return true if proto has the same value as current target's prototype. +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 4. If SameValue(V, current), return true. + ... +features: [Reflect, Reflect.setPrototypeOf] +---*/ + +var o1 = {}; +Object.preventExtensions(o1); +assert.sameValue(Reflect.setPrototypeOf(o1, Object.prototype), true); + +var o2 = Object.create(null); +Object.preventExtensions(o2); +assert.sameValue(Reflect.setPrototypeOf(o2, null), true); + +var proto = {}; +var o3 = Object.create(proto); +Object.preventExtensions(o3); +assert.sameValue(Reflect.setPrototypeOf(o3, proto), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/setPrototypeOf.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/setPrototypeOf.js new file mode 100644 index 0000000000..d40c716c00 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/setPrototypeOf.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.14 +description: > + Reflect.setPrototypeOf is configurable, writable and not enumerable. +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'setPrototypeOf'); +verifyWritable(Reflect, 'setPrototypeOf'); +verifyConfigurable(Reflect, 'setPrototypeOf'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/shell.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/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/setPrototypeOf/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/target-is-not-object-throws.js new file mode 100644 index 0000000000..5123fee721 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/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.14 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Reflect.setPrototypeOf] +---*/ + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf(1, {}); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf(null, {}); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf(undefined, {}); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf('', {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/target-is-symbol-throws.js new file mode 100644 index 0000000000..9e0c1c6e8f --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/setPrototypeOf/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.14 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Reflect.setPrototypeOf, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf(Symbol(1), {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/shell.js b/js/src/tests/test262/built-ins/Reflect/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/shell.js |