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

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 | no next file » | 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,6 +177,16 @@
const JavaScriptConstantSystem();
/**
+ * Returns true if the given [value] will turn into NaN or infinity
karlklose 2013/07/15 13:52:08 '... true if [value] will...'?
ngeoffray 2013/07/15 13:53:38 Done.
+ * at runtime.
+ */
+ bool integerBecomesNanOrInfinity(int value) {
+ int absValue = value.abs();
floitsch 2013/07/15 13:25:51 Why do you need the absolute value? isNaN and isIn
ngeoffray 2013/07/15 13:49:27 Done.
+ double doubleValue = absValue.toDouble();
+ return doubleValue.isNaN || doubleValue.isInfinite;
+ }
+
+ /**
* Returns true if the given [value] fits into a double without losing
* precision.
*/
@@ -187,13 +197,20 @@
return value.toDouble().floor().toInt() == value;
}
+
karlklose 2013/07/15 13:52:08 Remove extra line.
ngeoffray 2013/07/15 13:53:38 Done.
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 looses precision with JavaScript numbers, use
karlklose 2013/07/15 13:52:08 'looses' -> 'loses'.
ngeoffray 2013/07/15 13:53:38 Done.
+ // 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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698