diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/built-ins/Array/of | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/of')
18 files changed, 550 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..7a4a987f04 --- /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, '`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(len, 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( + len, 3, + '`Array.of.call(C, false, null, undefined);` called `new C(3)`' +); +assert.sameValue(hits, 3, 'Called constructor once per call'); + +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..a303d3a870 --- /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 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'); + +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..a7fed502e3 --- /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) { + $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); + +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..62c1110d83 --- /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 `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..d890ef6548 --- /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 `"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..1327964630 --- /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 TypeError'); + + +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..a2f8b4923b --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/of/proto-from-ctor-realm.js @@ -0,0 +1,31 @@ +// 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); + +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..d587255c3f --- /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, + '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'); + +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..f5235fe514 --- /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, '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' +); + +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..b574f5fb7a --- /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); +}); + +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..0c070b450c --- /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'); +}); + +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..b87d93dd06 --- /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'); +}); + +function T2() { + Object.defineProperty(this, 0, { + configurable: false, + writable: true, + enumerable: true + }); +} + +assert.throws(TypeError, function() { + Array.of.call(T2, 'Bob'); +}) + +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..abe52c5924 --- /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); +}); + +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..11ad6a3b9b --- /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, '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'); + +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 |