| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 280 } |
| 281 | 281 |
| 282 | 282 |
| 283 builtin$iterator$0(var receiver) { | 283 builtin$iterator$0(var receiver) { |
| 284 if (isJSArray(receiver)) { | 284 if (isJSArray(receiver)) { |
| 285 return new ListIterator(receiver); | 285 return new ListIterator(receiver); |
| 286 } | 286 } |
| 287 return UNINTERCEPTED(receiver.iterator()); | 287 return UNINTERCEPTED(receiver.iterator()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 builtin$charCodeAt$1(var receiver, int index) { |
| 291 if (JS("bool", @"typeof receiver === 'string'")) { |
| 292 return JS("string", @"$0.charCodeAt($1)", receiver, index); |
| 293 } else { |
| 294 return UNINTERCEPTED(receiver.charCodeAt(index)); |
| 295 } |
| 296 } |
| 297 |
| 298 builtin$isEmpty$0(var receiver) { |
| 299 if (JS("bool", @"typeof $0 === 'string'", receiver) || isJSArray(receiver)) { |
| 300 return JS("bool", @"$0.length === 0", receiver); |
| 301 } |
| 302 return UNINTERCEPTED(receiver.isEmpty()); |
| 303 } |
| 304 |
| 290 | 305 |
| 291 bool isInt(var v) { | 306 bool isInt(var v) { |
| 292 return JS("bool", @"($0 | 0) === $1", v, v); | 307 return JS("bool", @"($0 | 0) === $1", v, v); |
| 293 } | 308 } |
| 294 | 309 |
| 295 /* Include when interfaces are implemented | 310 /* Include when interfaces are implemented |
| 296 interface Iterable<T> { | 311 interface Iterable<T> { |
| 297 Iterator<T> iterator(); | 312 Iterator<T> iterator(); |
| 298 } | 313 } |
| 299 | 314 |
| 300 interface Iterator<T> { | 315 interface Iterator<T> { |
| 301 bool hasNext(); | 316 bool hasNext(); |
| 302 T next(); | 317 T next(); |
| 303 } | 318 } |
| 304 */ | 319 */ |
| 305 class int {} | 320 class int {} |
| 306 class double {} | 321 class double {} |
| 307 class String {} | 322 class String {} |
| 308 class bool {} | 323 class bool {} |
| 309 class Object { | 324 class Object { |
| 310 String toString() { | 325 String toString() { |
| 311 String name = JS('String', @'this.constructor.name'); | 326 String name = JS('String', @'this.constructor.name'); |
| 312 if (name === null) { | 327 if (name === null) { |
| 313 name = JS('String', @'$0.match(/^\s*function\s*(\S*)\s*\(/)[1]', | 328 name = JS('String', @'$0.match(/^\s*function\s*(\S*)\s*\(/)[1]', |
| 314 JS('String', @'this.constructor.toString()')); | 329 JS('String', @'this.constructor.toString()')); |
| 315 } | 330 } |
| 316 return "Instance of '$name'"; | 331 return "Instance of '$name'"; |
| 317 } | 332 } |
| 333 |
| 334 void noSuchMethod(String name, List args) { |
| 335 throw new NoSuchMethodException(this, name, args); |
| 336 } |
| 318 } | 337 } |
| 338 |
| 339 class NoSuchMethodException { |
| 340 Object receiver; |
| 341 String name; |
| 342 List args; |
| 343 NoSuchMethodException(Object r, String n, List a) |
| 344 : receiver = r, name = n, args = a; |
| 345 String toString() { |
| 346 return "NoSuchMethodException - receiver: '$receiver'" + |
| 347 "function name: '$name' arguments: [$args]"; |
| 348 } |
| 349 } |
| 350 |
| 319 class List<T> /* implements Iterable<T> */ { | 351 class List<T> /* implements Iterable<T> */ { |
| 320 | 352 |
| 321 static void _checkConstructorInput(n) { | 353 static void _checkConstructorInput(n) { |
| 322 // TODO(ngeoffray): Inline once we support optional parameters or | 354 // TODO(ngeoffray): Inline once we support optional parameters or |
| 323 // bailout. | 355 // bailout. |
| 324 if (!isInt(n)) throw "Invalid argument"; | 356 if (!isInt(n)) throw "Invalid argument"; |
| 325 if (n < 0) throw "Negative size"; | 357 if (n < 0) throw "Negative size"; |
| 326 } | 358 } |
| 327 | 359 |
| 328 factory List(n) { | 360 factory List(n) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } else { | 437 } else { |
| 406 return | 438 return |
| 407 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); | 439 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); |
| 408 } | 440 } |
| 409 } | 441 } |
| 410 | 442 |
| 411 int frequency() { | 443 int frequency() { |
| 412 return 1000; | 444 return 1000; |
| 413 } | 445 } |
| 414 } | 446 } |
| OLD | NEW |