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;
|
external static int get cidFunction;
|
||||||
@pragma("wasm:class-id", "dart.core#_Function")
|
@pragma("wasm:class-id", "dart.core#_Function")
|
||||||
external static int get cid_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.
|
// Class IDs for RTI Types.
|
||||||
@pragma("wasm:class-id", "dart.core#_NeverType")
|
@pragma("wasm:class-id", "dart.core#_NeverType")
|
||||||
|
|
|
@ -125,12 +125,18 @@ abstract class _StringBase implements String {
|
||||||
static String createFromCharCodes(
|
static String createFromCharCodes(
|
||||||
Iterable<int> charCodes, int start, int? end, int? limit) {
|
Iterable<int> charCodes, int start, int? end, int? limit) {
|
||||||
// TODO(srdjan): Also skip copying of wide typed arrays.
|
// TODO(srdjan): Also skip copying of wide typed arrays.
|
||||||
if (charCodes is Uint8List) {
|
final ccid = ClassID.getID(charCodes);
|
||||||
final actualEnd =
|
if (ccid != ClassID.cidFixedLengthList &&
|
||||||
RangeError.checkValidRange(start, end, charCodes.length);
|
ccid != ClassID.cidListBase &&
|
||||||
return _createOneByteString(charCodes, start, actualEnd - start);
|
ccid != ClassID.cidGrowableList &&
|
||||||
} else if (charCodes is! Uint16List) {
|
ccid != ClassID.cidImmutableList) {
|
||||||
return _createStringFromIterable(charCodes, start, end);
|
if (charCodes is Uint8List) {
|
||||||
|
final actualEnd =
|
||||||
|
RangeError.checkValidRange(start, end, charCodes.length);
|
||||||
|
return _createOneByteString(charCodes, start, actualEnd - start);
|
||||||
|
} else if (charCodes is! Uint16List) {
|
||||||
|
return _createStringFromIterable(charCodes, start, end);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final int codeCount = charCodes.length;
|
final int codeCount = charCodes.length;
|
||||||
final actualEnd = RangeError.checkValidRange(start, end, codeCount);
|
final actualEnd = RangeError.checkValidRange(start, end, codeCount);
|
||||||
|
@ -172,11 +178,8 @@ abstract class _StringBase implements String {
|
||||||
if (charCodes is EfficientLengthIterable) {
|
if (charCodes is EfficientLengthIterable) {
|
||||||
int length = charCodes.length;
|
int length = charCodes.length;
|
||||||
final endVal = RangeError.checkValidRange(start, end, length);
|
final endVal = RangeError.checkValidRange(start, end, length);
|
||||||
final Uint16List charCodeList = Uint16List(endVal - start);
|
final charCodeList =
|
||||||
int i = 0;
|
List<int>.from(charCodes.take(endVal).skip(start), growable: false);
|
||||||
for (final char in charCodes.take(endVal).skip(start)) {
|
|
||||||
charCodeList[i++] = char;
|
|
||||||
}
|
|
||||||
return createFromCharCodes(charCodeList, 0, charCodeList.length, null);
|
return createFromCharCodes(charCodeList, 0, charCodeList.length, null);
|
||||||
}
|
}
|
||||||
// Don't know length of iterable, so iterate and see if all the values
|
// Don't know length of iterable, so iterate and see if all the values
|
||||||
|
|
Loading…
Reference in a new issue