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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/to_number_order.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return %Math_asin(x); 61 return %Math_asin(x);
62 } 62 }
63 63
64 // ECMA 262 - 15.8.2.4 64 // ECMA 262 - 15.8.2.4
65 function MathAtan(x) { 65 function MathAtan(x) {
66 if (!IS_NUMBER(x)) x = ToNumber(x); 66 if (!IS_NUMBER(x)) x = ToNumber(x);
67 return %Math_atan(x); 67 return %Math_atan(x);
68 } 68 }
69 69
70 // ECMA 262 - 15.8.2.5 70 // ECMA 262 - 15.8.2.5
71 function MathAtan2(x, y) { 71 // The naming of y and x matches the spec, as does the order in which
72 // ToNumber (valueOf) is called.
73 function MathAtan2(y, x) {
74 if (!IS_NUMBER(y)) y = ToNumber(y);
72 if (!IS_NUMBER(x)) x = ToNumber(x); 75 if (!IS_NUMBER(x)) x = ToNumber(x);
73 if (!IS_NUMBER(y)) y = ToNumber(y); 76 return %Math_atan2(y, x);
74 return %Math_atan2(x, y);
75 } 77 }
76 78
77 // ECMA 262 - 15.8.2.6 79 // ECMA 262 - 15.8.2.6
78 function MathCeil(x) { 80 function MathCeil(x) {
79 if (!IS_NUMBER(x)) x = ToNumber(x); 81 if (!IS_NUMBER(x)) x = ToNumber(x);
80 return %Math_ceil(x); 82 return %Math_ceil(x);
81 } 83 }
82 84
83 // ECMA 262 - 15.8.2.7 85 // ECMA 262 - 15.8.2.7
84 function MathCos(x) { 86 function MathCos(x) {
(...skipping 25 matching lines...) Expand all
110 112
111 // ECMA 262 - 15.8.2.10 113 // ECMA 262 - 15.8.2.10
112 function MathLog(x) { 114 function MathLog(x) {
113 if (!IS_NUMBER(x)) x = ToNumber(x); 115 if (!IS_NUMBER(x)) x = ToNumber(x);
114 return %Math_log(x); 116 return %Math_log(x);
115 } 117 }
116 118
117 // ECMA 262 - 15.8.2.11 119 // ECMA 262 - 15.8.2.11
118 function MathMax(arg1, arg2) { // length == 2 120 function MathMax(arg1, arg2) { // length == 2
119 var r = -$Infinity; 121 var r = -$Infinity;
120 for (var i = %_ArgumentsLength() - 1; i >= 0; --i) { 122 var length = %_ArgumentsLength();
123 for (var i = 0; i < length; i++) {
121 var n = ToNumber(%_Arguments(i)); 124 var n = ToNumber(%_Arguments(i));
122 if (NUMBER_IS_NAN(n)) return n; 125 if (NUMBER_IS_NAN(n)) return n;
123 // Make sure +0 is consider greater than -0. 126 // Make sure +0 is considered greater than -0.
124 if (n > r || (n === 0 && r === 0 && (1 / n) > (1 / r))) r = n; 127 if (n > r || (r === 0 && n === 0 && !%_IsSmi(r))) r = n;
125 } 128 }
126 return r; 129 return r;
127 } 130 }
128 131
129 // ECMA 262 - 15.8.2.12 132 // ECMA 262 - 15.8.2.12
130 function MathMin(arg1, arg2) { // length == 2 133 function MathMin(arg1, arg2) { // length == 2
131 var r = $Infinity; 134 var r = $Infinity;
132 for (var i = %_ArgumentsLength() - 1; i >= 0; --i) { 135 var length = %_ArgumentsLength();
136 for (var i = 0; i < length; i++) {
133 var n = ToNumber(%_Arguments(i)); 137 var n = ToNumber(%_Arguments(i));
134 if (NUMBER_IS_NAN(n)) return n; 138 if (NUMBER_IS_NAN(n)) return n;
135 // Make sure -0 is consider less than +0. 139 // Make sure -0 is considered less than +0.
136 if (n < r || (n === 0 && r === 0 && (1 / n) < (1 / r))) r = n; 140 if (n < r || (r === 0 && n === 0 && !%_IsSmi(n))) r = n;
137 } 141 }
138 return r; 142 return r;
139 } 143 }
140 144
141 // ECMA 262 - 15.8.2.13 145 // ECMA 262 - 15.8.2.13
142 function MathPow(x, y) { 146 function MathPow(x, y) {
143 if (!IS_NUMBER(x)) x = ToNumber(x); 147 if (!IS_NUMBER(x)) x = ToNumber(x);
144 if (!IS_NUMBER(y)) y = ToNumber(y); 148 if (!IS_NUMBER(y)) y = ToNumber(y);
145 return %Math_pow(x, y); 149 return %Math_pow(x, y);
146 } 150 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 "tan", MathTan, 239 "tan", MathTan,
236 "atan2", MathAtan2, 240 "atan2", MathAtan2,
237 "pow", MathPow, 241 "pow", MathPow,
238 "max", MathMax, 242 "max", MathMax,
239 "min", MathMin 243 "min", MathMin
240 )); 244 ));
241 }; 245 };
242 246
243 247
244 SetupMath(); 248 SetupMath();
OLDNEW
« 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