diff --git a/test/built-ins/Reflect/construct/arguments-list-is-not-array-like.js b/test/built-ins/Reflect/construct/arguments-list-is-not-array-like.js new file mode 100644 index 0000000000..d378fed935 --- /dev/null +++ b/test/built-ins/Reflect/construct/arguments-list-is-not-array-like.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.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). + ... +---*/ + +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); +}); diff --git a/test/built-ins/Reflect/construct/construct.js b/test/built-ins/Reflect/construct/construct.js new file mode 100644 index 0000000000..e9f1d4388c --- /dev/null +++ b/test/built-ins/Reflect/construct/construct.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.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] +---*/ + +verifyNotEnumerable(Reflect, 'construct'); +verifyWritable(Reflect, 'construct'); +verifyConfigurable(Reflect, 'construct'); diff --git a/test/built-ins/Reflect/construct/length.js b/test/built-ins/Reflect/construct/length.js new file mode 100644 index 0000000000..94c2b63e58 --- /dev/null +++ b/test/built-ins/Reflect/construct/length.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.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] +---*/ + +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'); diff --git a/test/built-ins/Reflect/construct/name.js b/test/built-ins/Reflect/construct/name.js new file mode 100644 index 0000000000..7eefbf5fcd --- /dev/null +++ b/test/built-ins/Reflect/construct/name.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.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] +---*/ + +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'); diff --git a/test/built-ins/Reflect/construct/newtarget-is-not-constructor-throws.js b/test/built-ins/Reflect/construct/newtarget-is-not-constructor-throws.js new file mode 100644 index 0000000000..cce13fcd3a --- /dev/null +++ b/test/built-ins/Reflect/construct/newtarget-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 `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. + ... +---*/ + +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); +}); diff --git a/test/built-ins/Reflect/construct/return-with-newtarget-argument.js b/test/built-ins/Reflect/construct/return-with-newtarget-argument.js new file mode 100644 index 0000000000..6a6f0b2650 --- /dev/null +++ b/test/built-ins/Reflect/construct/return-with-newtarget-argument.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.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). +---*/ + +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); diff --git a/test/built-ins/Reflect/construct/return-without-newtarget-argument.js b/test/built-ins/Reflect/construct/return-without-newtarget-argument.js new file mode 100644 index 0000000000..7b86b796ff --- /dev/null +++ b/test/built-ins/Reflect/construct/return-without-newtarget-argument.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: > + 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). +---*/ + +var o = {}; +function fn() { + this.o = o; +} + +var result = Reflect.construct(fn, []); + +assert.sameValue(result.o, o); +assert(result instanceof fn); diff --git a/test/built-ins/Reflect/construct/target-is-not-constructor-throws.js b/test/built-ins/Reflect/construct/target-is-not-constructor-throws.js new file mode 100644 index 0000000000..18fec82205 --- /dev/null +++ b/test/built-ins/Reflect/construct/target-is-not-constructor-throws.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.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. +---*/ + +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, []); +}); diff --git a/test/built-ins/Reflect/construct/use-arguments-list.js b/test/built-ins/Reflect/construct/use-arguments-list.js new file mode 100644 index 0000000000..c67cd75b63 --- /dev/null +++ b/test/built-ins/Reflect/construct/use-arguments-list.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: > + 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). +---*/ + +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');