diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/of')
18 files changed, 554 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/of/browser.js b/js/src/tests/test262/built-ins/Array/of/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/browser.js diff --git a/js/src/tests/test262/built-ins/Array/of/construct-this-with-the-number-of-arguments.js b/js/src/tests/test262/built-ins/Array/of/construct-this-with-the-number-of-arguments.js new file mode 100644 index 0000000000..546cb95348 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/construct-this-with-the-number-of-arguments.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. +/*--- +esid: sec-array.of +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 len; +var hits = 0; + +function C(length) { + len = length; + hits++; +} + +Array.of.call(C); +assert.sameValue(len, 0, 'The value of len is expected to be 0'); +assert.sameValue(hits, 1, 'The value of hits is expected to be 1'); + +Array.of.call(C, 'a', 'b') +assert.sameValue(len, 2, 'The value of len is expected to be 2'); +assert.sameValue(hits, 2, 'The value of hits is expected to be 2'); + +Array.of.call(C, false, null, undefined); +assert.sameValue( + len, 3, + 'The value of len is expected to be 3' +); +assert.sameValue(hits, 3, 'The value of hits is expected to be 3'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/creates-a-new-array-from-arguments.js b/js/src/tests/test262/built-ins/Array/of/creates-a-new-array-from-arguments.js new file mode 100644 index 0000000000..09ef45b6da --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/creates-a-new-array-from-arguments.js @@ -0,0 +1,47 @@ +// 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. +/*--- +esid: sec-array.of +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 value of a1.length is expected to be 3' +); +assert.sameValue(a1[0], 'Mike', 'The value of a1[0] is expected to be "Mike"'); +assert.sameValue(a1[1], 'Rick', 'The value of a1[1] is expected to be "Rick"'); +assert.sameValue(a1[2], 'Leo', 'The value of a1[2] is expected to be "Leo"'); + +var a2 = Array.of(undefined, false, null, undefined); +assert.sameValue( + a2.length, 4, + 'The value of a2.length is expected to be 4' +); +assert.sameValue(a2[0], undefined, 'The value of a2[0] is expected to equal undefined'); +assert.sameValue(a2[1], false, 'The value of a2[1] is expected to be false'); +assert.sameValue(a2[2], null, 'The value of a2[2] is expected to be null'); +assert.sameValue(a2[3], undefined, 'The value of a2[3] is expected to equal undefined'); + +var a3 = Array.of(); +assert.sameValue(a3.length, 0, 'The value of a3.length is expected to be 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/does-not-use-prototype-properties.js b/js/src/tests/test262/built-ins/Array/of/does-not-use-prototype-properties.js new file mode 100644 index 0000000000..6f08da1f92 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/does-not-use-prototype-properties.js @@ -0,0 +1,32 @@ +// 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. +/*--- +esid: sec-array.of +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) { + throw new Test262Error('Should define own properties'); + } +}); + +var arr = Array.of(true); +assert.sameValue(arr[0], true, 'The value of arr[0] is expected to be true'); + +function Custom() {} + +Object.defineProperty(Custom.prototype, "0", { + set: function(v) { + throw new Test262Error('Should define own properties'); + } +}); + +var custom = Array.of.call(Custom, true); +assert.sameValue(custom[0], true, 'The value of custom[0] is expected to be true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/does-not-use-set-for-indices.js b/js/src/tests/test262/built-ins/Array/of/does-not-use-set-for-indices.js new file mode 100644 index 0000000000..7461aef192 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/does-not-use-set-for-indices.js @@ -0,0 +1,38 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.of +description: > + Non-writable properties are overwritten by CreateDataProperty. + (result object's "0" is non-writable) +info: | + Array.of ( ...items ) + + [...] + 7. Repeat, while k < len + [...] + c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue). + [...] +includes: [propertyHelper.js] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + value: 1, + writable: false, + enumerable: false, + configurable: true, + }); +}; + +var res = Array.of.call(A, 2); + +verifyProperty(res, "0", { + value: 2, + writable: true, + enumerable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/length.js b/js/src/tests/test262/built-ins/Array/of/length.js new file mode 100644 index 0000000000..f77c48b768 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/length.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. +/*--- +esid: sec-array.of +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 expected to be 0' +); + +verifyNotEnumerable(Array.of, 'length'); +verifyNotWritable(Array.of, 'length'); +verifyConfigurable(Array.of, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/name.js b/js/src/tests/test262/built-ins/Array/of/name.js new file mode 100644 index 0000000000..842dd1ad11 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/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. +/*--- +esid: sec-array.of +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 expected to be "of"' +); + +verifyNotEnumerable(Array.of, 'name'); +verifyNotWritable(Array.of, 'name'); +verifyConfigurable(Array.of, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/of/not-a-constructor.js new file mode 100644 index 0000000000..a9f9221010 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/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: > + Array.of 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, arrow-function] +---*/ + +assert.sameValue(isConstructor(Array.of), false, 'isConstructor(Array.of) must return false'); + +assert.throws(TypeError, () => { + new Array.of(1); +}, '`new Array.of(1)` throws a TypeError exception'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/of.js b/js/src/tests/test262/built-ins/Array/of/of.js new file mode 100644 index 0000000000..8dee2737ce --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/of.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. +/*--- +esid: sec-array.of +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/Array/of/proto-from-ctor-realm.js new file mode 100644 index 0000000000..e2bdcca1e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/proto-from-ctor-realm.js @@ -0,0 +1,35 @@ +// 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-array.of +description: Default [[Prototype]] value derived from realm of the constructor +info: | + [...] + 4. If IsConstructor(C) is true, then + a. Let A be ? Construct(C, « len »). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +var a = Array.of.call(C, 1, 2, 3); + +assert.sameValue( + Object.getPrototypeOf(a), + other.Object.prototype, + 'Object.getPrototypeOf(Array.of.call(C, 1, 2, 3)) returns other.Object.prototype' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/return-a-custom-instance.js b/js/src/tests/test262/built-ins/Array/of/return-a-custom-instance.js new file mode 100644 index 0000000000..88510b9c7d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/return-a-custom-instance.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. +/*--- +esid: sec-array.of +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, + 'The value of coop.length is expected to be 3' +); +assert.sameValue( + coop[0], 'Mike', + 'The value of coop[0] is expected to be "Mike"' +); +assert.sameValue( + coop[1], 'Rick', + 'The value of coop[1] is expected to be "Rick"' +); +assert.sameValue( + coop[2], 'Leo', + 'The value of coop[2] is expected to be "Leo"' +); +assert(coop instanceof Coop, 'The result of evaluating (coop instanceof Coop) is expected to be true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/return-a-new-array-object.js b/js/src/tests/test262/built-ins/Array/of/return-a-new-array-object.js new file mode 100644 index 0000000000..a344f7aa34 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/return-a-new-array-object.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. +/*--- +esid: sec-array.of +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, 'The result of evaluating (result instanceof Array) is expected to be true'); + +result = Array.of.call(undefined); +assert( + result instanceof Array, + 'The result of evaluating (result instanceof Array) is expected to be true' +); + +result = Array.of.call(Math.cos); +assert( + result instanceof Array, + 'The result of evaluating (result instanceof Array) is expected to be true' +); + +result = Array.of.call(Math.cos.bind(Math)); +assert( + result instanceof Array, + 'The result of evaluating (result instanceof Array) is expected to be true' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-contructor.js b/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-contructor.js new file mode 100644 index 0000000000..3eee722071 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-contructor.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. +/*--- +esid: sec-array.of +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); +}, 'Array.of.call(T) throws a Test262Error exception'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-data-property-using-proxy.js b/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-data-property-using-proxy.js new file mode 100644 index 0000000000..de60c318dc --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-data-property-using-proxy.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. +/*--- +esid: sec-array.of +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'); +}, 'Array.of.call(T, "Bob") throws a Test262Error exception'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-data-property.js b/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-data-property.js new file mode 100644 index 0000000000..de7f8acc75 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-data-property.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. +/*--- +esid: sec-array.of +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'); +}, 'Array.of.call(T1, "Bob") throws a TypeError exception'); + +function T2() { + Object.defineProperty(this, 0, { + configurable: false, + writable: true, + enumerable: true + }); +} + +assert.throws(TypeError, function() { + Array.of.call(T2, 'Bob'); +}, 'Array.of.call(T2, "Bob") throws a TypeError exception') + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-setting-length.js b/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-setting-length.js new file mode 100644 index 0000000000..f4dd67769f --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/return-abrupt-from-setting-length.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. +/*--- +esid: sec-array.of +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); +}, 'Array.of.call(T) throws a Test262Error exception'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/sets-length.js b/js/src/tests/test262/built-ins/Array/of/sets-length.js new file mode 100644 index 0000000000..2b651a4068 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/sets-length.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. +/*--- +esid: sec-array.of +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, 'The value of hits is expected to be 1'); +assert.sameValue( + value, 4, + 'The value of value is expected to be 4' +); +assert.sameValue(_this_, result, 'The value of _this_ is expected to equal the value of result'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/of/shell.js b/js/src/tests/test262/built-ins/Array/of/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/shell.js |