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 #library('dart:_interceptors'); | 5 #library('dart:_interceptors'); |
6 | 6 |
7 #import('dart:coreimpl'); | 7 #import('dart:coreimpl'); |
8 | 8 |
9 add$1(var receiver, var value) { | 9 add$1(var receiver, var value) { |
10 if (isJsArray(receiver)) { | 10 if (isJsArray(receiver)) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 | 110 |
111 compareTo(a, b) { | 111 compareTo(a, b) { |
112 if (checkNumbers(a, b)) { | 112 if (checkNumbers(a, b)) { |
113 if (a < b) { | 113 if (a < b) { |
114 return -1; | 114 return -1; |
115 } else if (a > b) { | 115 } else if (a > b) { |
116 return 1; | 116 return 1; |
117 } else if (a == b) { | 117 } else if (a == b) { |
118 if (a == 0) { | 118 if (a == 0) { |
119 bool aIsNegative = a.isNegative(); | 119 bool aIsNegative = a.isNegative; |
120 bool bIsNegative = b.isNegative(); | 120 bool bIsNegative = b.isNegative; |
121 if (aIsNegative == bIsNegative) return 0; | 121 if (aIsNegative == bIsNegative) return 0; |
122 if (aIsNegative) return -1; | 122 if (aIsNegative) return -1; |
123 return 1; | 123 return 1; |
124 } | 124 } |
125 return 0; | 125 return 0; |
126 } else if (a.isNaN()) { | 126 } else if (a.isNaN) { |
127 if (b.isNaN()) { | 127 if (b.isNaN) { |
128 return 0; | 128 return 0; |
129 } | 129 } |
130 return 1; | 130 return 1; |
131 } else { | 131 } else { |
132 return -1; | 132 return -1; |
133 } | 133 } |
134 } else if (a is String) { | 134 } else if (a is String) { |
135 if (b is !String) throw new ArgumentError(b); | 135 if (b is !String) throw new ArgumentError(b); |
136 return JS('bool', r'# == #', a, b) ? 0 | 136 return JS('bool', r'# == #', a, b) ? 0 |
137 : JS('bool', r'# < #', a, b) ? -1 : 1; | 137 : JS('bool', r'# < #', a, b) ? -1 : 1; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 checkMutable(receiver, 'sort'); | 366 checkMutable(receiver, 'sort'); |
367 DualPivotQuicksort.sort(receiver, Comparable.compare); | 367 DualPivotQuicksort.sort(receiver, Comparable.compare); |
368 } | 368 } |
369 | 369 |
370 sort$1(receiver, compare) { | 370 sort$1(receiver, compare) { |
371 if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.sort(compare)); | 371 if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.sort(compare)); |
372 checkMutable(receiver, 'sort'); | 372 checkMutable(receiver, 'sort'); |
373 DualPivotQuicksort.sort(receiver, compare); | 373 DualPivotQuicksort.sort(receiver, compare); |
374 } | 374 } |
375 | 375 |
376 isNegative(receiver) { | 376 get$isNegative(receiver) { |
377 if (receiver is num) { | 377 if (receiver is num) { |
378 return (receiver == 0) ? (1 / receiver) < 0 : receiver < 0; | 378 return (receiver == 0) ? (1 / receiver) < 0 : receiver < 0; |
379 } else { | 379 } else { |
380 return UNINTERCEPTED(receiver.isNegative()); | 380 return UNINTERCEPTED(receiver.isNegative); |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 isNaN(receiver) { | 384 get$isNaN(receiver) { |
385 if (receiver is num) { | 385 if (receiver is num) { |
386 return JS('bool', r'isNaN(#)', receiver); | 386 return JS('bool', r'isNaN(#)', receiver); |
387 } else { | 387 } else { |
388 return UNINTERCEPTED(receiver.isNaN()); | 388 return UNINTERCEPTED(receiver.isNaN); |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 remainder(a, b) { | 392 remainder(a, b) { |
393 if (checkNumbers(a, b)) { | 393 if (checkNumbers(a, b)) { |
394 return JS('num', r'# % #', a, b); | 394 return JS('num', r'# % #', a, b); |
395 } else { | 395 } else { |
396 return UNINTERCEPTED(a.remainder(b)); | 396 return UNINTERCEPTED(a.remainder(b)); |
397 } | 397 } |
398 } | 398 } |
399 | 399 |
400 abs(receiver) { | 400 abs(receiver) { |
401 if (receiver is !num) return UNINTERCEPTED(receiver.abs()); | 401 if (receiver is !num) return UNINTERCEPTED(receiver.abs()); |
402 | 402 |
403 return JS('num', r'Math.abs(#)', receiver); | 403 return JS('num', r'Math.abs(#)', receiver); |
404 } | 404 } |
405 | 405 |
406 toInt(receiver) { | 406 toInt(receiver) { |
407 if (receiver is !num) return UNINTERCEPTED(receiver.toInt()); | 407 if (receiver is !num) return UNINTERCEPTED(receiver.toInt()); |
408 | 408 |
409 if (receiver.isNaN()) throw new FormatException('NaN'); | 409 if (receiver.isNaN) throw new FormatException('NaN'); |
410 | 410 |
411 if (receiver.isInfinite()) throw new FormatException('Infinity'); | 411 if (receiver.isInfinite) throw new FormatException('Infinity'); |
412 | 412 |
413 var truncated = receiver.truncate(); | 413 var truncated = receiver.truncate(); |
414 return JS('bool', r'# == -0.0', truncated) ? 0 : truncated; | 414 return JS('bool', r'# == -0.0', truncated) ? 0 : truncated; |
415 } | 415 } |
416 | 416 |
417 ceil(receiver) { | 417 ceil(receiver) { |
418 if (receiver is !num) return UNINTERCEPTED(receiver.ceil()); | 418 if (receiver is !num) return UNINTERCEPTED(receiver.ceil()); |
419 | 419 |
420 return JS('num', r'Math.ceil(#)', receiver); | 420 return JS('num', r'Math.ceil(#)', receiver); |
421 } | 421 } |
422 | 422 |
423 floor(receiver) { | 423 floor(receiver) { |
424 if (receiver is !num) return UNINTERCEPTED(receiver.floor()); | 424 if (receiver is !num) return UNINTERCEPTED(receiver.floor()); |
425 | 425 |
426 return JS('num', r'Math.floor(#)', receiver); | 426 return JS('num', r'Math.floor(#)', receiver); |
427 } | 427 } |
428 | 428 |
429 isInfinite(receiver) { | 429 get$isInfinite(receiver) { |
430 if (receiver is !num) return UNINTERCEPTED(receiver.isInfinite()); | 430 if (receiver is !num) return UNINTERCEPTED(receiver.isInfinite); |
431 | 431 |
432 return JS('bool', r'# == Infinity', receiver) | 432 return JS('bool', r'# == Infinity', receiver) |
433 || JS('bool', r'# == -Infinity', receiver); | 433 || JS('bool', r'# == -Infinity', receiver); |
434 } | 434 } |
435 | 435 |
436 round(receiver) { | 436 round(receiver) { |
437 if (receiver is !num) return UNINTERCEPTED(receiver.round()); | 437 if (receiver is !num) return UNINTERCEPTED(receiver.round()); |
438 | 438 |
439 if (JS('bool', r'# < 0', receiver)) { | 439 if (JS('bool', r'# < 0', receiver)) { |
440 return JS('num', r'-Math.round(-#)', receiver); | 440 return JS('num', r'-Math.round(-#)', receiver); |
(...skipping 14 matching lines...) Expand all Loading... |
455 return receiver < 0 ? receiver.ceil() : receiver.floor(); | 455 return receiver < 0 ? receiver.ceil() : receiver.floor(); |
456 } | 456 } |
457 | 457 |
458 toStringAsFixed(receiver, fractionDigits) { | 458 toStringAsFixed(receiver, fractionDigits) { |
459 if (receiver is !num) { | 459 if (receiver is !num) { |
460 return UNINTERCEPTED(receiver.toStringAsFixed(fractionDigits)); | 460 return UNINTERCEPTED(receiver.toStringAsFixed(fractionDigits)); |
461 } | 461 } |
462 checkNum(fractionDigits); | 462 checkNum(fractionDigits); |
463 | 463 |
464 String result = JS('String', r'#.toFixed(#)', receiver, fractionDigits); | 464 String result = JS('String', r'#.toFixed(#)', receiver, fractionDigits); |
465 if (receiver == 0 && receiver.isNegative()) return "-$result"; | 465 if (receiver == 0 && receiver.isNegative) return "-$result"; |
466 return result; | 466 return result; |
467 } | 467 } |
468 | 468 |
469 toStringAsExponential(receiver, fractionDigits) { | 469 toStringAsExponential(receiver, fractionDigits) { |
470 if (receiver is !num) { | 470 if (receiver is !num) { |
471 return UNINTERCEPTED(receiver.toStringAsExponential(fractionDigits)); | 471 return UNINTERCEPTED(receiver.toStringAsExponential(fractionDigits)); |
472 } | 472 } |
473 String result; | 473 String result; |
474 if (fractionDigits != null) { | 474 if (fractionDigits != null) { |
475 checkNum(fractionDigits); | 475 checkNum(fractionDigits); |
476 result = JS('String', r'#.toExponential(#)', receiver, fractionDigits); | 476 result = JS('String', r'#.toExponential(#)', receiver, fractionDigits); |
477 } else { | 477 } else { |
478 result = JS('String', r'#.toExponential()', receiver); | 478 result = JS('String', r'#.toExponential()', receiver); |
479 } | 479 } |
480 if (receiver == 0 && receiver.isNegative()) return "-$result"; | 480 if (receiver == 0 && receiver.isNegative) return "-$result"; |
481 return result; | 481 return result; |
482 } | 482 } |
483 | 483 |
484 toStringAsPrecision(receiver, fractionDigits) { | 484 toStringAsPrecision(receiver, fractionDigits) { |
485 if (receiver is !num) { | 485 if (receiver is !num) { |
486 return UNINTERCEPTED(receiver.toStringAsPrecision(fractionDigits)); | 486 return UNINTERCEPTED(receiver.toStringAsPrecision(fractionDigits)); |
487 } | 487 } |
488 checkNum(fractionDigits); | 488 checkNum(fractionDigits); |
489 | 489 |
490 String result = JS('String', r'#.toPrecision(#)', | 490 String result = JS('String', r'#.toPrecision(#)', |
491 receiver, fractionDigits); | 491 receiver, fractionDigits); |
492 if (receiver == 0 && receiver.isNegative()) return "-$result"; | 492 if (receiver == 0 && receiver.isNegative) return "-$result"; |
493 return result; | 493 return result; |
494 } | 494 } |
495 | 495 |
496 toRadixString(receiver, radix) { | 496 toRadixString(receiver, radix) { |
497 if (receiver is !num) { | 497 if (receiver is !num) { |
498 return UNINTERCEPTED(receiver.toRadixString(radix)); | 498 return UNINTERCEPTED(receiver.toRadixString(radix)); |
499 } | 499 } |
500 checkNum(radix); | 500 checkNum(radix); |
501 if (radix < 2 || radix > 36) throw new ArgumentError(radix); | 501 if (radix < 2 || radix > 36) throw new ArgumentError(radix); |
502 return JS('String', r'#.toString(#)', receiver, radix); | 502 return JS('String', r'#.toString(#)', receiver, radix); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 charCodes(receiver) { | 649 charCodes(receiver) { |
650 if (receiver is !String) return UNINTERCEPTED(receiver.charCodes()); | 650 if (receiver is !String) return UNINTERCEPTED(receiver.charCodes()); |
651 int len = receiver.length; | 651 int len = receiver.length; |
652 List<int> result = new List<int>(len); | 652 List<int> result = new List<int>(len); |
653 for (int i = 0; i < len; i++) { | 653 for (int i = 0; i < len; i++) { |
654 result[i] = receiver.charCodeAt(i); | 654 result[i] = receiver.charCodeAt(i); |
655 } | 655 } |
656 return result; | 656 return result; |
657 } | 657 } |
658 | 658 |
659 isEven(receiver) { | 659 get$isEven(receiver) { |
660 if (receiver is !int) return UNINTERCEPTED(receiver.isEven()); | 660 if (receiver is !int) return UNINTERCEPTED(receiver.isEven); |
661 return (receiver & 1) == 0; | 661 return (receiver & 1) == 0; |
662 } | 662 } |
663 | 663 |
664 isOdd(receiver) { | 664 get$isOdd(receiver) { |
665 if (receiver is !int) return UNINTERCEPTED(receiver.isOdd()); | 665 if (receiver is !int) return UNINTERCEPTED(receiver.isOdd); |
666 return (receiver & 1) == 1; | 666 return (receiver & 1) == 1; |
667 } | 667 } |
668 | 668 |
669 get$runtimeType(receiver) { | 669 get$runtimeType(receiver) { |
670 if (receiver is int) { | 670 if (receiver is int) { |
671 return getOrCreateCachedRuntimeType('int'); | 671 return getOrCreateCachedRuntimeType('int'); |
672 } else if (receiver is String) { | 672 } else if (receiver is String) { |
673 return getOrCreateCachedRuntimeType('String'); | 673 return getOrCreateCachedRuntimeType('String'); |
674 } else if (receiver is double) { | 674 } else if (receiver is double) { |
675 return getOrCreateCachedRuntimeType('double'); | 675 return getOrCreateCachedRuntimeType('double'); |
676 } else if (receiver is bool) { | 676 } else if (receiver is bool) { |
677 return getOrCreateCachedRuntimeType('bool'); | 677 return getOrCreateCachedRuntimeType('bool'); |
678 } else if (receiver == null) { | 678 } else if (receiver == null) { |
679 return getOrCreateCachedRuntimeType('Null'); | 679 return getOrCreateCachedRuntimeType('Null'); |
680 } else if (isJsArray(receiver)) { | 680 } else if (isJsArray(receiver)) { |
681 return getOrCreateCachedRuntimeType('List'); | 681 return getOrCreateCachedRuntimeType('List'); |
682 } else { | 682 } else { |
683 return UNINTERCEPTED(receiver.runtimeType); | 683 return UNINTERCEPTED(receiver.runtimeType); |
684 } | 684 } |
685 } | 685 } |
686 | 686 |
687 // TODO(lrn): These getters should be generated automatically for all | 687 // TODO(lrn): These getters should be generated automatically for all |
688 // intercepted methods. | 688 // intercepted methods. |
689 get$toString(receiver) => () => toString(receiver); | 689 get$toString(receiver) => () => toString(receiver); |
OLD | NEW |