diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Reflect/construct')
12 files changed, 318 insertions, 0 deletions
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); |