Parent: #473 Depends on: #622 (complete) Related: #493
Problem
String.prototype.indexOf and lastIndexOf clamped and reported UTF-16 positions, but their actual match was a raw WTF-8 byte substring search. A high or low surrogate needle therefore could not match its corresponding code unit inside an astral scalar, and a start/limit inside a surrogate pair was mapped to a whole-sequence byte boundary that could admit or exclude the wrong candidate. #622 established the shared exact forward matcher for the predicate methods; this child owns the numeric-returning methods and reverse/limited search.
Scope
- Reuse the exact UTF-16 matcher boundary from #622 for
indexOf. - Add a bounded-linear last-match search whose candidate start is at or before the specified UTF-16 limit.
- Preserve ToString/ToNumber order, NaN/default handling, empty-needle results, ASCII allocation-free matching, lone surrogates, and OOM propagation.
- Keep byte-offset conversion only where representation invariants prove it equivalent to code-unit indexing.
No-workaround rules
- No code-point comparison, normalization, replacement characters, repeated random-access decoding, ASCII-only acceptance, or raw-byte result correction after an inexact search.
Acceptance
- Unit fixtures cover BMP, astral halves, lone surrogates, empty needles, start/limit boundaries, overlap, and coercion order.
indexOfandlastIndexOfreturn exact UTF-16 code-unit indices with bounded-linear non-ASCII work.- Relevant Test262 subtrees have nonzero exact before → after accounting with no regressions.
- Focused/full units and applicable sanitizer gates pass; #473 and #622 are cross-linked.