Skip to content

Commit c9a8bbd

Browse files
osa1Commit Queue
authored andcommitted
[dart2wasm] Fix JSCM String.fromCharCodes
Fixes test corelib/string_fromcharcodes_test in JSCM. Change-Id: I9c2a1b7f67819c193a98b00932328571303589fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392901 Commit-Queue: Ömer Ağacan <[email protected]> Reviewed-by: Slava Egorov <[email protected]>
1 parent 66a2ecd commit c9a8bbd

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

sdk/lib/_internal/wasm_js_compatibility/lib/string_patch.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class String {
1515
@patch
1616
factory String.fromCharCodes(Iterable<int> charCodes,
1717
[int start = 0, int? end]) {
18-
final length = charCodes.length;
19-
20-
RangeError.checkValueInInterval(start, 0, length);
21-
18+
RangeError.checkNotNegative(start, "start");
2219
if (end != null) {
23-
RangeError.checkValueInInterval(end, start, length);
20+
if (end < start) {
21+
throw RangeError.range(end, start, null, "end");
22+
}
23+
if (end == start) return "";
2424
}
2525

2626
// Skip until `start`.
@@ -32,14 +32,15 @@ class String {
3232
// The part of the iterable converted to string is collected in a JS typed
3333
// array, to be able to effciently get subarrays, to pass to
3434
// `String.fromCharCode.apply`.
35-
final charCodesLength = (end ?? length) - start;
35+
final charCodesLength = (end ?? charCodes.length) - start;
36+
if (charCodesLength <= 0) return "";
3637
final typedArrayLength = charCodesLength * 2;
3738
final list = JSUint32ArrayImpl(typedArrayLength);
3839
int index = 0; // index in `list`.
3940
end ??= start + charCodesLength;
4041
for (int i = start; i < end; i++) {
4142
if (!it.moveNext()) {
42-
throw RangeError.range(end, start, i);
43+
break;
4344
}
4445
final charCode = it.current;
4546
if (charCode >= 0 && charCode <= 0xffff) {

0 commit comments

Comments
 (0)