From de091de9f6aeed634df7359d45bd186fa7570aff Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Fri, 11 Dec 2020 11:03:40 -0500 Subject: [PATCH] Include indexOf(undefined, ...) and lastIndexOf(undefined, ...) --- ...omIndex-returns-minus-one-for-undefined.js | 49 +++++++++++++++++++ ...g-fromIndex-returns-minus-one-for-zero.js} | 0 ...omIndex-returns-minus-one-for-undefined.js | 49 +++++++++++++++++++ ...g-fromIndex-returns-minus-one-for-zero.js} | 0 ...omIndex-returns-minus-one-for-undefined.js | 46 +++++++++++++++++ ...g-fromIndex-returns-minus-one-for-zero.js} | 0 ...omIndex-returns-minus-one-for-undefined.js | 46 +++++++++++++++++ ...g-fromIndex-returns-minus-one-for-zero.js} | 0 8 files changed, 190 insertions(+) create mode 100644 test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js rename test/built-ins/TypedArray/prototype/indexOf/BigInt/{detached-buffer-during-fromIndex-returns-minus-one.js => detached-buffer-during-fromIndex-returns-minus-one-for-zero.js} (100%) create mode 100644 test/built-ins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js rename test/built-ins/TypedArray/prototype/indexOf/{detached-buffer-during-fromIndex-returns-minus-one.js => detached-buffer-during-fromIndex-returns-minus-one-for-zero.js} (100%) create mode 100644 test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js rename test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/{detached-buffer-during-fromIndex-returns-minus-one.js => detached-buffer-during-fromIndex-returns-minus-one-for-zero.js} (100%) create mode 100644 test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js rename test/built-ins/TypedArray/prototype/lastIndexOf/{detached-buffer-during-fromIndex-returns-minus-one.js => detached-buffer-during-fromIndex-returns-minus-one-for-zero.js} (100%) diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js new file mode 100644 index 0000000000..b147acc92e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-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.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(undefined, fromIndex), -1); +}); 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-for-zero.js similarity index 100% rename from test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one.js rename to test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js diff --git a/test/built-ins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js b/test/built-ins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js new file mode 100644 index 0000000000..afc2df938d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-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.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(undefined, 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-for-zero.js similarity index 100% rename from test/built-ins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one.js rename to test/built-ins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js new file mode 100644 index 0000000000..327965c0e6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.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(undefined, fromIndex), -1); +}); 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-for-zero.js similarity index 100% rename from test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one.js rename to test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js b/test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js new file mode 100644 index 0000000000..0f8094e221 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.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(undefined, 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-for-zero.js similarity index 100% rename from test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one.js rename to test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js