OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Patch file for dart:core classes. | 5 // Patch file for dart:core classes. |
6 import "dart:_internal" as _symbol_dev; | 6 import "dart:_internal" as _symbol_dev; |
7 import 'dart:_interceptors'; | 7 import 'dart:_interceptors'; |
8 import 'dart:_js_helper' show patch, | 8 import 'dart:_js_helper' show patch, |
9 checkInt, | 9 checkInt, |
10 getRuntimeType, | 10 getRuntimeType, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 235 } |
236 | 236 |
237 class _ListConstructorSentinel { | 237 class _ListConstructorSentinel { |
238 const _ListConstructorSentinel(); | 238 const _ListConstructorSentinel(); |
239 } | 239 } |
240 | 240 |
241 // Patch for List implementation. | 241 // Patch for List implementation. |
242 @patch | 242 @patch |
243 class List<E> { | 243 class List<E> { |
244 @patch | 244 @patch |
245 factory List([int length = const _ListConstructorSentinel()]) { | 245 factory List([int length]) { |
246 if (length == const _ListConstructorSentinel()) { | 246 if (length == null) { |
247 return new JSArray<E>.emptyGrowable(); | 247 return JS('', '[]'); |
248 } | 248 } |
249 return new JSArray<E>.fixed(length); | 249 // Explicit type test is necessary to guard against JavaScript conversions |
| 250 // in unchecked mode. |
| 251 if ((length is !int) || (length < 0)) { |
| 252 throw new ArgumentError("Length must be a non-negative integer: $length"); |
| 253 } |
| 254 var list = JS('', 'new Array(#)', length); |
| 255 // TODO(jmesserly): consider a fixed array subclass instead. |
| 256 JS('void', r'#.fixed$length = Array', list); |
| 257 return list; |
250 } | 258 } |
251 | 259 |
252 @patch | 260 @patch |
253 factory List.filled(int length, E fill) { | 261 factory List.filled(int length, E fill) { |
254 List result = new JSArray<E>.fixed(length); | 262 List result = new JSArray<E>.fixed(length); |
255 if (length != 0 && fill != null) { | 263 if (length != 0 && fill != null) { |
256 for (int i = 0; i < result.length; i++) { | 264 for (int i = 0; i < result.length; i++) { |
257 result[i] = fill; | 265 result[i] = fill; |
258 } | 266 } |
259 } | 267 } |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 @patch | 457 @patch |
450 static bool get _isWindows => false; | 458 static bool get _isWindows => false; |
451 | 459 |
452 @patch | 460 @patch |
453 static Uri get base { | 461 static Uri get base { |
454 String uri = Primitives.currentUri(); | 462 String uri = Primitives.currentUri(); |
455 if (uri != null) return Uri.parse(uri); | 463 if (uri != null) return Uri.parse(uri); |
456 throw new UnsupportedError("'Uri.base' is not supported"); | 464 throw new UnsupportedError("'Uri.base' is not supported"); |
457 } | 465 } |
458 } | 466 } |
OLD | NEW |