Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/constant_system_javascript.dart

Issue 19180002: A dart int literal is a dart2js' int unless it will become NaN or infinity. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/constant_javascript_semantics4_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/js_backend/constant_system_javascript.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/js_backend/constant_system_javascript.dart (revision 25000)
+++ sdk/lib/_internal/compiler/implementation/js_backend/constant_system_javascript.dart (working copy)
@@ -177,30 +177,34 @@
const JavaScriptConstantSystem();
/**
- * Returns true if the given [value] fits into a double without losing
- * precision.
+ * Returns true if [value] will turn into NaN or infinity
+ * at runtime.
*/
- bool integerFitsIntoDouble(int value) {
- int absValue = value.abs();
- double doubleValue = absValue.toDouble();
- if (doubleValue.isNaN || doubleValue.isInfinite) return false;
- return value.toDouble().floor().toInt() == value;
+ bool integerBecomesNanOrInfinity(int value) {
+ double doubleValue = value.toDouble();
+ return doubleValue.isNaN || doubleValue.isInfinite;
}
NumConstant convertToJavaScriptConstant(NumConstant constant) {
if (constant.isInt()) {
IntConstant intConstant = constant;
int intValue = intConstant.value;
- if (!integerFitsIntoDouble(intValue)) {
+ if (integerBecomesNanOrInfinity(intValue)) {
return new DoubleConstant(intValue.toDouble());
}
+ // If the integer loses precision with JavaScript numbers, use
+ // the floored version JavaScript will use.
+ int floorValue = intValue.toDouble().floor().toInt();
+ if (floorValue != intValue) {
+ return new IntConstant(floorValue);
+ }
} else if (constant.isDouble()) {
DoubleConstant doubleResult = constant;
double doubleValue = doubleResult.value;
if (!doubleValue.isInfinite && !doubleValue.isNaN &&
!constant.isMinusZero()) {
int intValue = doubleValue.truncate();
- if (intValue == doubleValue && integerFitsIntoDouble(intValue)) {
+ if (intValue == doubleValue) {
return new IntConstant(intValue);
}
}
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/constant_javascript_semantics4_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698