Index: sdk/lib/_internal/compiler/js_lib/core_patch.dart |
diff --git a/sdk/lib/_internal/compiler/js_lib/core_patch.dart b/sdk/lib/_internal/compiler/js_lib/core_patch.dart |
index 29ee7787287406b79905d8f436547aa66d6ec302..3fe172b646c748ea6c5f2a2bfc0ff4fefa7fd81a 100644 |
--- a/sdk/lib/_internal/compiler/js_lib/core_patch.dart |
+++ b/sdk/lib/_internal/compiler/js_lib/core_patch.dart |
@@ -14,6 +14,8 @@ import 'dart:_js_helper' show patch, |
stringJoinUnchecked, |
objectHashCode; |
+import 'dart:_native_typed_data' show NativeUint8List; |
+ |
String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); |
_symbolMapToStringMap(Map<Symbol, dynamic> map) { |
@@ -275,26 +277,14 @@ class String { |
@patch |
factory String.fromCharCodes(Iterable<int> charCodes, |
[int start = 0, int end]) { |
- // If possible, recognize typed lists too. |
- if (charCodes is! JSArray) { |
- return _stringFromIterable(charCodes, start, end); |
- } |
- List list = charCodes; |
- int len = list.length; |
- if (start < 0 || start > len) { |
- throw new RangeError.range(start, 0, len); |
+ if (charCodes is JSArray) { |
+ return _stringFromJSArray(charCodes, start, end); |
} |
- if (end == null) { |
- end = len; |
- } else if (end < start || end > len) { |
- throw new RangeError.range(end, start, len); |
+ if (charCodes is NativeUint8List) { |
+ return _stringFromUint8List(charCodes, start, end); |
} |
- |
- if (start > 0 || end < len) { |
- list = list.sublist(start, end); |
- } |
- return Primitives.stringFromCharCodes(list); |
+ return _stringFromIterable(charCodes, start, end); |
} |
@patch |
@@ -308,6 +298,34 @@ class String { |
'String.fromEnvironment can only be used as a const constructor'); |
} |
+ static String _stringFromJSArray(List list, int start, int endOrNull) { |
+ int len = list.length; |
+ int end = _checkBounds(len, start, endOrNull); |
+ if (start > 0 || end < len) { |
+ list = list.sublist(start, end); |
+ } |
+ return Primitives.stringFromCharCodes(list); |
+ } |
+ |
+ static String _stringFromUint8List( |
+ NativeUint8List charCodes, int start, int endOrNull) { |
+ int len = charCodes.length; |
+ int end = _checkBounds(len, start, endOrNull); |
+ return Primitives.stringFromNativeUint8List(charCodes, start, end); |
+ } |
+ |
+ static int _checkBounds(int len, int start, int end) { |
+ if (start < 0 || start > len) { |
+ throw new RangeError.range(start, 0, len); |
+ } |
+ if (end == null) { |
+ end = len; |
+ } else if (end < start || end > len) { |
+ throw new RangeError.range(end, start, len); |
+ } |
+ return end; |
+ } |
+ |
static String _stringFromIterable(Iterable<int> charCodes, |
int start, int end) { |
if (start < 0) throw new RangeError.range(start, 0, charCodes.length); |