| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 void print(var obj) { | 5 void print(var obj) { |
| 6 obj = obj.toString(); | 6 obj = obj.toString(); |
| 7 var hasConsole = JS("bool", @"typeof console == 'object'"); | 7 var hasConsole = JS("bool", @"typeof console == 'object'"); |
| 8 if (hasConsole) { | 8 if (hasConsole) { |
| 9 JS("void", @"console.log($0)", obj); | 9 JS("void", @"console.log($0)", obj); |
| 10 } else { | 10 } else { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 List args; | 342 List args; |
| 343 NoSuchMethodException(Object this.receiver, String this.name, List this.args); | 343 NoSuchMethodException(Object this.receiver, String this.name, List this.args); |
| 344 String toString() { | 344 String toString() { |
| 345 return "NoSuchMethodException - receiver: '$receiver'" + | 345 return "NoSuchMethodException - receiver: '$receiver'" + |
| 346 "function name: '$name' arguments: [$args]"; | 346 "function name: '$name' arguments: [$args]"; |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 class List<T> /* implements Iterable<T> */ { | 350 class List<T> /* implements Iterable<T> */ { |
| 351 | 351 |
| 352 static void _checkConstructorInput(n) { | 352 factory List([int length]) { |
| 353 // TODO(ngeoffray): Inline once we support optional parameters or | 353 if (length == null) return JS("Object", @"new Array()"); |
| 354 // bailout. | 354 if (!isInt(length)) throw "Invalid argument"; |
| 355 if (!isInt(n)) throw "Invalid argument"; | 355 if (length < 0) throw "Negative size"; |
| 356 if (n < 0) throw "Negative size"; | 356 return JS("Object", @"new Array($0)", length); |
| 357 } | |
| 358 | |
| 359 factory List(n) { | |
| 360 // TODO(ngeoffray): Adjust to optional parameters. | |
| 361 if (JS("bool", @"$0 === (void 0)", n)) return JS("Object", @"new Array()"); | |
| 362 _checkConstructorInput(n); | |
| 363 return JS("Object", @"new Array($0)", n); | |
| 364 } | 357 } |
| 365 } | 358 } |
| 366 | 359 |
| 367 class ListIterator<T> /* implements Iterator<T> */ { | 360 class ListIterator<T> /* implements Iterator<T> */ { |
| 368 int i; | 361 int i; |
| 369 List<T> list; | 362 List<T> list; |
| 370 ListIterator(List<T> this.list) : i = 0; | 363 ListIterator(List<T> this.list) : i = 0; |
| 371 bool hasNext() => i < JS("int", @"$0.length", list); | 364 bool hasNext() => i < JS("int", @"$0.length", list); |
| 372 T next() { | 365 T next() { |
| 373 var value = JS("Object", @"$0[$1]", list, i); | 366 var value = JS("Object", @"$0[$1]", list, i); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 } else { | 450 } else { |
| 458 return | 451 return |
| 459 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); | 452 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); |
| 460 } | 453 } |
| 461 } | 454 } |
| 462 | 455 |
| 463 int frequency() { | 456 int frequency() { |
| 464 return 1000; | 457 return 1000; |
| 465 } | 458 } |
| 466 } | 459 } |
| OLD | NEW |