diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-false-for-zero.js b/test/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-false-for-zero.js new file mode 100644 index 0000000000..286a0e4e36 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-false-for-zero.js @@ -0,0 +1,46 @@ +// 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); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-true-for-undefined.js b/test/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-true-for-undefined.js new file mode 100644 index 0000000000..329985324f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-true-for-undefined.js @@ -0,0 +1,47 @@ +// 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); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-false-for-zero.js b/test/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-false-for-zero.js new file mode 100644 index 0000000000..6ac449e9a1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-false-for-zero.js @@ -0,0 +1,47 @@ +// 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); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-true-for-undefined.js b/test/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-true-for-undefined.js new file mode 100644 index 0000000000..e524e28759 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-true-for-undefined.js @@ -0,0 +1,47 @@ +// 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); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/detached-buffer-tointeger.js b/test/built-ins/TypedArray/prototype/includes/detached-buffer-tointeger.js deleted file mode 100644 index 9eebb34c2e..0000000000 --- a/test/built-ins/TypedArray/prototype/includes/detached-buffer-tointeger.js +++ /dev/null @@ -1,37 +0,0 @@ -// 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: > - Does not throw a TypeError if this has a detached buffer after index coercion, - because ValidateTypedArray has already successfully completed. - -info: | - 22.2.3.14 %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). - ... - -includes: [testTypedArray.js, detachArrayBuffer.js] -features: [align-detached-buffer-semantics-with-web-reality, TypedArray] ----*/ - -testWithTypedArrayConstructors(function(TA) { - const sample = new TA(10); - let isDetached = false; - function valueOf(){ - $DETACHBUFFER(sample.buffer); - isDetached = true; - return 0; - } - assert.sameValue(sample.includes(0, {valueOf}), false); - assert.sameValue(isDetached, true); -}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one.js new file mode 100644 index 0000000000..b357ad216b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one.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.indexof +description: Throws a TypeError if this has a detached buffer +info: | + %TypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %TypedArray%.prototype.indexOf are the same as for Array.prototype.indexOf as defined in 22.1.3.14. + + When the indexOf 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 -1F. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return -1F. + 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 kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k + 1. + Return -1F. + +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.indexOf(0n, fromIndex), -1); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one.js b/test/built-ins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one.js new file mode 100644 index 0000000000..4dc25bf11b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one.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.indexof +description: Returns -1 if buffer is detached after ValidateTypedArray +info: | + %TypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %TypedArray%.prototype.indexOf are the same as for Array.prototype.indexOf as defined in 22.1.3.14. + + When the indexOf 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 -1F. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return -1F. + 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 kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k + 1. + Return -1F. + +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.indexOf(0, fromIndex), -1); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js b/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js new file mode 100644 index 0000000000..7b1e6e67a1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js @@ -0,0 +1,42 @@ +// 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.join +description: Returns single separator if buffer is detached after ValidateTypedArray +info: | + %TypedArray%.prototype.join ( separator ) + + The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. + + When the join method is called with one argument separator, the following steps are taken: + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + If separator is undefined, let sep be the single-element String ",". + Else, let sep be ? ToString(separator). + Let R be the empty String. + Let k be 0. + Repeat, while k < len, + If k > 0, set R to the string-concatenation of R and sep. + Let element be ! Get(O, ! ToString(𝔽(k))). + If element is undefined or null, let next be the empty String; otherwise, let next be ! ToString(element). + Set R to the string-concatenation of R and next. + Set k to k + 1. + Return R. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA([1n,2n,3n]); + const separator = { + toString() { + $DETACHBUFFER(sample.buffer); + return ','; + } + }; + + assert.sameValue(sample.join(separator), ',,'); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js index 1af7ae94c5..e4c91a5409 100644 --- a/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js +++ b/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js @@ -4,31 +4,30 @@ esid: sec-%typedarray%.prototype.join description: Throws a TypeError if this has a detached buffer info: | - 22.2.3.15 %TypedArray%.prototype.join ( separator ) + %TypedArray%.prototype.join ( separator ) - 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. + The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. - 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + When the join method is called with one argument separator, the following steps are taken: + Let O be the this value. + Perform ? ValidateTypedArray(O). ... - 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - ... + includes: [testBigIntTypedArray.js, detachArrayBuffer.js] features: [BigInt, TypedArray] ---*/ -var obj = { - toString: function() { +let obj = { + toString() { throw new Test262Error(); } }; testWithBigIntTypedArrayConstructors(function(TA) { - var sample = new TA(1); + let sample = new TA(1); $DETACHBUFFER(sample.buffer); - assert.throws(TypeError, function() { + assert.throws(TypeError, () => { sample.join(obj); }); }); diff --git a/test/built-ins/TypedArray/prototype/join/detached-buffer-during-fromIndex-returns-single-comma.js b/test/built-ins/TypedArray/prototype/join/detached-buffer-during-fromIndex-returns-single-comma.js new file mode 100644 index 0000000000..e1edd3a519 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/detached-buffer-during-fromIndex-returns-single-comma.js @@ -0,0 +1,42 @@ +// 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.join +description: Returns single separator if buffer is detached after ValidateTypedArray +info: | + %TypedArray%.prototype.join ( separator ) + + The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. + + When the join method is called with one argument separator, the following steps are taken: + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + If separator is undefined, let sep be the single-element String ",". + Else, let sep be ? ToString(separator). + Let R be the empty String. + Let k be 0. + Repeat, while k < len, + If k > 0, set R to the string-concatenation of R and sep. + Let element be ! Get(O, ! ToString(𝔽(k))). + If element is undefined or null, let next be the empty String; otherwise, let next be ! ToString(element). + Set R to the string-concatenation of R and next. + Set k to k + 1. + Return R. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA([1,2,3]); + const separator = { + toString() { + $DETACHBUFFER(sample.buffer); + return ','; + } + }; + + assert.sameValue(sample.join(separator), ',,'); +}); diff --git a/test/built-ins/TypedArray/prototype/join/detached-buffer.js b/test/built-ins/TypedArray/prototype/join/detached-buffer.js index b737c9f91a..0d78c2b091 100644 --- a/test/built-ins/TypedArray/prototype/join/detached-buffer.js +++ b/test/built-ins/TypedArray/prototype/join/detached-buffer.js @@ -4,31 +4,30 @@ esid: sec-%typedarray%.prototype.join description: Throws a TypeError if this has a detached buffer info: | - 22.2.3.15 %TypedArray%.prototype.join ( separator ) + %TypedArray%.prototype.join ( separator ) - 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. + The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. - 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + When the join method is called with one argument separator, the following steps are taken: + Let O be the this value. + Perform ? ValidateTypedArray(O). ... - 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - ... + includes: [testTypedArray.js, detachArrayBuffer.js] features: [TypedArray] ---*/ -var obj = { - toString: function() { +let obj = { + toString() { throw new Test262Error(); } }; testWithTypedArrayConstructors(function(TA) { - var sample = new TA(1); + let sample = new TA(1); $DETACHBUFFER(sample.buffer); - assert.throws(TypeError, function() { + assert.throws(TypeError, () => { sample.join(obj); }); }); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one.js new file mode 100644 index 0000000000..16fef1d6ae --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one.js @@ -0,0 +1,46 @@ +// 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.lastindexof +description: Returns -1 if buffer is detached after ValidateTypedArray +info: | + %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %TypedArray%.prototype.lastIndexOf are the same as for Array.prototype.lastIndexOf as defined in 22.1.3.17. + + When the lastIndexOf 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 -1F. + If fromIndex is present, let n be ? ToIntegerOrInfinity(fromIndex); else let n be len - 1. + If n is -∞, return -1F. + If n ≥ 0, then + Let k be min(n, len - 1). + Else, + Let k be len + n. + Repeat, while k ≥ 0, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k - 1. + Return -1F. + +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.lastIndexOf(0n, fromIndex), -1); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one.js b/test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one.js new file mode 100644 index 0000000000..90096ada09 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one.js @@ -0,0 +1,46 @@ +// 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.lastindexof +description: Returns -1 if buffer is detached after ValidateTypedArray +info: | + %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %TypedArray%.prototype.lastIndexOf are the same as for Array.prototype.lastIndexOf as defined in 22.1.3.17. + + When the lastIndexOf 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 -1F. + If fromIndex is present, let n be ? ToIntegerOrInfinity(fromIndex); else let n be len - 1. + If n is -∞, return -1F. + If n ≥ 0, then + Let k be min(n, len - 1). + Else, + Let k be len + n. + Repeat, while k ≥ 0, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k - 1. + Return -1F. + +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.lastIndexOf(0, fromIndex), -1); +}); diff --git a/test/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js b/test/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js index c708844a40..6c2ce33e12 100644 --- a/test/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js +++ b/test/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js @@ -30,6 +30,7 @@ testWithTypedArrayConstructors(function(TA) { let sample = new TA([42]); $DETACHBUFFER(sample.buffer); sample[0] = 1; + assert.sameValue(sample[0], undefined, '`sample[0] = 1` is undefined'); sample['1.1'] = 1; assert.sameValue(sample['1.1'], undefined, '`sample[\'1.1\'] = 1` is undefined');