[INFER] Add overflow check for Math.pow(1, x), bug 642154. r=bhackett

This commit is contained in:
Jan de Mooij 2011-03-16 12:17:06 -07:00
parent db525548f6
commit ae5397c993
2 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,16 @@
assertEq(Math.pow(1, undefined), NaN);
assertEq(Math.pow(1, null), 1);
assertEq(Math.pow(1, true), 1);
assertEq(Math.pow(1, false), 1);
assertEq(Math.pow(1, 0), 1);
assertEq(Math.pow(1, -0), 1);
assertEq(Math.pow(1, NaN), NaN);
assertEq(Math.pow(1, {}), NaN);
assertEq(Math.pow(1, {valueOf: function() { return undefined; }}), NaN);
x = 2.2;
assertEq(Math.pow(x - 1.2, undefined), NaN);
var y;
assertEq(Math.pow(1, y), NaN);

View File

@ -504,7 +504,7 @@ math_pow(JSContext *cx, uintN argc, Value *vp)
*/
if (!JSDOUBLE_IS_FINITE(y) && (x == 1.0 || x == -1.0)) {
vp->setDouble(js_NaN);
return JS_TRUE;
return vp[3].isDouble() || cx->markTypeCallerOverflow();
}
/* pow(x, +-0) is always 1, even for x = NaN. */
if (y == 0) {