Chromium Code Reviews| 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..bcf09dd970753892f38dc4f36f5638592857e2e4 100644 |
| --- a/sdk/lib/_internal/compiler/js_lib/core_patch.dart |
| +++ b/sdk/lib/_internal/compiler/js_lib/core_patch.dart |
| @@ -14,6 +14,9 @@ import 'dart:_js_helper' show patch, |
| stringJoinUnchecked, |
| objectHashCode; |
| +import 'dart:typed_data' show Uint8List; |
|
Lasse Reichstein Nielsen
2015/01/21 09:36:38
Is this import used?
sra1
2015/01/21 20:27:05
Done.
|
| +import 'dart:_native_typed_data' show NativeUint8List; |
| + |
| String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); |
| _symbolMapToStringMap(Map<Symbol, dynamic> map) { |
| @@ -275,26 +278,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 +299,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); |
|
Lasse Reichstein Nielsen
2015/01/21 09:36:38
You should soon be able to use RangeError.checkVal
|
| + 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); |