diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/with')
23 files changed, 607 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/browser.js b/js/src/tests/test262/built-ins/Array/prototype/with/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/frozen-this-value.js b/js/src/tests/test262/built-ins/Array/prototype/with/frozen-this-value.js new file mode 100644 index 0000000000..73cdc284c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/frozen-this-value.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with works on frozen objects +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = Object.freeze([0, 1, 2]); +var result = arr.with(1, 3); +assert.compareArray(result, [0, 3, 2]); + +var arrayLike = Object.freeze({ length: 3, 0: 0, 1: 1, 2: 2 }); +var result2 = Array.prototype.with.call(arrayLike, 1, 3); +assert.compareArray(result2, [0, 3, 2]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/holes-not-preserved.js b/js/src/tests/test262/built-ins/Array/prototype/with/holes-not-preserved.js new file mode 100644 index 0000000000..faefdc173d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/holes-not-preserved.js @@ -0,0 +1,32 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with does not preserve holes in the array +info: | + Array.prototype.with ( ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + ... + 5. Repeat, while k < len + a. Let Pk be ! ToString(š¯”½(k)). + b. If k is actualIndex, let fromValue be value. + c. Else, let fromValue be ? Get(O, Pk). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, /* hole */, 2, /* hole */, 4]; +Array.prototype[3] = 3; + +var result = arr.with(2, 6); +assert.compareArray(result, [0, undefined, 6, 3, 4]); +assert(result.hasOwnProperty(1)); +assert(result.hasOwnProperty(3)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/ignores-species.js b/js/src/tests/test262/built-ins/Array/prototype/with/ignores-species.js new file mode 100644 index 0000000000..7b198186fc --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/ignores-species.js @@ -0,0 +1,32 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with ignores @@species +info: | + Array.prototype.with ( ) + + ... + 8. Let A be ? ArrayCreate(š¯”½(len)). + ... +features: [change-array-by-copy] +---*/ + +var a = [1, 2, 3]; +a.constructor = {}; +a.constructor[Symbol.species] = function () {} + +assert.sameValue(Object.getPrototypeOf(a.with(0, 0)), Array.prototype); + +var b = [1, 2, 3]; +Object.defineProperty(b, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } +}); + +b.with(0, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/immutable.js b/js/src/tests/test262/built-ins/Array/prototype/with/immutable.js new file mode 100644 index 0000000000..04c1621dff --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/immutable.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with does not mutate its this value +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; +arr.with(1, 3); + +assert.compareArray(arr, [0, 1, 2]); +assert.notSameValue(arr.with(1, 3), arr); +assert.notSameValue(arr.with(1, 1), arr); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/index-bigger-or-eq-than-length.js b/js/src/tests/test262/built-ins/Array/prototype/with/index-bigger-or-eq-than-length.js new file mode 100644 index 0000000000..752b280db7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/index-bigger-or-eq-than-length.js @@ -0,0 +1,37 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with throws if the index is bigger than or equal to the array length. +info: | + Array.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + 6. If actualIndex >= len or actualIndex < 0, throw a *RangeError* exception. + ... +features: [change-array-by-copy, exponentiation] +---*/ + +assert.throws(RangeError, function() { + [0, 1, 2].with(3, 7); +}); + +assert.throws(RangeError, function() { + [0, 1, 2].with(10, 7); +}); + +assert.throws(RangeError, function() { + [0, 1, 2].with(2 ** 53 + 2, 7); +}); + +assert.throws(RangeError, function() { + [0, 1, 2].with(Infinity, 7); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/index-casted-to-number.js b/js/src/tests/test262/built-ins/Array/prototype/with/index-casted-to-number.js new file mode 100644 index 0000000000..e0543723e0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/index-casted-to-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with casts the index to an integer. +info: | + Array.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 4, 16]; + +assert.compareArray(arr.with(1.2, 7), [0, 7, 16]); +assert.compareArray(arr.with("1", 3), [0, 3, 16]); +assert.compareArray(arr.with("-1", 5), [0, 4, 5]); +assert.compareArray(arr.with(NaN, 2), [2, 4, 16]); +assert.compareArray(arr.with("dog", "cat"), ["cat", 4, 16]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/index-negative.js b/js/src/tests/test262/built-ins/Array/prototype/with/index-negative.js new file mode 100644 index 0000000000..d9b8a8eaac --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/index-negative.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with adds length to index if it's negative. +info: | + Array.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; + +assert.compareArray(arr.with(-1, 4), [0, 1, 4]); +assert.compareArray(arr.with(-3, 4), [4, 1, 2]); + +// -0 is not < 0 +assert.compareArray(arr.with(-0, 4), [4, 1, 2]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/index-smaller-than-minus-length.js b/js/src/tests/test262/built-ins/Array/prototype/with/index-smaller-than-minus-length.js new file mode 100644 index 0000000000..d1f98336ab --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/index-smaller-than-minus-length.js @@ -0,0 +1,39 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with throws if the (negative) index is smaller than -length. +info: | + Array.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + 6. If actualIndex >= len or actualIndex < 0, throw a *RangeError* exception. + ... +features: [change-array-by-copy, exponentiation] +---*/ + +[0, 1, 2].with(-3, 7); + +assert.throws(RangeError, function() { + [0, 1, 2].with(-4, 7); +}); + +assert.throws(RangeError, function() { + [0, 1, 2].with(-10, 7); +}); + +assert.throws(RangeError, function() { + [0, 1, 2].with(-(2 ** 53) - 2, 7); +}); + +assert.throws(RangeError, function() { + [0, 1, 2].with(-Infinity, 7); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/length-decreased-while-iterating.js b/js/src/tests/test262/built-ins/Array/prototype/with/length-decreased-while-iterating.js new file mode 100644 index 0000000000..8102da0e52 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/length-decreased-while-iterating.js @@ -0,0 +1,42 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with caches the length getting the array elements. +info: | + Array.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + ... + 5. Repeat, while k < len + a. Let Pk be ! ToString(š¯”½(k)). + b. If k is actualIndex, let fromValue be value. + c. Else, let fromValue be ? Get(O, Pk). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +Array.prototype[4] = 5; + +var arr = Object.defineProperty([0, 1, 2, 3, 4], "1", { + get() { + arr.length = 1; + return 1; + } +}); +assert.compareArray(arr.with(2, 7), [0, 1, 7, undefined, 5]); + +arr = Object.defineProperty([0, 1, 2, 3, 4], "1", { + get() { + arr.length = 1; + return 1; + } +}); +assert.compareArray(arr.with(0, 7), [7, 1, undefined, undefined, 5]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/length-exceeding-array-length-limit.js b/js/src/tests/test262/built-ins/Array/prototype/with/length-exceeding-array-length-limit.js new file mode 100644 index 0000000000..76dd9cf5ec --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/length-exceeding-array-length-limit.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with limits the length to 2 ** 32 - 1 +info: | + Array.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + ... + 7. Let A be ? ArrayCreate(š¯”½(len)). + ... + + ArrayCreate ( length [, proto ] ) + + 1. If length > 2 ** 32 - 1, throw a RangeError exception. +features: [change-array-by-copy, exponentiation] +---*/ + +// Object with large "length" property +var arrayLike = { + get "0"() { + throw new Test262Error("Get 0"); + }, + get "4294967295" () { // 2 ** 32 - 1 + throw new Test262Error("Get 4294967295"); + }, + get "4294967296" () { // 2 ** 32 + throw new Test262Error("Get 4294967296"); + }, + length: 2 ** 32 +}; + +assert.throws(RangeError, function() { + Array.prototype.with.call(arrayLike, 0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/length-increased-while-iterating.js b/js/src/tests/test262/built-ins/Array/prototype/with/length-increased-while-iterating.js new file mode 100644 index 0000000000..01e3147e51 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/length-increased-while-iterating.js @@ -0,0 +1,34 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with caches the length getting the array elements. +info: | + Array.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + ... + 5. Repeat, while k < len + a. Let Pk be ! ToString(š¯”½(k)). + b. If k is actualIndex, let fromValue be value. + c. Else, let fromValue be ? Get(O, Pk). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; +Object.defineProperty(arr, "0", { + get() { + arr.push(4); + return 0; + } +}); + +assert.compareArray(arr.with(1, 4), [0, 4, 2]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/length-tolength.js b/js/src/tests/test262/built-ins/Array/prototype/with/length-tolength.js new file mode 100644 index 0000000000..2573c8532f --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/length-tolength.js @@ -0,0 +1,32 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with converts the this value length to a number. +info: | + Array.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arrayLike = { length: "2", 0: 1, 1: 2, 2: 3 }; +assert.compareArray(Array.prototype.with.call(arrayLike, 0, 4), [4, 2]); + +var arrayLike = { + length: { + valueOf: () => 2 + }, + 0: 1, + 1: 2, + 2: 3, +}; + +assert.compareArray(Array.prototype.with.call(arrayLike, 0, 4), [4, 2]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/metadata/browser.js b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/metadata/length.js b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/length.js new file mode 100644 index 0000000000..7fac787816 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + The "length" property of Array.prototype.with +info: | + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form Ā«...nameĀ») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(Array.prototype.with, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/metadata/name.js b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/name.js new file mode 100644 index 0000000000..108a0b9a7e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with.name is "with". +info: | + Array.prototype.with ( index, value ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(Array.prototype.with, "name", { + value: "with", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/metadata/property-descriptor.js b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/property-descriptor.js new file mode 100644 index 0000000000..2c43f28ec6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/property-descriptor.js @@ -0,0 +1,27 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + "with" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +assert.sameValue(typeof Array.prototype.with, "function", "typeof"); + +verifyProperty(Array.prototype, "with", { + value: Array.prototype.with, + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/metadata/shell.js b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/metadata/shell.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/no-get-replaced-index.js b/js/src/tests/test262/built-ins/Array/prototype/with/no-get-replaced-index.js new file mode 100644 index 0000000000..91c77a539e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/no-get-replaced-index.js @@ -0,0 +1,32 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with does not [[Get]] the value in the replaced position +info: | + Array.prototype.with ( ) + + ... + 5. Repeat, while k < len + a. Let Pk be ! ToString(š¯”½(k)). + b. If k is actualIndex, let fromValue be value. + c. Else, let fromValue be ? Get(O, Pk). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "2", { + get() { + throw new Test262Error("Should not get '2'"); + } +}); + +var result = arr.with(2, 6); +assert.compareArray(result, [0, 1, 6, 3]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/with/not-a-constructor.js new file mode 100644 index 0000000000..257a21aa51 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2021 Igalia, S.L. 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.prototype.with 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: [change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(Array.prototype.with), + false, + 'isConstructor(Array.prototype.with) must return false' +); + +assert.throws(TypeError, () => { + new Array.prototype.with(); +}, '`new Array.prototype.with()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/shell.js b/js/src/tests/test262/built-ins/Array/prototype/with/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/shell.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/this-value-boolean.js b/js/src/tests/test262/built-ins/Array/prototype/with/this-value-boolean.js new file mode 100644 index 0000000000..453817c2a5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/this-value-boolean.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with casts primitive receivers to objects +info: | + Array.prototype.with ( index, value ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +Boolean.prototype.length = 2; +Boolean.prototype[0] = 0; +Boolean.prototype[1] = 1; + +assert.compareArray(Array.prototype.with.call(true, 0, 2), [2, 1]); +assert.compareArray(Array.prototype.with.call(false, 0, 2), [2, 1]); + +/* Add length and indexed properties to `Boolean.prototype` */ +Boolean.prototype.length = 3; +delete Boolean.prototype[0]; +delete Boolean.prototype[1]; +assert.compareArray(Array.prototype.with.call(true, 0, 2), [2, undefined, undefined]); +assert.compareArray(Array.prototype.with.call(false, 0, 2), [2, undefined, undefined]); +delete Boolean.prototype.length; +Boolean.prototype[0] = "monkeys"; +Boolean.prototype[2] = "bogus"; +assert.throws(RangeError, + () => compareArray(Array.prototype.with.call(true, 0, 2)), + "Array.prototype.with on object with undefined length"); +assert.throws(RangeError, + () => compareArray(Array.prototype.with.call(false, 0, 2)), + "Array.prototype.with on object with undefined length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/with/this-value-nullish.js b/js/src/tests/test262/built-ins/Array/prototype/with/this-value-nullish.js new file mode 100644 index 0000000000..befef0642d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/with/this-value-nullish.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with throws if the receiver is null or undefined +info: | + Array.prototype.with ( index, value ) + + 1. Let O be ? ToObject(this value). + ... +features: [change-array-by-copy] +---*/ + +assert.throws(TypeError, () => { + Array.prototype.with.call(null, 0, 0); +}, '`Array.prototype.with.call(null, 0, 0)` throws TypeError'); + +assert.throws(TypeError, () => { + Array.prototype.with.call(undefined, 0, 0); +}, '`Array.prototype.with.call(undefined, 0, 0)` throws TypeError'); + +reportCompare(0, 0); |