summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js')
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js
new file mode 100644
index 0000000000..6d4460d294
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-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.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);
+});
+
+reportCompare(0, 0);