Skip to content

Commit 3d99ff6

Browse files
committed
Bug 1965844 - Part 4: Correctly update search index for resized typed array in lastIndexOf. r=jandem
Test case in <tc39/test262#4477>. Differential Revision: https://phabricator.services.mozilla.com/D248929 UltraBlame original commit: 192b5d74f9ca4a7594142bf8fd789e2d5ab20b9c
1 parent 4f22f4e commit 3d99ff6

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

js/src/vm/TypedArrayObject.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,16 +2530,6 @@ static bool TypedArray_lastIndexOf(JSContext* cx, const CallArgs& args) {
25302530
}
25312531

25322532

2533-
2534-
len = std::min(len, tarray->length().valueOr(0));
2535-
2536-
2537-
if (len == 0) {
2538-
args.rval().setInt32(-1);
2539-
return true;
2540-
}
2541-
2542-
25432533
if (fromIndex >= 0) {
25442534
k = size_t(std::min(fromIndex, double(len - 1)));
25452535
} else {
@@ -2550,6 +2540,24 @@ static bool TypedArray_lastIndexOf(JSContext* cx, const CallArgs& args) {
25502540
}
25512541
k = size_t(d);
25522542
}
2543+
MOZ_ASSERT(k < len);
2544+
2545+
2546+
2547+
size_t currentLength = tarray->length().valueOr(0);
2548+
2549+
2550+
if (currentLength < len) {
2551+
2552+
if (currentLength == 0) {
2553+
args.rval().setInt32(-1);
2554+
return true;
2555+
}
2556+
2557+
2558+
k = std::min(k, currentLength - 1);
2559+
len = currentLength;
2560+
}
25532561
}
25542562
MOZ_ASSERT(k < len);
25552563

0 commit comments

Comments
 (0)