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 a26ee926e08377f9b1f570e7ca9b910bf7293e9c..2de51286d987aea96f8bb9831c395d429cad1ebc 100644 |
--- a/sdk/lib/_internal/compiler/js_lib/core_patch.dart |
+++ b/sdk/lib/_internal/compiler/js_lib/core_patch.dart |
@@ -272,28 +272,33 @@ class String { |
@patch |
factory String.fromCharCodes(Iterable<int> charCodes, |
[int start = 0, int end]) { |
- if (start < 0) throw new RangeError.value(start); |
List list; |
- if (charCodes is JSArray) { |
- list = charCodes; |
- // If possible, recognize typed lists too. |
- int len = list.length; |
- if (end == null || end > len) end = len; |
- if (start > 0 || end < len) { |
- if (start >= end) return ""; |
- list = list.sublist(start, end); |
- } |
- } else { |
- if (end != null) { |
- if (start >= end) return ""; |
- charCodes = charCodes.take(end); |
- } |
- if (start > 0) charCodes = charCodes.skip(start); |
- list = charCodes.toList(); // Try the iterable's own toList first. |
- if (list is! JSArray) { |
- // If that fails, force a JSArray. |
- list = new List.from(list); |
+ // If possible, recognize typed lists too. |
+ if (charCodes is! JSArray) { |
+ if (start > 0 || end != null) { |
+ if (start < 0) throw new RangeError.value(start); |
+ if (end < start) throw new RangeError.value(end); |
Søren Gjesse
2014/09/26 11:43:00
As you mentioned yourself end can be null here.
|
+ int len = end - start; |
+ list = new List.from(charCodes.take(end).skip(start)); |
Søren Gjesse
2014/09/26 11:43:00
skip before take?
|
+ if (list.length != len) { |
+ throw new RangeError.range(end, 0, len); |
+ } |
+ return Primitives.stringFromCharCodes(list); |
} |
+ list = new List.from(charCodes); |
+ } |
+ int len = list.length; |
+ 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); |
+ } |
+ |
+ if (start > 0 || end < len) { |
+ list = list.sublist(start, end); |
} |
return Primitives.stringFromCharCodes(list); |
} |