mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
[dart2wasm] Fix string fromCharCodes
for some unicode surrogate pairs.
Change-Id: Id6ceb12057a1e5a419eb7fc30b6995aed8159321 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265620 Commit-Queue: Ömer Ağacan <omersa@google.com> Reviewed-by: Ömer Ağacan <omersa@google.com>
This commit is contained in:
parent
79405df629
commit
97bcffb7c7
|
@ -22,6 +22,14 @@ class ClassID {
|
|||
external static int get cidFunction;
|
||||
@pragma("wasm:class-id", "dart.core#_Function")
|
||||
external static int get cid_Function;
|
||||
@pragma("wasm:class-id", "dart.core#_List")
|
||||
external static int get cidFixedLengthList;
|
||||
@pragma("wasm:class-id", "dart.core#_ListBase")
|
||||
external static int get cidListBase;
|
||||
@pragma("wasm:class-id", "dart.core#_GrowableList")
|
||||
external static int get cidGrowableList;
|
||||
@pragma("wasm:class-id", "dart.core#_ImmutableList")
|
||||
external static int get cidImmutableList;
|
||||
|
||||
// Class IDs for RTI Types.
|
||||
@pragma("wasm:class-id", "dart.core#_NeverType")
|
||||
|
|
|
@ -125,6 +125,11 @@ abstract class _StringBase implements String {
|
|||
static String createFromCharCodes(
|
||||
Iterable<int> charCodes, int start, int? end, int? limit) {
|
||||
// TODO(srdjan): Also skip copying of wide typed arrays.
|
||||
final ccid = ClassID.getID(charCodes);
|
||||
if (ccid != ClassID.cidFixedLengthList &&
|
||||
ccid != ClassID.cidListBase &&
|
||||
ccid != ClassID.cidGrowableList &&
|
||||
ccid != ClassID.cidImmutableList) {
|
||||
if (charCodes is Uint8List) {
|
||||
final actualEnd =
|
||||
RangeError.checkValidRange(start, end, charCodes.length);
|
||||
|
@ -132,6 +137,7 @@ abstract class _StringBase implements String {
|
|||
} else if (charCodes is! Uint16List) {
|
||||
return _createStringFromIterable(charCodes, start, end);
|
||||
}
|
||||
}
|
||||
final int codeCount = charCodes.length;
|
||||
final actualEnd = RangeError.checkValidRange(start, end, codeCount);
|
||||
final len = actualEnd - start;
|
||||
|
@ -172,11 +178,8 @@ abstract class _StringBase implements String {
|
|||
if (charCodes is EfficientLengthIterable) {
|
||||
int length = charCodes.length;
|
||||
final endVal = RangeError.checkValidRange(start, end, length);
|
||||
final Uint16List charCodeList = Uint16List(endVal - start);
|
||||
int i = 0;
|
||||
for (final char in charCodes.take(endVal).skip(start)) {
|
||||
charCodeList[i++] = char;
|
||||
}
|
||||
final charCodeList =
|
||||
List<int>.from(charCodes.take(endVal).skip(start), growable: false);
|
||||
return createFromCharCodes(charCodeList, 0, charCodeList.length, null);
|
||||
}
|
||||
// Don't know length of iterable, so iterate and see if all the values
|
||||
|
|
Loading…
Reference in a new issue