mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 795745 - Properly report errors for Number.prototype.to* methods when a provided precision is invalid. r=luke
This commit is contained in:
parent
f3daa82807
commit
68238fd960
@ -789,10 +789,10 @@ ComputePrecisionInRange(JSContext *cx, int minPrecision, int maxPrecision, const
|
||||
*precision = int(prec);
|
||||
return true;
|
||||
}
|
||||
|
||||
ToCStringBuf cbuf;
|
||||
char *numStr = IntToCString(&cbuf, *precision);
|
||||
JS_ASSERT(numStr);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_PRECISION_RANGE, numStr);
|
||||
if (char *numStr = NumberToCString(cx, &cbuf, prec, 10))
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_PRECISION_RANGE, numStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
46
js/src/tests/ecma_5/Number/conversion-invalid-precision.js
Normal file
46
js/src/tests/ecma_5/Number/conversion-invalid-precision.js
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommonn.org/licenses/publicdomain/
|
||||
*/
|
||||
|
||||
var BUGNUMBER = 795745;
|
||||
var summary =
|
||||
"Number.prototype.to* should throw a RangeError when passed a bad precision";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
function test(method, prec)
|
||||
{
|
||||
try
|
||||
{
|
||||
Number.prototype[method].call(0, prec);
|
||||
throw "should have thrown";
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
assertEq(e instanceof RangeError, true,
|
||||
"expected RangeError for " + method + " with precision " + prec +
|
||||
", got " + e);
|
||||
}
|
||||
}
|
||||
|
||||
test("toExponential", -32);
|
||||
test("toFixed", -32);
|
||||
test("toPrecision", -32);
|
||||
|
||||
test("toExponential", 9999999);
|
||||
test("toFixed", 9999999);
|
||||
test("toPrecision", 9999999);
|
||||
|
||||
test("toPrecision", 0);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
||||
print("Tests complete");
|
Loading…
Reference in New Issue
Block a user