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

Unified Diff: src/math.js

Issue 149188: Fix the order in which ToNumber is called for some Math functions.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 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 | test/mjsunit/to_number_order.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/math.js
===================================================================
--- src/math.js (revision 2356)
+++ src/math.js (working copy)
@@ -68,10 +68,12 @@
}
// ECMA 262 - 15.8.2.5
-function MathAtan2(x, y) {
+// The naming of y and x matches the spec, as does the order in which
+// ToNumber (valueOf) is called.
+function MathAtan2(y, x) {
+ if (!IS_NUMBER(y)) y = ToNumber(y);
if (!IS_NUMBER(x)) x = ToNumber(x);
- if (!IS_NUMBER(y)) y = ToNumber(y);
- return %Math_atan2(x, y);
+ return %Math_atan2(y, x);
}
// ECMA 262 - 15.8.2.6
@@ -117,11 +119,12 @@
// ECMA 262 - 15.8.2.11
function MathMax(arg1, arg2) { // length == 2
var r = -$Infinity;
- for (var i = %_ArgumentsLength() - 1; i >= 0; --i) {
+ var length = %_ArgumentsLength();
+ for (var i = 0; i < length; i++) {
var n = ToNumber(%_Arguments(i));
if (NUMBER_IS_NAN(n)) return n;
- // Make sure +0 is consider greater than -0.
- if (n > r || (n === 0 && r === 0 && (1 / n) > (1 / r))) r = n;
+ // Make sure +0 is considered greater than -0.
+ if (n > r || (r === 0 && n === 0 && !%_IsSmi(r))) r = n;
}
return r;
}
@@ -129,11 +132,12 @@
// ECMA 262 - 15.8.2.12
function MathMin(arg1, arg2) { // length == 2
var r = $Infinity;
- for (var i = %_ArgumentsLength() - 1; i >= 0; --i) {
+ var length = %_ArgumentsLength();
+ for (var i = 0; i < length; i++) {
var n = ToNumber(%_Arguments(i));
if (NUMBER_IS_NAN(n)) return n;
- // Make sure -0 is consider less than +0.
- if (n < r || (n === 0 && r === 0 && (1 / n) < (1 / r))) r = n;
+ // Make sure -0 is considered less than +0.
+ if (n < r || (r === 0 && n === 0 && !%_IsSmi(n))) r = n;
}
return r;
}
« no previous file with comments | « no previous file | test/mjsunit/to_number_order.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698