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

Unified Diff: src/math.js

Issue 11444030: Iterate through all arguments for side effects in Math.min/max. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years 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 | test/mjsunit/regress/regress-2444.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/math.js
diff --git a/src/math.js b/src/math.js
index aee56af4f9916d526695b91420ad7150fc95792e..46863284f08b1b888400c2065a97b9cd6a2aaa75 100644
--- a/src/math.js
+++ b/src/math.js
@@ -131,19 +131,16 @@ function MathMax(arg1, arg2) { // length == 2
// All comparisons failed, one of the arguments must be NaN.
return 0/0; // Compiler constant-folds this to NaN.
}
- if (length == 0) {
- return -1/0; // Compiler constant-folds this to -Infinity.
- }
- var r = arg1;
- if (!IS_NUMBER(r)) r = NonNumberToNumber(r);
- if (NUMBER_IS_NAN(r)) return r;
- for (var i = 1; i < length; i++) {
+ var r = -1/0; // Compiler constant-folds this to -Infinity.
+ for (var i = 0; i < length; i++) {
var n = %_Arguments(i);
if (!IS_NUMBER(n)) n = NonNumberToNumber(n);
- if (NUMBER_IS_NAN(n)) return n;
// Make sure +0 is considered greater than -0. -0 is never a Smi, +0 can be
// a Smi or heap number.
- if (n > r || (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) r = n;
+ if (NUMBER_IS_NAN(n) || n > r ||
+ (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) {
+ r = n;
+ }
}
return r;
}
@@ -164,19 +161,16 @@ function MathMin(arg1, arg2) { // length == 2
// All comparisons failed, one of the arguments must be NaN.
return 0/0; // Compiler constant-folds this to NaN.
}
- if (length == 0) {
- return 1/0; // Compiler constant-folds this to Infinity.
- }
- var r = arg1;
- if (!IS_NUMBER(r)) r = NonNumberToNumber(r);
- if (NUMBER_IS_NAN(r)) return r;
- for (var i = 1; i < length; i++) {
+ var r = 1/0; // Compiler constant-folds this to Infinity.
+ for (var i = 0; i < length; i++) {
var n = %_Arguments(i);
if (!IS_NUMBER(n)) n = NonNumberToNumber(n);
- if (NUMBER_IS_NAN(n)) return n;
// Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be a
// Smi or a heap number.
- if (n < r || (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) r = n;
+ if (NUMBER_IS_NAN(n) || n < r ||
+ (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) {
+ r = n;
+ }
}
return r;
}
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-2444.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698