| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); | 7 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); |
| 8 | 8 |
| 9 class JavaScriptBitNotOperation extends BitNotOperation { | 9 class JavaScriptBitNotOperation extends BitNotOperation { |
| 10 const JavaScriptBitNotOperation(); | 10 const JavaScriptBitNotOperation(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 IntConstant intConstant = constant; | 192 IntConstant intConstant = constant; |
| 193 int intValue = intConstant.value; | 193 int intValue = intConstant.value; |
| 194 if (!integerFitsIntoDouble(intValue)) { | 194 if (!integerFitsIntoDouble(intValue)) { |
| 195 return new DoubleConstant(intValue.toDouble()); | 195 return new DoubleConstant(intValue.toDouble()); |
| 196 } | 196 } |
| 197 } else if (constant.isDouble()) { | 197 } else if (constant.isDouble()) { |
| 198 DoubleConstant doubleResult = constant; | 198 DoubleConstant doubleResult = constant; |
| 199 double doubleValue = doubleResult.value; | 199 double doubleValue = doubleResult.value; |
| 200 if (!doubleValue.isInfinite && !doubleValue.isNaN && | 200 if (!doubleValue.isInfinite && !doubleValue.isNaN && |
| 201 !constant.isMinusZero()) { | 201 !constant.isMinusZero()) { |
| 202 int intValue = doubleValue.toInt(); | 202 int intValue = doubleValue.truncate(); |
| 203 if (intValue == doubleValue && integerFitsIntoDouble(intValue)) { | 203 if (intValue == doubleValue && integerFitsIntoDouble(intValue)) { |
| 204 return new IntConstant(intValue); | 204 return new IntConstant(intValue); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 return constant; | 208 return constant; |
| 209 } | 209 } |
| 210 | 210 |
| 211 NumConstant createInt(int i) | 211 NumConstant createInt(int i) |
| 212 => convertToJavaScriptConstant(new IntConstant(i)); | 212 => convertToJavaScriptConstant(new IntConstant(i)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 230 // At runtime, an integer is both an integer and a double: the | 230 // At runtime, an integer is both an integer and a double: the |
| 231 // integer type check is Math.floor, which will return true only | 231 // integer type check is Math.floor, which will return true only |
| 232 // for real integers, and our double type check is 'typeof number' | 232 // for real integers, and our double type check is 'typeof number' |
| 233 // which will return true for both integers and doubles. | 233 // which will return true for both integers and doubles. |
| 234 if (s.element == compiler.intClass && t.element == compiler.doubleClass) { | 234 if (s.element == compiler.intClass && t.element == compiler.doubleClass) { |
| 235 return true; | 235 return true; |
| 236 } | 236 } |
| 237 return compiler.types.isSubtype(s, t); | 237 return compiler.types.isSubtype(s, t); |
| 238 } | 238 } |
| 239 } | 239 } |
| OLD | NEW |