Repository navigation
fix(ecmascript): fold string methods by UTF-16 code units - #26752
Merged
Merged
Conversation
This was referenced Sep 17, 2026
Member
Author
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
3 times, most recently
from
September 17, 2026 04:14
8420254 to
1e90e0d
Compare
This was referenced Sep 17, 2026
Merged
Dunqing
force-pushed
the
jsstr-encode-utf16-size-hint
branch
from
September 18, 2026 02:20
92954b0 to
e6fef16
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
2 times, most recently
from
September 18, 2026 15:15
d29d07b to
ca3e24e
Compare
Dunqing
force-pushed
the
jsstr-encode-utf16-size-hint
branch
from
September 18, 2026 15:15
e6fef16 to
81912e4
Compare
Dunqing
force-pushed
the
jsstr-encode-utf16-size-hint
branch
from
September 21, 2026 01:14
5615ee7 to
e9e1efe
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
from
September 21, 2026 01:14
ee9b3b7 to
3df1998
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
from
September 21, 2026 01:48
caada83 to
871acbe
Compare
Dunqing
force-pushed
the
jsstr-encode-utf16-size-hint
branch
2 times, most recently
from
September 21, 2026 01:54
0689ee9 to
ab69599
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
from
September 21, 2026 01:54
871acbe to
bbae803
Compare
Dunqing
force-pushed
the
jsstr-encode-utf16-size-hint
branch
from
September 21, 2026 02:54
ab69599 to
6d6357e
Compare
Dunqing
force-pushed
the
jsstr-estree-escape-table
branch
2 times, most recently
from
September 22, 2026 02:41
a2e3fd0 to
21771a1
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
2 times, most recently
from
September 22, 2026 04:12
4013fd9 to
761e789
Compare
Dunqing
force-pushed
the
jsstr-estree-escape-table
branch
2 times, most recently
from
September 22, 2026 08:20
14a0af9 to
40d03e5
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
2 times, most recently
from
September 23, 2026 01:55
5c24f47 to
a92bf91
Compare
Dunqing
force-pushed
the
jsstr-estree-escape-table
branch
2 times, most recently
from
September 23, 2026 02:19
7597f5a to
dc17203
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
from
September 23, 2026 02:19
a92bf91 to
805fbe7
Compare
Dunqing
force-pushed
the
jsstr-estree-escape-table
branch
from
September 23, 2026 02:24
dc17203 to
bab6a6d
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
2 times, most recently
from
September 23, 2026 02:55
fde800f to
5c35c20
Compare
Dunqing
force-pushed
the
jsstr-estree-escape-table
branch
from
September 23, 2026 02:55
bab6a6d to
1bcb751
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
from
September 23, 2026 03:14
5c35c20 to
68650e3
Compare
Dunqing
force-pushed
the
jsstr-estree-escape-table
branch
from
September 23, 2026 03:14
1bcb751 to
301441e
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
from
September 23, 2026 07:22
68650e3 to
f6d2e81
Compare
Dunqing
force-pushed
the
jsstr-estree-escape-table
branch
from
September 23, 2026 07:22
301441e to
4e50dd5
Compare
Dunqing
force-pushed
the
jsstr-utf16-string-folds
branch
from
September 27, 2026 06:37
f6d2e81 to
8d1a725
Compare
Dunqing
force-pushed
the
jsstr-estree-escape-table
branch
from
September 27, 2026 06:37
4e50dd5 to
5c1efa5
Compare
graphite-app Bot
pushed a commit
that referenced
this pull request
Oct 19, 2026
String indexing now folds by UTF-16 code unit, so `"😀"[0]` folds to `"\uD83D"` and `"a\uD800b"[1]` to `"\uD800"`. The result is built with `JSStrBuilder` instead of a temporary heap string; ordinary strings keep the native UTF-8 path. Closes #26636. Based on #26717. Part of #26242. Continues #26752. Implemented with AI assistance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Continued in #27096. GitHub marked this PR indirectly merged during stack reordering; the change has not landed in
main.The
indexOf,lastIndexOf,slice, andsubstringfolds indexed strings by Rust character and byte offset, but JavaScript string positions are UTF-16 code units, so any astral character made the folded value wrong:"a😀b".indexOf("b")folded to 5 instead of 3,"a😀b".slice(1, 3)to the wrong text, and"a😀b".substring(3, 4)to the empty string. The rewrite also surfaced two adjacent numeric bugs: a position beyond the 32-bit range wrapped to a small index, folding"aa".indexOf("a", 3e9)to 0 instead of -1, and a NaNlastIndexOfposition searched from the start instead of the end.Search, clamp, and slice over the encoded code units, converting positions per ToIntegerOrInfinity. The searches stay over bytes, since a UTF-8 match can only begin on a character boundary; only the positions at the edges convert, so no fold allocates, and a folded
sliceorsubstringborrows the arena string. A boundary that falls inside a surrogate pair has no Rust string representation, so the fold declines those ranges. A NaN end also declines, since after evaluation it is indistinguishable fromundefined, which means the opposite boundary.charAt,charCodeAt, string indexing, andlengthalready counted code units and are untouched. TheStringSubstringtrait is removed: the fold slices the arena string directly and no other caller existed. Removing a public trait is a breaking change tooxc_ecmascript.Example
Before minification folds this to
5 "😀b" ""; node prints3 "😀" "b", and the minified output now matches node exactly. A result that would split the emoji, such as"a😀b".substring(1, 2), stays unfolded.Verified against node with a generated corpus of 2,408 method calls over ASCII, multi-byte, astral, and lone-surrogate haystacks, an independent review oracle of 9,160 cases, byte-identical minify-twice output, an unchanged minification size snapshot, a full conformance run with zero drift, and the crate test suites.
Ninth PR in the JSStr stack, based on #26743. Part of #26242.
Implemented with AI assistance.