Chromium Code Reviews| 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('js_helper'); | 5 #library('js_helper'); |
| 6 | 6 |
| 7 #import('coreimpl.dart'); | 7 #import('coreimpl.dart'); |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Returns true if both arguments are numbers. | 10 * Returns true if both arguments are numbers. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 return result - b; | 75 return result - b; |
| 76 } else { | 76 } else { |
| 77 return result + b; | 77 return result + b; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 return UNINTERCEPTED(a % b); | 80 return UNINTERCEPTED(a % b); |
| 81 } | 81 } |
| 82 | 82 |
| 83 tdiv(var a, var b) { | 83 tdiv(var a, var b) { |
| 84 if (checkNumbers(a, b, "num~/ expects a number as second operand.")) { | 84 if (checkNumbers(a, b, "num~/ expects a number as second operand.")) { |
| 85 if (b === 0) throw new IntegerDivisionByZeroException(); | |
| 85 return (a / b).truncate(); | 86 return (a / b).truncate(); |
| 86 } | 87 } |
| 87 return UNINTERCEPTED(a ~/ b); | 88 return UNINTERCEPTED(a ~/ b); |
| 88 } | 89 } |
| 89 | 90 |
| 90 eq(var a, var b) { | 91 eq(var a, var b) { |
| 91 if (JS("bool", @"typeof $0 === 'object'", a)) { | 92 if (JS("bool", @"typeof $0 === 'object'", a)) { |
| 92 if (JS_HAS_EQUALS(a)) { | 93 if (JS_HAS_EQUALS(a)) { |
| 93 return UNINTERCEPTED(a == b) === true; | 94 return UNINTERCEPTED(a == b) === true; |
| 94 } else { | 95 } else { |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 if (receiver is num) { | 671 if (receiver is num) { |
| 671 return JS("bool", @"isNaN($0)", receiver); | 672 return JS("bool", @"isNaN($0)", receiver); |
| 672 } else { | 673 } else { |
| 673 return UNINTERCEPTED(receiver.isNegative()); | 674 return UNINTERCEPTED(receiver.isNegative()); |
| 674 } | 675 } |
| 675 } | 676 } |
| 676 | 677 |
| 677 builtin$remainder$1(a, b) { | 678 builtin$remainder$1(a, b) { |
| 678 checkNull(a); | 679 checkNull(a); |
| 679 if (checkNumbers(a, b, "num.remainder expects a number as second operand.")) { | 680 if (checkNumbers(a, b, "num.remainder expects a number as second operand.")) { |
| 681 if (b === 0) throw new IntegerDivisionByZeroException(); | |
| 680 return JS("num", @"$0 % $1", a, b); | 682 return JS("num", @"$0 % $1", a, b); |
| 681 } else { | 683 } else { |
| 682 return UNINTERCEPTED(a.remainder(b)); | 684 return UNINTERCEPTED(a.remainder(b)); |
| 683 } | 685 } |
| 684 } | 686 } |
| 685 | 687 |
| 686 builtin$abs$0(receiver) { | 688 builtin$abs$0(receiver) { |
| 687 checkNull(receiver); | 689 checkNull(receiver); |
| 688 if (receiver is !num) return UNINTERCEPTED(receiver.abs()); | 690 if (receiver is !num) return UNINTERCEPTED(receiver.abs()); |
| 689 | 691 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 if (receiver is !num) return UNINTERCEPTED(receiver.truncate()); | 753 if (receiver is !num) return UNINTERCEPTED(receiver.truncate()); |
| 752 | 754 |
| 753 return receiver < 0 ? receiver.ceil() : receiver.floor(); | 755 return receiver < 0 ? receiver.ceil() : receiver.floor(); |
| 754 } | 756 } |
| 755 | 757 |
| 756 builtin$toStringAsFixed$1(receiver, fractionDigits) { | 758 builtin$toStringAsFixed$1(receiver, fractionDigits) { |
| 757 checkNull(receiver); | 759 checkNull(receiver); |
| 758 if (receiver is !num) { | 760 if (receiver is !num) { |
| 759 return UNINTERCEPTED(receiver.toStringAsFixed(fractionDigits)); | 761 return UNINTERCEPTED(receiver.toStringAsFixed(fractionDigits)); |
| 760 } | 762 } |
| 763 checkNum(fractionDigits); | |
| 761 | 764 |
| 762 return JS("String", @"$0.toFixed($1)", receiver, fractionDigits); | 765 return JS("String", @"$0.toFixed($1)", receiver, fractionDigits); |
| 763 } | 766 } |
| 764 | 767 |
| 768 builtin$toStringAsExponential$1(receiver, fractionDigits) { | |
| 769 checkNull(receiver); | |
|
ngeoffray
2012/02/21 12:20:30
No need for these check null.
| |
| 770 if (receiver is !num) { | |
| 771 return UNINTERCEPTED(receiver.toStringAsExponential(fractionDigits)); | |
| 772 } | |
| 773 checkNum(fractionDigits); | |
| 774 | |
| 775 return JS("String", @"$0.toExponential($1)", receiver, fractionDigits); | |
| 776 } | |
| 777 | |
| 778 builtin$toStringAsPrecision$1(receiver, fractionDigits) { | |
| 779 checkNull(receiver); | |
| 780 if (receiver is !num) { | |
| 781 return UNINTERCEPTED(receiver.toStringAsPrecision(fractionDigits)); | |
| 782 } | |
| 783 checkNum(fractionDigits); | |
| 784 | |
| 785 return JS("String", @"$0.toPrecision($1)", receiver, fractionDigits); | |
| 786 } | |
| 787 | |
| 788 builtin$toRadixString$1(receiver, radix) { | |
| 789 checkNull(receiver); | |
| 790 if (receiver is !num) { | |
| 791 return UNINTERCEPTED(receiver.toRadixString(radix)); | |
| 792 } | |
| 793 checkNum(radix); | |
| 794 | |
| 795 return JS("String", @"$0.toString($1)", receiver, radix); | |
| 796 } | |
| 797 | |
| 765 builtin$allMatches$1(receiver, str) { | 798 builtin$allMatches$1(receiver, str) { |
| 766 checkNull(receiver); | 799 checkNull(receiver); |
| 767 if (receiver is !String) return UNINTERCEPTED(receiver.allMatches(str)); | 800 if (receiver is !String) return UNINTERCEPTED(receiver.allMatches(str)); |
| 768 | 801 |
| 769 throw new NotImplementedException(); | 802 throw new NotImplementedException(); |
| 770 } | 803 } |
| 771 | 804 |
| 772 builtin$concat$1(receiver, other) { | 805 builtin$concat$1(receiver, other) { |
| 773 checkNull(receiver); | 806 checkNull(receiver); |
| 774 if (receiver is !String) return UNINTERCEPTED(receiver.concat(other)); | 807 if (receiver is !String) return UNINTERCEPTED(receiver.concat(other)); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 => JS("double", @"Math.log($0)", checkNum(value)); | 939 => JS("double", @"Math.log($0)", checkNum(value)); |
| 907 | 940 |
| 908 static num pow(num value, num exponent) { | 941 static num pow(num value, num exponent) { |
| 909 checkNum(value); | 942 checkNum(value); |
| 910 checkNum(exponent); | 943 checkNum(exponent); |
| 911 return JS("num", @"Math.pow($0, $1)", value, exponent); | 944 return JS("num", @"Math.pow($0, $1)", value, exponent); |
| 912 } | 945 } |
| 913 | 946 |
| 914 static double random() => JS("double", "Math.random()"); | 947 static double random() => JS("double", "Math.random()"); |
| 915 } | 948 } |
| 949 | |
| 950 builtin$hashCode$0(receiver) { | |
| 951 if (receiver is num) return receiver & 0x1FFFFFFF; | |
| 952 if (receiver is String) { | |
| 953 throw new NotImplementedException(); | |
| 954 } | |
| 955 if (isJSArray(receiver)) { | |
| 956 throw new NotImplementedException(); | |
| 957 } | |
| 958 return UNINTERCEPTED(receiver.hashCode()); | |
| 959 } | |
| OLD | NEW |