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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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]) { | 245 factory List([int length]) { |
| 246 dynamic list; |
246 if (length == null) { | 247 if (length == null) { |
247 return JS('', '[]'); | 248 list = JS('', '[]'); |
| 249 } else { |
| 250 // Explicit type test is necessary to guard against JavaScript conversions |
| 251 // in unchecked mode. |
| 252 if ((length is !int) || (length < 0)) { |
| 253 throw new ArgumentError("Length must be a non-negative integer: $length"
); |
| 254 } |
| 255 list = JS('', 'new Array(#)', length); |
| 256 // TODO(jmesserly): consider a fixed array subclass instead. |
| 257 JS('void', r'#.fixed$length = Array', list); |
248 } | 258 } |
249 // Explicit type test is necessary to guard against JavaScript conversions | 259 // TODO(jmesserly): skip this when E is dynamic and Object. |
250 // in unchecked mode. | 260 JS('void', 'dart.setType(#, List\$(#))', list, E); |
251 if ((length is !int) || (length < 0)) { | 261 // TODO(jmesserly): compiler creates a bogus type check here. |
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; | 262 return list; |
258 } | 263 } |
259 | 264 |
260 @patch | 265 @patch |
261 factory List.filled(int length, E fill) { | 266 factory List.filled(int length, E fill) { |
262 List result = new JSArray<E>.fixed(length); | 267 List result = new List<E>(length); |
263 if (length != 0 && fill != null) { | 268 if (length != 0 && fill != null) { |
264 for (int i = 0; i < result.length; i++) { | 269 for (int i = 0; i < result.length; i++) { |
265 result[i] = fill; | 270 result[i] = fill; |
266 } | 271 } |
267 } | 272 } |
268 return result; | 273 return result; |
269 } | 274 } |
270 | 275 |
271 @patch | 276 @patch |
272 factory List.from(Iterable elements, { bool growable: true }) { | 277 factory List.from(Iterable elements, { bool growable: true }) { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 @patch | 462 @patch |
458 static bool get _isWindows => false; | 463 static bool get _isWindows => false; |
459 | 464 |
460 @patch | 465 @patch |
461 static Uri get base { | 466 static Uri get base { |
462 String uri = Primitives.currentUri(); | 467 String uri = Primitives.currentUri(); |
463 if (uri != null) return Uri.parse(uri); | 468 if (uri != null) return Uri.parse(uri); |
464 throw new UnsupportedError("'Uri.base' is not supported"); | 469 throw new UnsupportedError("'Uri.base' is not supported"); |
465 } | 470 } |
466 } | 471 } |
OLD | NEW |