diff --git a/test/built-ins/Array/of/Array.of_assignment-to-new-object-length.js b/test/built-ins/Array/of/Array.of_assignment-to-new-object-length.js deleted file mode 100644 index 0f7dea26b9..0000000000 --- a/test/built-ins/Array/of/Array.of_assignment-to-new-object-length.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.2.3 -description: > - The Array.of() method creates a new Array instance - with a variable number of arguments, regardless of - number or type of the arguments. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of -includes: [compareArray.js] ----*/ -function Empty() {} -Empty.of = Array.of; -Object.defineProperty(Empty.prototype, "length", {get: function() { return 0; }}); - -assert.throws(TypeError, function() { Empty.of(); }); diff --git a/test/built-ins/Array/of/Array.of_basics.js b/test/built-ins/Array/of/Array.of_basics.js deleted file mode 100644 index 7f1a2fd876..0000000000 --- a/test/built-ins/Array/of/Array.of_basics.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.2.3 -description: > - The Array.of() method creates a new Array instance - with a variable number of arguments, regardless of - number or type of the arguments. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of -includes: [compareArray.js] ----*/ -var a = Array.of(); -var elem = []; -assert.sameValue(a.length, 0); -a = Array.of(undefined, null, 3.14, elem); - -assert(compareArray(a, [undefined, null, 3.14, elem])); -a = []; -for (var i = 0; i < 1000; i++) { - a[i] = i; -} -assert(compareArray(Array.of.apply(null, a), a)); diff --git a/test/built-ins/Array/of/Array.of_calls-a-length-setter-if-one-is-present.js b/test/built-ins/Array/of/Array.of_calls-a-length-setter-if-one-is-present.js deleted file mode 100644 index 57c19655c5..0000000000 --- a/test/built-ins/Array/of/Array.of_calls-a-length-setter-if-one-is-present.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.2.3 -description: > - The Array.of() method creates a new Array instance - with a variable number of arguments, regardless of - number or type of the arguments. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of -includes: [compareArray.js] ----*/ -var hits = 0; -var lastObj = null, lastVal = undefined; -function setter(v) { - hits++; - lastObj = this; - lastVal = v; -} - -// when the setter is on the new object -function Pack() { - Object.defineProperty(this, "length", {set: setter}); -} -Pack.of = Array.of; -var pack = Pack.of("wolves", "cards", "cigarettes", "lies"); -assert(compareArray(lastObj, pack)); -assert.sameValue(lastVal, 4); - -// when the setter is on the new object's prototype -function Bevy() {} -Object.defineProperty(Bevy.prototype, "length", {set: setter}); -Bevy.of = Array.of; -var bevy = Bevy.of("quail"); -assert(compareArray(lastObj, bevy)); -assert.sameValue(lastVal, 1); diff --git a/test/built-ins/Array/of/Array.of_can-be-transplanted-to-other-classes.js b/test/built-ins/Array/of/Array.of_can-be-transplanted-to-other-classes.js deleted file mode 100644 index 234f8e10a5..0000000000 --- a/test/built-ins/Array/of/Array.of_can-be-transplanted-to-other-classes.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.2.3 -description: > - The Array.of() method creates a new Array instance - with a variable number of arguments, regardless of - number or type of the arguments. - - Array.of can be transplanted to other classes. - - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of -includes: [compareArray.js] ----*/ -var hits = 0; -function Bag() { - hits++; -} -Bag.of = Array.of; - -hits = 0; -var actual = Bag.of("zero", "one"); -assert.sameValue(hits, 1); - -hits = 0; -var expected = new Bag; -expected[0] = "zero"; -expected[1] = "one"; -expected.length = 2; -assert(compareArray(actual, expected)); - -hits = 0; -actual = Array.of.call(Bag, "zero", "one"); -assert.sameValue(hits, 1); -assert(compareArray(actual, expected)); - diff --git a/test/built-ins/Array/of/Array.of_check-superficial-features.js b/test/built-ins/Array/of/Array.of_check-superficial-features.js deleted file mode 100644 index ea8f809840..0000000000 --- a/test/built-ins/Array/of/Array.of_check-superficial-features.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.2.3 -description: > - The Array.of() method creates a new Array instance - with a variable number of arguments, regardless of - number or type of the arguments. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of -includes: [compareArray.js] ----*/ - -// Array.of Check superficial features. - -var desc = Object.getOwnPropertyDescriptor(Array, "of"); - -assert.sameValue(desc.configurable, true); -assert.sameValue(desc.enumerable, false); -assert.sameValue(desc.writable, true); -assert.sameValue(Array.of.length, 0); -assert.throws(TypeError, function() { new Array.of() }); // not a constructor - -// When the this-value passed in is not a constructor, the result is an array. -[ - undefined, - null, - false, - "cow", - NaN, - 67, - Infinity, - -Infinity, - Math.cos, // builtin functions with no [[Construct]] slot - Math.cos.bind(Math) // bound builtin functions with no [[Construct]] slot -].forEach(function(val) { - assert.sameValue(Array.isArray(Array.of.call(val, val)), true); -}); - - -var boundFn = (function() {}).bind(null); -var instance = Array.of.call(boundFn, 1, 2, 3); -assert.sameValue(instance.length, 3); -assert.sameValue(instance instanceof boundFn, true); -assert.sameValue(Array.isArray(instance), false); diff --git a/test/built-ins/Array/of/Array.of_does-not-leave-holes.js b/test/built-ins/Array/of/Array.of_does-not-leave-holes.js deleted file mode 100644 index 1e68f97475..0000000000 --- a/test/built-ins/Array/of/Array.of_does-not-leave-holes.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.2.3 -description: > - The Array.of() method creates a new Array instance - with a variable number of arguments, regardless of - number or type of the arguments. - - Array.of does not leave holes - - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of -includes: [compareArray.js] ----*/ -assert(compareArray(Array.of(undefined), [undefined])); -assert(compareArray(Array.of(undefined, undefined), [undefined, undefined])); -assert(compareArray(Array.of.apply(null, [,,undefined]), [undefined, undefined, undefined])); -assert(compareArray(Array.of.apply(null, Array(4)), [undefined, undefined, undefined, undefined])); - diff --git a/test/built-ins/Array/of/Array.of_does-not-trigger-prototype-setters.js b/test/built-ins/Array/of/Array.of_does-not-trigger-prototype-setters.js deleted file mode 100644 index add037ff61..0000000000 --- a/test/built-ins/Array/of/Array.of_does-not-trigger-prototype-setters.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.2.3 -description: > - The Array.of() method creates a new Array instance - with a variable number of arguments, regardless of - number or type of the arguments. - - Array.of does not trigger prototype setters. - (It defines elements rather than assigning to them.) - - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of -includes: [compareArray.js] ----*/ - - - - -function Bag() {} -Bag.of = Array.of; - -var status = "pass"; -Object.defineProperty(Array.prototype, "0", {set: function(v) {status = "FAIL 1"}}); -assert.sameValue(Array.of(1)[0], 1); -assert.sameValue(status, "pass"); - -Object.defineProperty(Bag.prototype, "0", {set: function(v) {status = "FAIL 2"}}); -assert.sameValue(Bag.of(1)[0], 1); -assert.sameValue(status, "pass"); - diff --git a/test/built-ins/Array/of/Array.of_makes-real-arrays.js b/test/built-ins/Array/of/Array.of_makes-real-arrays.js deleted file mode 100644 index f3bf5e895b..0000000000 --- a/test/built-ins/Array/of/Array.of_makes-real-arrays.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.2.3 -description: > - The Array.of() method creates a new Array instance - with a variable number of arguments, regardless of - number or type of the arguments. - - Array.of makes real arrays. - - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of ----*/ - -function check(a) { - assert.sameValue(Object.getPrototypeOf(a), Array.prototype); - assert.sameValue(Array.isArray(a), true); - a[9] = 9; - assert.sameValue(a.length, 10); -} - -check(Array.of()); -check(Array.of(0)); -check(Array.of(0, 1, 2)); -var f = Array.of; -check(f()); - diff --git a/test/built-ins/Array/of/Array.of_passes-the-number-of-arguments-to-the-constructor-it-calls.js b/test/built-ins/Array/of/Array.of_passes-the-number-of-arguments-to-the-constructor-it-calls.js deleted file mode 100644 index 61619a0d5d..0000000000 --- a/test/built-ins/Array/of/Array.of_passes-the-number-of-arguments-to-the-constructor-it-calls.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.2.3 -description: > - The Array.of() method creates a new Array instance - with a variable number of arguments, regardless of - number or type of the arguments. - - Array.of passes the number of arguments to the constructor it calls. - - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of -includes: [compareArray.js] ----*/ -var hits = 0; - -function Herd(n) { - assert.sameValue(arguments.length, 1); - assert.sameValue(n, 5); - hits++; -} - -Herd.of = Array.of; -Herd.of("sheep", "cattle", "elephants", "whales", "seals"); -assert.sameValue(hits, 1); diff --git a/test/built-ins/Array/of/S22.1.2.3_T1.js b/test/built-ins/Array/of/S22.1.2.3_T1.js deleted file mode 100644 index aad1f8f68c..0000000000 --- a/test/built-ins/Array/of/S22.1.2.3_T1.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2014 Hank Yates. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.1.2.3_T1 -description: Testing Array#of when passed Strings -author: Hank Yates (hankyates@gmail.com) -includes: [runTestCase.js] ----*/ - -runTestCase(function () { - var testArr = Array.of('testString', 'anotherTestString'); - - if (testArr[0] !== 'testString') { - return false; - } - - if (testArr[1] !== 'anotherTestString') { - return false; - } - - return true; - -}); diff --git a/test/built-ins/Array/of/S22.1.2.3_T2.js b/test/built-ins/Array/of/S22.1.2.3_T2.js deleted file mode 100644 index b75a66b3fb..0000000000 --- a/test/built-ins/Array/of/S22.1.2.3_T2.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2014 Hank Yates. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es6id: 22.1.2.3_T2 -description: Testing Array#of when passed single argument -author: Hank Yates (hankyates@gmail.com) -includes: [runTestCase.js] ----*/ - -runTestCase(function () { - var testArr = Array.of(3); - - if (testArr.length !== 1) { - return false; - } - - if (testArr[0] !== 3) { - return false; - } - - return true; - -}); diff --git a/test/built-ins/Array/of/construct-this-with-the-number-of-arguments.js b/test/built-ins/Array/of/construct-this-with-the-number-of-arguments.js new file mode 100644 index 0000000000..937b036ac9 --- /dev/null +++ b/test/built-ins/Array/of/construct-this-with-the-number-of-arguments.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: 22.1.2.3 +description: Passes the number of arguments to the constructor it calls. +info: > + Array.of ( ...items ) + + 1. Let len be the actual number of arguments passed to this function. + 2. Let items be the List of arguments passed to this function. + 3. Let C be the this value. + 4. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + ... +---*/ + +var length; +var hits = 0; + +function C(len) { + length = len; + hits++; +} + +Array.of.call(C); +assert.sameValue(length, 0, '`Array.of.call(C);` called `new C(0)`'); +assert.sameValue(hits, 1, 'Called constructor once per call'); + +Array.of.call(C, 'a', 'b') +assert.sameValue(length, 2, '`Array.of.call(C, "a", "b"));` called `new C(2)`'); +assert.sameValue(hits, 2, 'Called constructor once per call'); + +Array.of.call(C, false, null, undefined); +assert.sameValue( + length, 3, + '`Array.of.call(C, false, null, undefined);` called `new C(3)`' +); +assert.sameValue(hits, 3, 'Called constructor once per call'); \ No newline at end of file diff --git a/test/built-ins/Array/of/creates-a-new-array-from-arguments.js b/test/built-ins/Array/of/creates-a-new-array-from-arguments.js new file mode 100644 index 0000000000..be553f800b --- /dev/null +++ b/test/built-ins/Array/of/creates-a-new-array-from-arguments.js @@ -0,0 +1,44 @@ +// Copyright (c) 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +/*--- +es6id: 22.1.2.3 +description: > + Array.of method creates a new Array with a variable number of arguments. +info: > + 22.1.2.3 Array.of ( ...items ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + a. Let kValue be items[k]. + b. Let Pk be ToString(k). + c. Let defineStatus be CreateDataPropertyOrThrow(A,Pk, kValue). + d. ReturnIfAbrupt(defineStatus). + e. Increase k by 1. + 9. Let setStatus be Set(A, "length", len, true). + 10. ReturnIfAbrupt(setStatus). + 11. Return A. +---*/ + +var a1 = Array.of('Mike', 'Rick', 'Leo'); +assert.sameValue( + a1.length, 3, + 'The new array length is the same as the arguments size' +); +assert.sameValue(a1[0], 'Mike', 'set each property in order - #1'); +assert.sameValue(a1[1], 'Rick', 'set each property in order - #2'); +assert.sameValue(a1[2], 'Leo', 'set each property in order - #3'); + +var a2 = Array.of(undefined, false, null, undefined); +assert.sameValue( + a2.length, 4, + 'Creates an array from the arguments, regarless of their type values' +); +assert.sameValue(a2[0], undefined, 'set each property in order - #1'); +assert.sameValue(a2[1], false, 'set each property in order - #2'); +assert.sameValue(a2[2], null, 'set each property in order - #3'); +assert.sameValue(a2[3], undefined, 'set each property in order - #4'); + +var a3 = Array.of(); +assert.sameValue(a3.length, 0, 'Array.of() returns an empty array'); diff --git a/test/built-ins/Array/of/does-not-use-prototype-properties.js b/test/built-ins/Array/of/does-not-use-prototype-properties.js new file mode 100644 index 0000000000..bad15405a1 --- /dev/null +++ b/test/built-ins/Array/of/does-not-use-prototype-properties.js @@ -0,0 +1,29 @@ +// Copyright (c) 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +/*--- +es6id: 22.1.2.3 +description: Array.of does not use prototype properties for arguments. +info: > + It defines elements rather than assigning to them. +---*/ + +Object.defineProperty(Array.prototype, "0", { + set: function(v) { + $ERROR('Should define own properties'); + } +}); + +var arr = Array.of(true); +assert.sameValue(arr[0], true); + +function Custom() {} + +Object.defineProperty(Custom.prototype, "0", { + set: function(v) { + $ERROR('Should define own properties'); + } +}); + +var custom = Array.of.call(Custom, true); +assert.sameValue(custom[0], true); diff --git a/test/built-ins/Array/of/length.js b/test/built-ins/Array/of/length.js new file mode 100644 index 0000000000..b3110d0e65 --- /dev/null +++ b/test/built-ins/Array/of/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: 22.1.2.3 +description: > + Array.of.length value and property descriptor +info: > + Array.of ( ...items ) + + The length property of the of function is 0. +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.of.length, 0, + 'The value of `Array.of.length` is `0`' +); + +verifyNotEnumerable(Array.of, 'length'); +verifyNotWritable(Array.of, 'length'); +verifyConfigurable(Array.of, 'length'); diff --git a/test/built-ins/Array/of/name.js b/test/built-ins/Array/of/name.js new file mode 100644 index 0000000000..fe6686bfb9 --- /dev/null +++ b/test/built-ins/Array/of/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: 22.1.2.3 +description: > + Array.of.name value and property descriptor +info: > + Array.of ( ...items ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.of.name, 'of', + 'The value of `Array.of.name` is `"of"`' +); + +verifyNotEnumerable(Array.of, 'name'); +verifyNotWritable(Array.of, 'name'); +verifyConfigurable(Array.of, 'name'); diff --git a/test/built-ins/Array/of/not-a-constructor.js b/test/built-ins/Array/of/not-a-constructor.js new file mode 100644 index 0000000000..6a3f5b0985 --- /dev/null +++ b/test/built-ins/Array/of/not-a-constructor.js @@ -0,0 +1,11 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.2.3 +description: > + Array.of is not a constructor. +---*/ + +assert.throws(TypeError, function() { + new Array.of(); +}); diff --git a/test/built-ins/Array/of/of.js b/test/built-ins/Array/of/of.js new file mode 100644 index 0000000000..e6bd1e753d --- /dev/null +++ b/test/built-ins/Array/of/of.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: 22.1.2.3 +description: > + Array.of property descriptor +info: > + Array.of ( ...items ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Array, 'of'); +verifyWritable(Array, 'of'); +verifyConfigurable(Array, 'of'); diff --git a/test/built-ins/Array/of/return-a-custom-instance.js b/test/built-ins/Array/of/return-a-custom-instance.js new file mode 100644 index 0000000000..cba39a54e6 --- /dev/null +++ b/test/built-ins/Array/of/return-a-custom-instance.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: 22.1.2.3 +description: > + Returns an instance from a custom constructor. +info: > + Array.of ( ...items ) + + ... + 4. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + ... + 11. Return A. +---*/ + +function Coop() {} + +var coop = Array.of.call(Coop, 'Mike', 'Rick', 'Leo'); + +assert.sameValue( + coop.length, 3, + 'Sets a length property with the number of arguments' +); +assert.sameValue( + coop[0], 'Mike', + 'Sets each argument in order as integer properties - #1 argument' +); +assert.sameValue( + coop[1], 'Rick', + 'Sets each argument in order as integer properties - #2 argument' +); +assert.sameValue( + coop[2], 'Leo', + 'Sets each argument in order as integer properties - #3 argument' +); +assert(coop instanceof Coop, 'Returns an instance from a custom constructor'); diff --git a/test/built-ins/Array/of/return-a-new-array-object.js b/test/built-ins/Array/of/return-a-new-array-object.js new file mode 100644 index 0000000000..9f43fbc7e0 --- /dev/null +++ b/test/built-ins/Array/of/return-a-new-array-object.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.2.3 +description: > + Returns a new Array. +info: > + Array.of ( ...items ) + + 1. Let len be the actual number of arguments passed to this function. + 2. Let items be the List of arguments passed to this function. + 3. Let C be the this value. + 4. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + 5. Else, + b. Let A be ArrayCreate(len). + ... + 11. Return A. +---*/ + +var result = Array.of(); +assert(result instanceof Array, 'Array.of() returns a new Array'); + +result = Array.of.call(undefined); +assert( + result instanceof Array, + 'this is not a constructor' +); + +result = Array.of.call(Math.cos); +assert( + result instanceof Array, + 'this is a builtin function with no [[Construct]] slot' +); + +result = Array.of.call(Math.cos.bind(Math)); +assert( + result instanceof Array, + 'this is a bound builtin function with no [[Construct]] slot' +); diff --git a/test/built-ins/Array/of/return-abrupt-from-contructor.js b/test/built-ins/Array/of/return-abrupt-from-contructor.js new file mode 100644 index 0000000000..821e4d9cf7 --- /dev/null +++ b/test/built-ins/Array/of/return-abrupt-from-contructor.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: 22.1.2.3 +description: > + Return abrupt from this' constructor +info: > + Array.of ( ...items ) + + 1. Let len be the actual number of arguments passed to this function. + 2. Let items be the List of arguments passed to this function. + 3. Let C be the this value. + 4. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + 5. Else, + b. Let A be ArrayCreate(len). + 6. ReturnIfAbrupt(A). + ... +---*/ + +function T() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + Array.of.call(T); +}); diff --git a/test/built-ins/Array/of/return-abrupt-from-data-property-using-proxy.js b/test/built-ins/Array/of/return-abrupt-from-data-property-using-proxy.js new file mode 100644 index 0000000000..f5e82ad038 --- /dev/null +++ b/test/built-ins/Array/of/return-abrupt-from-data-property-using-proxy.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: 22.1.2.3 +description: > + Return abrupt from Data Property creation +info: > + Array.of ( ...items ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + a. Let kValue be items[k]. + b. Let Pk be ToString(k). + c. Let defineStatus be CreateDataPropertyOrThrow(A,Pk, kValue). + d. ReturnIfAbrupt(defineStatus). + ... + + 7.3.6 CreateDataPropertyOrThrow (O, P, V) + + ... + 3. Let success be CreateDataProperty(O, P, V). + 4. ReturnIfAbrupt(success). + ... +features: [Proxy] +---*/ + +function T() { + return new Proxy({}, { + defineProperty: function() { + throw new Test262Error(); + } + }); +} + +assert.throws(Test262Error, function() { + Array.of.call(T, 'Bob'); +}); diff --git a/test/built-ins/Array/of/return-abrupt-from-data-property.js b/test/built-ins/Array/of/return-abrupt-from-data-property.js new file mode 100644 index 0000000000..a8b8d82e42 --- /dev/null +++ b/test/built-ins/Array/of/return-abrupt-from-data-property.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: 22.1.2.3 +description: > + Return abrupt from Data Property creation +info: > + Array.of ( ...items ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + a. Let kValue be items[k]. + b. Let Pk be ToString(k). + c. Let defineStatus be CreateDataPropertyOrThrow(A,Pk, kValue). + d. ReturnIfAbrupt(defineStatus). + ... + + 7.3.6 CreateDataPropertyOrThrow (O, P, V) + + ... + 3. Let success be CreateDataProperty(O, P, V). + 4. ReturnIfAbrupt(success). + 5. If success is false, throw a TypeError exception. + ... +---*/ + +function T1() { + Object.preventExtensions(this); +} + +assert.throws(TypeError, function() { + Array.of.call(T1, 'Bob'); +}); + +function T2() { + Object.defineProperty(this, 0, { + configurable: false, + writable: true, + enumerable: true + }); +} + +assert.throws(TypeError, function() { + Array.of.call(T2, 'Bob'); +}) diff --git a/test/built-ins/Array/of/return-abrupt-from-setting-length.js b/test/built-ins/Array/of/return-abrupt-from-setting-length.js new file mode 100644 index 0000000000..870df29fc9 --- /dev/null +++ b/test/built-ins/Array/of/return-abrupt-from-setting-length.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: 22.1.2.3 +description: > + Return abrupt from setting the length property. +info: > + Array.of ( ...items ) + + ... + 9. Let setStatus be Set(A, "length", len, true). + 10. ReturnIfAbrupt(setStatus). + ... +---*/ + +function T() { + Object.defineProperty(this, 'length', { + set: function() { + throw new Test262Error(); + } + }); +} + +assert.throws(Test262Error, function() { + Array.of.call(T); +}); diff --git a/test/built-ins/Array/of/sets-length.js b/test/built-ins/Array/of/sets-length.js new file mode 100644 index 0000000000..d54492915b --- /dev/null +++ b/test/built-ins/Array/of/sets-length.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: 22.1.2.3 +description: > + Calls the length setter if available +info: > + Array.of ( ...items ) + + ... + 9. Let setStatus be Set(A, "length", len, true). + ... +---*/ + +var hits = 0; +var value; +var _this_; + +function Pack() { + Object.defineProperty(this, "length", { + set: function(len) { + hits++; + value = len; + _this_ = this; + } + }); +} + +var result = Array.of.call(Pack, 'wolves', 'cards', 'cigarettes', 'lies'); + +assert.sameValue(hits, 1, 'instance length setter called once'); +assert.sameValue( + value, 4, + 'setter is called with the number of Array.of arguments' +); +assert.sameValue(_this_, result, 'setter is called with the new object');