Index: sdk/lib/_internal/compiler/implementation/lib/core_patch.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/lib/core_patch.dart b/sdk/lib/_internal/compiler/implementation/lib/core_patch.dart |
index 5df7994bb5e6f62199bdd7bc379146c5a56856cd..92067ecb6de7022e9934014807b0d0ed03284162 100644 |
--- a/sdk/lib/_internal/compiler/implementation/lib/core_patch.dart |
+++ b/sdk/lib/_internal/compiler/implementation/lib/core_patch.dart |
@@ -159,7 +159,44 @@ patch class _StopwatchImpl { |
// Patch for List implementation. |
patch class _ListImpl<E> { |
- patch factory List([int length]) => Primitives.newList(length); |
+ patch factory List([int length = 0]) { |
+ if ((length is !int) || (length < 0)) { |
+ String lengthString = Error.safeToString(length); |
+ throw new ArgumentError( |
+ "Length must be a positive integer: $lengthString."); |
+ } |
+ return Primitives.newGrowableList(length); |
+ } |
+ |
+ patch factory List.fixedLength(int length, {E fill: null}) { |
+ if ((length is !int) || (length < 0)) { |
+ throw new ArgumentError("Length must be a positive integer: $length."); |
+ } |
+ List result = Primitives.newFixedList(length); |
+ if (length != 0 && fill != null) { |
+ for (int i = 0; i < result.length; i++) { |
+ result[i] = fill; |
+ } |
+ } |
+ return result; |
+ } |
+ |
+ /** |
+ * Creates an extendable list of the given [length] where each entry is |
+ * filled with [fill]. |
+ */ |
+ patch factory List.filled(int length, E fill) { |
+ if ((length is !int) || (length < 0)) { |
+ throw new ArgumentError("Length must be a positive integer: $length."); |
+ } |
+ List result = Primitives.newGrowableList(length); |
+ if (length != 0 && fill != null) { |
+ for (int i = 0; i < result.length; i++) { |
+ result[i] = fill; |
+ } |
+ } |
+ return result; |
+ } |
patch factory List.from(Iterable<E> other) { |
var result = new List(); |