Chromium Code Reviews| 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 | 5 |
| 6 | |
| 7 function native_NumberImplementation_BIT_OR(other) { | 6 function native_NumberImplementation_BIT_OR(other) { |
|
ahe
2012/01/19 13:27:16
Any method that starts with native_ and immediatel
kasperl
2012/01/19 13:33:10
Yes -- strongly agreed. That is certainly the plan
| |
| 8 "use strict"; | 7 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 9 if (typeof other != 'number') { | |
| 10 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 11 } | |
| 12 return this | other; | |
| 13 } | 8 } |
| 14 | 9 |
| 15 function native_NumberImplementation_BIT_XOR(other) { | 10 function native_NumberImplementation_BIT_XOR(other) { |
| 16 "use strict"; | 11 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 17 if (typeof other != 'number') { | |
| 18 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 19 } | |
| 20 return this ^ other; | |
| 21 } | 12 } |
| 22 | 13 |
| 23 function native_NumberImplementation_BIT_AND(other) { | 14 function native_NumberImplementation_BIT_AND(other) { |
| 24 "use strict"; | 15 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 25 if (typeof other != 'number') { | |
| 26 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 27 } | |
| 28 return this & other; | |
| 29 } | 16 } |
| 30 | 17 |
| 31 function native_NumberImplementation_SHL(other) { | 18 function native_NumberImplementation_SHL(other) { |
| 32 "use strict"; | 19 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 33 if (typeof other != 'number') { | |
| 34 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 35 } | |
| 36 return this << other; | |
| 37 } | 20 } |
| 38 | 21 |
| 39 function native_NumberImplementation_SAR(other) { | 22 function native_NumberImplementation_SAR(other) { |
| 40 "use strict"; | 23 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 41 if (typeof other != 'number') { | 24 } |
| 42 native__NumberJsUtil__throwIllegalArgumentException(other); | 25 |
| 43 } | 26 function native_NumberImplementation_BIT_NOT() { |
| 44 return this >> other; | 27 throw Error('UNREACHABLE'); |
| 45 } | 28 } |
| 46 | 29 |
| 47 function native_NumberImplementation_ADD(other) { | 30 function native_NumberImplementation_ADD(other) { |
| 48 "use strict"; | 31 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 49 if (typeof other != 'number') { | |
| 50 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 51 } | |
| 52 return this + other; | |
| 53 } | 32 } |
| 54 | 33 |
| 55 function native_NumberImplementation_SUB(other) { | 34 function native_NumberImplementation_SUB(other) { |
| 56 "use strict"; | 35 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 57 if (typeof other != 'number') { | |
| 58 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 59 } | |
| 60 return this - other; | |
| 61 } | 36 } |
| 62 | 37 |
| 63 function native_NumberImplementation_MUL(other) { | 38 function native_NumberImplementation_MUL(other) { |
| 64 "use strict"; | 39 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 65 if (typeof other != 'number') { | |
| 66 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 67 } | |
| 68 return this * other; | |
| 69 } | 40 } |
| 70 | 41 |
| 71 function native_NumberImplementation_DIV(other) { | 42 function native_NumberImplementation_DIV(other) { |
| 72 "use strict"; | 43 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 73 if (typeof other != 'number') { | |
| 74 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 75 } | |
| 76 return this / other; | |
| 77 } | 44 } |
| 78 | 45 |
| 79 function native_NumberImplementation_TRUNC(other) { | 46 function native_NumberImplementation_TRUNC(other) { |
| 80 "use strict"; | 47 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 81 if (typeof other != 'number') { | |
| 82 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 83 } | |
| 84 var tmp = this / other; | |
| 85 if (tmp < 0) { | |
| 86 return Math.ceil(tmp); | |
| 87 } else { | |
| 88 return Math.floor(tmp); | |
| 89 } | |
| 90 } | 48 } |
| 91 | 49 |
| 50 function native_NumberImplementation_MOD(other) { | |
| 51 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 52 } | |
| 53 | |
| 54 function native_NumberImplementation_negate() { | |
| 55 throw Error('UNREACHABLE'); | |
| 56 } | |
| 57 | |
| 58 function native_NumberImplementation_EQ(other) { | |
| 59 throw Error('UNREACHABLE'); | |
| 60 } | |
| 61 | |
| 62 function native_NumberImplementation_LT(other) { | |
| 63 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 64 } | |
| 65 | |
| 66 function native_NumberImplementation_GT(other) { | |
| 67 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 68 } | |
| 69 | |
| 70 function native_NumberImplementation_LTE(other) { | |
| 71 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 72 } | |
| 73 | |
| 74 function native_NumberImplementation_GTE(other) { | |
| 75 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 76 } | |
| 77 | |
| 78 | |
| 92 function number$euclideanModulo(a, b) { | 79 function number$euclideanModulo(a, b) { |
| 93 var result = a % b; | 80 var result = a % b; |
| 94 if (result == 0) { | 81 if (result == 0) { |
| 95 return 0; // Make sure we don't return -0.0. | 82 return 0; // Make sure we don't return -0.0. |
| 96 } else if (result < 0) { | 83 } else if (result < 0) { |
| 97 if (b < 0) { | 84 if (b < 0) { |
| 98 return result - b; | 85 return result - b; |
| 99 } else { | 86 } else { |
| 100 return result + b; | 87 return result + b; |
| 101 } | 88 } |
| 102 } | 89 } |
| 103 return result; | 90 return result; |
| 104 } | 91 } |
| 105 | 92 |
| 106 function native_NumberImplementation_MOD(other) { | |
| 107 "use strict"; | |
| 108 if (typeof other != 'number') { | |
| 109 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 110 } | |
| 111 return number$euclideanModulo(this, other); | |
| 112 } | |
| 113 | |
| 114 function native_NumberImplementation_LT(other) { | |
| 115 "use strict"; | |
| 116 if (typeof other != 'number') { | |
| 117 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 118 } | |
| 119 return this < other; | |
| 120 } | |
| 121 | |
| 122 function native_NumberImplementation_GT(other) { | |
| 123 "use strict"; | |
| 124 if (typeof other != 'number') { | |
| 125 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 126 } | |
| 127 return this > other; | |
| 128 } | |
| 129 | |
| 130 function native_NumberImplementation_LTE(other) { | |
| 131 "use strict"; | |
| 132 if (typeof other != 'number') { | |
| 133 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 134 } | |
| 135 return this <= other; | |
| 136 } | |
| 137 | |
| 138 function native_NumberImplementation_GTE(other) { | |
| 139 "use strict"; | |
| 140 if (typeof other != 'number') { | |
| 141 native__NumberJsUtil__throwIllegalArgumentException(other); | |
| 142 } | |
| 143 return this >= other; | |
| 144 } | |
| 145 | |
| 146 function native_NumberImplementation_EQ(other) { | |
| 147 "use strict"; | |
| 148 return typeof other == 'number' && this == other; | |
| 149 } | |
| 150 | |
| 151 function native_NumberImplementation_BIT_NOT() { | |
| 152 "use strict"; | |
| 153 return ~this; | |
| 154 } | |
| 155 | |
| 156 function native_NumberImplementation_negate() { | |
| 157 "use strict"; | |
| 158 return -this; | |
| 159 } | |
| 160 | |
| 161 function native_NumberImplementation_remainder(other) { | 93 function native_NumberImplementation_remainder(other) { |
| 162 "use strict"; | 94 "use strict"; |
| 163 if (typeof other != 'number') { | 95 if (typeof other != 'number') { |
| 164 native__NumberJsUtil__throwIllegalArgumentException(other); | 96 native__NumberJsUtil__throwIllegalArgumentException(other); |
| 165 } | 97 } |
| 166 return this % other; | 98 return this % other; |
| 167 } | 99 } |
| 168 | 100 |
| 169 function native_NumberImplementation_abs() { | 101 function native_NumberImplementation_abs() { |
| 170 "use strict"; | 102 "use strict"; |
| 171 return Math.abs(this); | 103 return Math.abs(this); |
| 172 } | 104 } |
| 173 | 105 |
| 174 function native_NumberImplementation_round() { | 106 function native_NumberImplementation_round() { |
| 175 "use strict"; | 107 "use strict"; |
| 176 return Math.round(this); | 108 return Math.round(this); |
| 177 } | 109 } |
| 110 | |
| 178 function native_NumberImplementation_floor() { | 111 function native_NumberImplementation_floor() { |
| 179 "use strict"; | 112 "use strict"; |
| 180 return Math.floor(this); | 113 return Math.floor(this); |
| 181 } | 114 } |
| 115 | |
| 182 function native_NumberImplementation_ceil() { | 116 function native_NumberImplementation_ceil() { |
| 183 "use strict"; | 117 "use strict"; |
| 184 return Math.ceil(this); | 118 return Math.ceil(this); |
| 185 } | 119 } |
| 120 | |
| 186 function native_NumberImplementation_truncate() { | 121 function native_NumberImplementation_truncate() { |
| 187 "use strict"; | 122 "use strict"; |
| 188 return (this < 0) ? Math.ceil(this) : Math.floor(this); | 123 return (this < 0) ? Math.ceil(this) : Math.floor(this); |
| 189 } | 124 } |
| 125 | |
| 190 function native_NumberImplementation_isNegative() { | 126 function native_NumberImplementation_isNegative() { |
| 191 "use strict"; | 127 "use strict"; |
| 192 // TODO(floitsch): is there a faster way to detect -0? | 128 // TODO(floitsch): is there a faster way to detect -0? |
| 193 if (this == 0) return (1 / this) < 0; | 129 if (this == 0) return (1 / this) < 0; |
| 194 return this < 0; | 130 return this < 0; |
| 195 } | 131 } |
| 132 | |
| 196 function native_NumberImplementation_isEven() { | 133 function native_NumberImplementation_isEven() { |
| 197 "use strict"; | 134 "use strict"; |
| 198 return ((this & 1) == 0); | 135 return ((this & 1) == 0); |
| 199 } | 136 } |
| 137 | |
| 200 function native_NumberImplementation_isOdd() { | 138 function native_NumberImplementation_isOdd() { |
| 201 "use strict"; | 139 "use strict"; |
| 202 return ((this & 1) == 1); | 140 return ((this & 1) == 1); |
| 203 } | 141 } |
| 142 | |
| 204 function native_NumberImplementation_isNaN() { | 143 function native_NumberImplementation_isNaN() { |
| 205 "use strict"; | 144 "use strict"; |
| 206 return isNaN(this); | 145 return isNaN(this); |
| 207 } | 146 } |
| 147 | |
| 208 function native_NumberImplementation_isInfinite() { | 148 function native_NumberImplementation_isInfinite() { |
| 209 "use strict"; | 149 "use strict"; |
| 210 return (this == Infinity) || (this == -Infinity); | 150 return (this == Infinity) || (this == -Infinity); |
| 211 } | 151 } |
| 212 | 152 |
| 213 function native_NumberImplementation_toDouble() { | 153 function native_NumberImplementation_toDouble() { |
| 214 "use strict"; | 154 "use strict"; |
| 215 return +this; | 155 return +this; |
| 216 } | 156 } |
| 217 | 157 |
| 218 function native_NumberImplementation_toString() { | 158 function native_NumberImplementation_toString() { |
| 219 return this.toString(); | 159 return this.toString(); |
| 220 } | 160 } |
| 161 | |
| 221 function native_NumberImplementation_toStringAsFixed(fractionDigits) { | 162 function native_NumberImplementation_toStringAsFixed(fractionDigits) { |
| 222 return this.toFixed(fractionDigits); | 163 return this.toFixed(fractionDigits); |
| 223 } | 164 } |
| 165 | |
| 224 function native_NumberImplementation_toStringAsPrecision(precision) { | 166 function native_NumberImplementation_toStringAsPrecision(precision) { |
| 225 return this.toPrecision(precision); | 167 return this.toPrecision(precision); |
| 226 } | 168 } |
| 169 | |
| 227 function native_NumberImplementation_toStringAsExponential(fractionDigits) { | 170 function native_NumberImplementation_toStringAsExponential(fractionDigits) { |
| 228 return this.toExponential(fractionDigits); | 171 return this.toExponential(fractionDigits); |
| 229 } | 172 } |
| 173 | |
| 230 function native_NumberImplementation_toRadixString(radix) { | 174 function native_NumberImplementation_toRadixString(radix) { |
| 231 return this.toString(radix); | 175 return this.toString(radix); |
| 232 } | 176 } |
| 233 | 177 |
| 234 function native_NumberImplementation_hashCode() { | 178 function native_NumberImplementation_hashCode() { |
| 235 "use strict"; | 179 "use strict"; |
| 236 return this & 0xFFFFFFF; | 180 return this & 0xFFFFFFF; |
| 237 } | 181 } |
| OLD | NEW |