diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/includes')
42 files changed, 1651 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-false-for-zero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-false-for-zero.js new file mode 100644 index 0000000000..323885aee8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-false-for-zero.js @@ -0,0 +1,48 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: Returns -1 if buffer is detached after ValidateTypedArray +info: | + %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %TypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13. + + When the includes method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return false. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return false. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let elementK be the result of ! Get(O, ! ToString(F(k))). + If SameValueZero(searchElement, elementK) is true, return true. + Set k to k + 1. + Return false. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.includes(0n, fromIndex), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-true-for-undefined.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-true-for-undefined.js new file mode 100644 index 0000000000..875fc9660d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-true-for-undefined.js @@ -0,0 +1,49 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: > + Returns false if buffer is detached after ValidateTypedArray and searchElement is a value +info: | + %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %TypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13. + + When the includes method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return false. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return false. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let elementK be the result of ! Get(O, ! ToString(F(k))). + If SameValueZero(searchElement, elementK) is true, return true. + Set k to k + 1. + Return false. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.includes(undefined, fromIndex), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer.js new file mode 100644 index 0000000000..ca2f008ce7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer.js @@ -0,0 +1,30 @@ +// 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-%typedarray%.prototype.includes +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.includes(0n); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-equal-or-greater-length-returns-false.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-equal-or-greater-length-returns-false.js new file mode 100644 index 0000000000..7fa2cc8769 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-equal-or-greater-length-returns-false.js @@ -0,0 +1,38 @@ +// 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-%typedarray%.prototype.includes +description: Return false if fromIndex >= ArrayLength +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(42); + assert.sameValue(sample.includes(0n, 42), false); + assert.sameValue(sample.includes(0n, 43), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-infinity.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-infinity.js new file mode 100644 index 0000000000..b366f1bb2f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-infinity.js @@ -0,0 +1,46 @@ +// 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-%typedarray%.prototype.includes +description: handle Infinity values for fromIndex +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + ... + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 43n, 41n]); + + assert.sameValue( + sample.includes(43n, Infinity), + false, + "includes(43, Infinity)" + ); + assert.sameValue( + sample.includes(43n, -Infinity), + true, + "includes(43, -Infinity)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-minus-zero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-minus-zero.js new file mode 100644 index 0000000000..d7d70313f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-minus-zero.js @@ -0,0 +1,36 @@ +// 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-%typedarray%.prototype.includes +description: -0 fromIndex becomes 0 +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n]); + assert.sameValue(sample.includes(42n, -0), true, "-0 [0]"); + assert.sameValue(sample.includes(43n, -0), true, "-0 [1]"); + assert.sameValue(sample.includes(44n, -0), false, "-0 [2]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/get-length-uses-internal-arraylength.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000..992515f668 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/get-length-uses-internal-arraylength.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-%typedarray%.prototype.includes +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", {value: 0}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n]); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.includes(7n), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/length-zero-returns-false.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/length-zero-returns-false.js new file mode 100644 index 0000000000..75d998d717 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/length-zero-returns-false.js @@ -0,0 +1,41 @@ +// 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-%typedarray%.prototype.includes +description: Returns false if length is 0 +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.includes(0), false, "returns false"); + assert.sameValue(sample.includes(), false, "returns false - no arg"); + assert.sameValue( + sample.includes(0n, fromIndex), false, + "length is checked before ToInteger(fromIndex)" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..0b97d929e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: Return abrupt when "this" value fails buffer boundary checks +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, TypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.includes, + 'function', + 'implements TypedArray.prototype.includes' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.includes(0n); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.includes(0n); + + var expectedError; + try { + ab.resize(BPE * 2); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the includes operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.includes(0n); + throw new Test262Error('includes completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 0000000000..df26b72aed --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex-symbol.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-%typedarray%.prototype.includes +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n]); + + assert.throws(TypeError, function() { + sample.includes(7n, fromIndex); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex.js new file mode 100644 index 0000000000..983e19bd93 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex.js @@ -0,0 +1,39 @@ +// 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-%typedarray%.prototype.includes +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n]); + + assert.throws(Test262Error, function() { + sample.includes(7n, fromIndex); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/search-found-returns-true.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/search-found-returns-true.js new file mode 100644 index 0000000000..48edd20630 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/search-found-returns-true.js @@ -0,0 +1,46 @@ +// 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-%typedarray%.prototype.includes +description: returns true for found index +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 42n, 41n]); + assert.sameValue(sample.includes(42n), true, "includes(42)"); + assert.sameValue(sample.includes(43n), true, "includes(43)"); + assert.sameValue(sample.includes(43n, 1), true, "includes(43, 1)"); + assert.sameValue(sample.includes(42n, 1), true, "includes(42, 1)"); + assert.sameValue(sample.includes(42n, 2), true, "includes(42, 2)"); + + assert.sameValue(sample.includes(42n, -4), true, "includes(42, -4)"); + assert.sameValue(sample.includes(42n, -3), true, "includes(42, -3)"); + assert.sameValue(sample.includes(42n, -2), true, "includes(42, -2)"); + assert.sameValue(sample.includes(42n, -5), true, "includes(42, -5)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/search-not-found-returns-false.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/search-not-found-returns-false.js new file mode 100644 index 0000000000..e99f8e0e56 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/search-not-found-returns-false.js @@ -0,0 +1,44 @@ +// 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-%typedarray%.prototype.includes +description: returns false if the element is not found +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n, 42n, 41n]); + assert.sameValue(sample.includes(44n), false, "includes(44)"); + assert.sameValue(sample.includes(43n, 2), false, "includes(43, 2)"); + assert.sameValue(sample.includes(42n, 3), false, "includes(42, 3)"); + assert.sameValue(sample.includes(44n, -4), false, "includes(44, -4)"); + assert.sameValue(sample.includes(44n, -5), false, "includes(44, -5)"); + assert.sameValue(sample.includes(42n, -1), false, "includes(42, -1)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/tointeger-fromindex.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/tointeger-fromindex.js new file mode 100644 index 0000000000..67e101024c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/BigInt/tointeger-fromindex.js @@ -0,0 +1,67 @@ +// 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-%typedarray%.prototype.includes +description: get the integer value from fromIndex +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n]); + assert.sameValue(sample.includes(42n, "1"), false, "string [0]"); + assert.sameValue(sample.includes(43n, "1"), true, "string [1]"); + + assert.sameValue(sample.includes(42n, true), false, "true [0]"); + assert.sameValue(sample.includes(43n, true), true, "true [1]"); + + assert.sameValue(sample.includes(42n, false), true, "false [0]"); + assert.sameValue(sample.includes(43n, false), true, "false [1]"); + + assert.sameValue(sample.includes(42n, NaN), true, "NaN [0]"); + assert.sameValue(sample.includes(43n, NaN), true, "NaN [1]"); + + assert.sameValue(sample.includes(42n, null), true, "null [0]"); + assert.sameValue(sample.includes(43n, null), true, "null [1]"); + + assert.sameValue(sample.includes(42n, undefined), true, "undefined [0]"); + assert.sameValue(sample.includes(43n, undefined), true, "undefined [1]"); + + assert.sameValue(sample.includes(42n, null), true, "null [0]"); + assert.sameValue(sample.includes(43n, null), true, "null [1]"); + + assert.sameValue(sample.includes(42n, obj), false, "object [0]"); + assert.sameValue(sample.includes(43n, obj), true, "object [1]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-false-for-zero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-false-for-zero.js new file mode 100644 index 0000000000..493f0bc00d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-false-for-zero.js @@ -0,0 +1,49 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: > + Returns false if buffer is detached after ValidateTypedArray and searchElement is a value +info: | + %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %TypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13. + + When the includes method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return false. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return false. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let elementK be the result of ! Get(O, ! ToString(F(k))). + If SameValueZero(searchElement, elementK) is true, return true. + Set k to k + 1. + Return false. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.includes(0, fromIndex), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-true-for-undefined.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-true-for-undefined.js new file mode 100644 index 0000000000..43ba9f0629 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-true-for-undefined.js @@ -0,0 +1,49 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: > + Returns true if buffer is detached after ValidateTypedArray and searchElement is undefined +info: | + %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %TypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13. + + When the includes method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return false. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return false. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let elementK be the result of ! Get(O, ! ToString(F(k))). + If SameValueZero(searchElement, elementK) is true, return true. + Set k to k + 1. + Return false. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.includes(undefined, fromIndex), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/detached-buffer.js new file mode 100644 index 0000000000..3d8dff1368 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/detached-buffer.js @@ -0,0 +1,30 @@ +// 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-%typedarray%.prototype.includes +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.includes(0); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js new file mode 100644 index 0000000000..4298fc7c08 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js @@ -0,0 +1,38 @@ +// 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-%typedarray%.prototype.includes +description: Return false if fromIndex >= ArrayLength +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... + 8. Return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(42); + assert.sameValue(sample.includes(0, 42), false); + assert.sameValue(sample.includes(0, 43), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/fromIndex-infinity.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/fromIndex-infinity.js new file mode 100644 index 0000000000..d067193aaa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/fromIndex-infinity.js @@ -0,0 +1,46 @@ +// 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-%typedarray%.prototype.includes +description: handle Infinity values for fromIndex +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + ... + 8. Return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 43, 41]); + + assert.sameValue( + sample.includes(43, Infinity), + false, + "includes(43, Infinity)" + ); + assert.sameValue( + sample.includes(43, -Infinity), + true, + "includes(43, -Infinity)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/fromIndex-minus-zero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/fromIndex-minus-zero.js new file mode 100644 index 0000000000..0bb301447f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/fromIndex-minus-zero.js @@ -0,0 +1,36 @@ +// 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-%typedarray%.prototype.includes +description: -0 fromIndex becomes 0 +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43]); + assert.sameValue(sample.includes(42, -0), true, "-0 [0]"); + assert.sameValue(sample.includes(43, -0), true, "-0 [1]"); + assert.sameValue(sample.includes(44, -0), false, "-0 [2]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000..b7a1f870a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.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-%typedarray%.prototype.includes +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", {value: 0}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7]); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.includes(7), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/invoked-as-func.js new file mode 100644 index 0000000000..d90cc7b111 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/invoked-as-func.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-%typedarray%.prototype.includes +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var includes = TypedArray.prototype.includes; + +assert.sameValue(typeof includes, "function"); + +assert.throws(TypeError, function() { + includes(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/invoked-as-method.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/invoked-as-method.js new file mode 100644 index 0000000000..0d138bfa6c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/invoked-as-method.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-%typedarray%.prototype.includes +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.includes, "function"); + +assert.throws(TypeError, function() { + TypedArrayPrototype.includes(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/length-zero-returns-false.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/length-zero-returns-false.js new file mode 100644 index 0000000000..ab59a078d7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/length-zero-returns-false.js @@ -0,0 +1,41 @@ +// 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-%typedarray%.prototype.includes +description: Returns false if length is 0 +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return false. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.includes(0), false, "returns false"); + assert.sameValue(sample.includes(), false, "returns false - no arg"); + assert.sameValue( + sample.includes(0, fromIndex), false, + "length is checked before ToInteger(fromIndex)" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/length.js new file mode 100644 index 0000000000..33e7547d6c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/length.js @@ -0,0 +1,32 @@ +// 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-%typedarray%.prototype.includes +description: > + %TypedArray%.prototype.includes.length is 1. +info: | + %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + 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, including optional + parameters. However, rest parameters 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, testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(TypedArray.prototype.includes.length, 1); + +verifyNotEnumerable(TypedArray.prototype.includes, "length"); +verifyNotWritable(TypedArray.prototype.includes, "length"); +verifyConfigurable(TypedArray.prototype.includes, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/name.js new file mode 100644 index 0000000000..a76942e846 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/name.js @@ -0,0 +1,29 @@ +// 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-%typedarray%.prototype.includes +description: > + %TypedArray%.prototype.includes.name is "includes". +info: | + %TypedArray%.prototype.includes (searchElement [ , fromIndex ] ) + + 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, testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(TypedArray.prototype.includes.name, "includes"); + +verifyNotEnumerable(TypedArray.prototype.includes, "name"); +verifyNotWritable(TypedArray.prototype.includes, "name"); +verifyConfigurable(TypedArray.prototype.includes, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/not-a-constructor.js new file mode 100644 index 0000000000..726d7ec28f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/not-a-constructor.js @@ -0,0 +1,35 @@ +// 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: > + TypedArray.prototype.includes 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, testTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(TypedArray.prototype.includes), + false, + 'isConstructor(TypedArray.prototype.includes) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.includes(1); +}, '`let u8 = new Uint8Array(1); new u8.includes(1)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/prop-desc.js new file mode 100644 index 0000000000..3931bd6be2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/prop-desc.js @@ -0,0 +1,21 @@ +// 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-%typedarray%.prototype.includes +description: > + "includes" property of TypedArrayPrototype +info: | + ES6 section 17: 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, testTypedArray.js] +features: [TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, "includes"); +verifyWritable(TypedArrayPrototype, "includes"); +verifyConfigurable(TypedArrayPrototype, "includes"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..eba3b912b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: Return abrupt when "this" value fails buffer boundary checks +includes: [testTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.includes, + 'function', + 'implements TypedArray.prototype.includes' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.includes(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.includes(0); + + var expectedError; + try { + ab.resize(BPE * 2); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the includes operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.includes(0); + throw new Test262Error('includes completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 0000000000..495c48b1a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.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-%typedarray%.prototype.includes +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7]); + + assert.throws(TypeError, function() { + sample.includes(7, fromIndex); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js new file mode 100644 index 0000000000..ee5c08f7df --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js @@ -0,0 +1,39 @@ +// 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-%typedarray%.prototype.includes +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7]); + + assert.throws(Test262Error, function() { + sample.includes(7, fromIndex); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/samevaluezero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/samevaluezero.js new file mode 100644 index 0000000000..6b7438d7ce --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/samevaluezero.js @@ -0,0 +1,46 @@ +// 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-%typedarray%.prototype.includes +description: search element is compared using SameValueZero +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 0, 1, undefined]); + assert.sameValue(sample.includes(), false, "no arg"); + assert.sameValue(sample.includes(undefined), false, "undefined"); + assert.sameValue(sample.includes("42"), false, "'42'"); + assert.sameValue(sample.includes([42]), false, "[42]"); + assert.sameValue(sample.includes(42.0), true, "42.0"); + assert.sameValue(sample.includes(-0), true, "-0"); + assert.sameValue(sample.includes(true), false, "true"); + assert.sameValue(sample.includes(false), false, "false"); + assert.sameValue(sample.includes(null), false, "null"); + assert.sameValue(sample.includes(""), false, "empty string"); +}); + +testWithTypedArrayConstructors(function(FloatArray) { + var sample = new FloatArray([42, 0, 1, undefined, NaN]); + assert.sameValue(sample.includes(NaN), true, "NaN"); +}, [Float32Array, Float64Array]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/search-found-returns-true.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/search-found-returns-true.js new file mode 100644 index 0000000000..7d2cf925b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/search-found-returns-true.js @@ -0,0 +1,46 @@ +// 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-%typedarray%.prototype.includes +description: returns true for found index +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 42, 41]); + assert.sameValue(sample.includes(42), true, "includes(42)"); + assert.sameValue(sample.includes(43), true, "includes(43)"); + assert.sameValue(sample.includes(43, 1), true, "includes(43, 1)"); + assert.sameValue(sample.includes(42, 1), true, "includes(42, 1)"); + assert.sameValue(sample.includes(42, 2), true, "includes(42, 2)"); + + assert.sameValue(sample.includes(42, -4), true, "includes(42, -4)"); + assert.sameValue(sample.includes(42, -3), true, "includes(42, -3)"); + assert.sameValue(sample.includes(42, -2), true, "includes(42, -2)"); + assert.sameValue(sample.includes(42, -5), true, "includes(42, -5)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/search-not-found-returns-false.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/search-not-found-returns-false.js new file mode 100644 index 0000000000..f647deebf9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/search-not-found-returns-false.js @@ -0,0 +1,44 @@ +// 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-%typedarray%.prototype.includes +description: returns false if the element is not found +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43, 42, 41]); + assert.sameValue(sample.includes(44), false, "includes(44)"); + assert.sameValue(sample.includes(43, 2), false, "includes(43, 2)"); + assert.sameValue(sample.includes(42, 3), false, "includes(42, 3)"); + assert.sameValue(sample.includes(44, -4), false, "includes(44, -4)"); + assert.sameValue(sample.includes(44, -5), false, "includes(44, -5)"); + assert.sameValue(sample.includes(42, -1), false, "includes(42, -1)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/searchelement-not-integer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/searchelement-not-integer.js new file mode 100644 index 0000000000..22d65b5c0b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/searchelement-not-integer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Google. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: Check that search element is not coerced if not an integer +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the same algorithm as Array.prototype.includes as defined in 22.1.3.13 + + 22.1.3.13 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + 8. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(10); + function throwFunc(){ + throw Test262Error() + return 0; + } + + assert.sameValue(sample.includes({valueOf : throwFunc}), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/this-is-not-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/this-is-not-object.js new file mode 100644 index 0000000000..ffaadb48fc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/this-is-not-object.js @@ -0,0 +1,52 @@ +// 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-%typedarray%.prototype.includes +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var includes = TypedArray.prototype.includes; + +assert.throws(TypeError, function() { + includes.call(undefined, 42); +}, "this is undefined"); + +assert.throws(TypeError, function() { + includes.call(null, 42); +}, "this is null"); + +assert.throws(TypeError, function() { + includes.call(42, 42); +}, "this is 42"); + +assert.throws(TypeError, function() { + includes.call("1", 42); +}, "this is a string"); + +assert.throws(TypeError, function() { + includes.call(true, 42); +}, "this is true"); + +assert.throws(TypeError, function() { + includes.call(false, 42); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + includes.call(s, 42); +}, "this is a Symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/this-is-not-typedarray-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000..3a7d86dcd3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/this-is-not-typedarray-instance.js @@ -0,0 +1,44 @@ +// 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-%typedarray%.prototype.includes +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var includes = TypedArray.prototype.includes; + +assert.throws(TypeError, function() { + includes.call({}, 42); +}, "this is an Object"); + +assert.throws(TypeError, function() { + includes.call([], 42); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + includes.call(ab, 42); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + includes.call(dv, 42); +}, "this is a DataView instance"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/includes/tointeger-fromindex.js b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/tointeger-fromindex.js new file mode 100644 index 0000000000..ad25ab47d7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/includes/tointeger-fromindex.js @@ -0,0 +1,67 @@ +// 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-%typedarray%.prototype.includes +description: get the integer value from fromIndex +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43]); + assert.sameValue(sample.includes(42, "1"), false, "string [0]"); + assert.sameValue(sample.includes(43, "1"), true, "string [1]"); + + assert.sameValue(sample.includes(42, true), false, "true [0]"); + assert.sameValue(sample.includes(43, true), true, "true [1]"); + + assert.sameValue(sample.includes(42, false), true, "false [0]"); + assert.sameValue(sample.includes(43, false), true, "false [1]"); + + assert.sameValue(sample.includes(42, NaN), true, "NaN [0]"); + assert.sameValue(sample.includes(43, NaN), true, "NaN [1]"); + + assert.sameValue(sample.includes(42, null), true, "null [0]"); + assert.sameValue(sample.includes(43, null), true, "null [1]"); + + assert.sameValue(sample.includes(42, undefined), true, "undefined [0]"); + assert.sameValue(sample.includes(43, undefined), true, "undefined [1]"); + + assert.sameValue(sample.includes(42, null), true, "null [0]"); + assert.sameValue(sample.includes(43, null), true, "null [1]"); + + assert.sameValue(sample.includes(42, obj), false, "object [0]"); + assert.sameValue(sample.includes(43, obj), true, "object [1]"); +}); + +reportCompare(0, 0); |