Bug 621061: Add a testing function to return a double-typed number. r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D81317
This commit is contained in:
André Bargull 2020-06-26 17:44:24 +00:00
Родитель dcaaec0f7b
Коммит 4c855c60d7
11 изменённых файлов: 45 добавлений и 21 удалений

Просмотреть файл

@ -5880,6 +5880,22 @@ static bool NewPrivateName(JSContext* cx, unsigned argc, Value* vp) {
return true;
}
static bool NumberToDouble(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
if (!args.requireAtLeast(cx, "numberToDouble", 1)) {
return false;
}
if (!args[0].isNumber()) {
RootedObject callee(cx, &args.callee());
ReportUsageErrorASCII(cx, callee, "argument must be a number");
return false;
}
args.rval().setDouble(args[0].toNumber());
return true;
}
static bool PCCountProfiling_Start(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
@ -6841,6 +6857,10 @@ gc::ZealModeHelpText),
"newPrivateName(desc)",
"Create a new PrivateName symbol."),
JS_FN_HELP("numberToDouble", NumberToDouble, 1, 0,
"numberToDouble(number)",
" Return the input number as double-typed number."),
JS_FS_HELP_END
};
// clang-format on

Просмотреть файл

@ -21,6 +21,6 @@ assertEq(parseInt(-0, 10), 0);
assertEq(parseInt('0', 10), 0);
assertEq(parseInt('-0', 10), -0);
/* this is not very hacky, but we try to get a double value of 0, instead of int */
assertEq(parseInt(Math.asin(0), 10), 0);
assertEq(parseInt(Math.asin(-0), 10), 0);
// Test with 0 typed as a double instead of int.
assertEq(parseInt(numberToDouble(0), 10), 0);
assertEq(parseInt(numberToDouble(-0), 10), 0);

Просмотреть файл

@ -59,8 +59,8 @@ var xs = [
];
function Double(x) {
// Math.hypot always returns a Double valued number.
return x < 0 ? -Math.hypot(x) : Math.hypot(x);
// numberToDouble always returns a Double valued number.
return numberToDouble(x);
}
// Compute the Double approximation of the BigInt values.

Просмотреть файл

@ -31,8 +31,8 @@ var ys = [
];
function Double(x) {
// Math.hypot always returns a Double valued number.
return x < 0 ? -Math.hypot(x) : Math.hypot(x);
// numberToDouble always returns a Double valued number.
return numberToDouble(x);
}
var zs = [

Просмотреть файл

@ -16,9 +16,9 @@ for (var i = 0; i < 30; i++) {
get_thee(A, i % A.length);
}
// Math.hypot currently always returns a Number, so helps
// us ensure we're accessing the array with a Number index.
var y = Math.hypot(1,0);
// numberToDouble always returns a double-typed Number, so helps
// us ensure we're accessing the array with a double-typed Number index.
var y = numberToDouble(1);
var z = 2**31-1;
// Ensure we handle negative indices.
var a = -1;

Просмотреть файл

@ -19,7 +19,7 @@ assertThrowsInstanceOf(function () { dbg.findScripts({url:4}); }, TypeError);
assertThrowsInstanceOf(function () { dbg.findScripts({url:{}}); }, TypeError);
assertEq(dbg.findScripts({url:"", line:1}).length, 0);
assertEq(dbg.findScripts({url:"", line:Math.sqrt(4)}).length, 0);
assertEq(dbg.findScripts({url:"", line:numberToDouble(2)}).length, 0);
// A 'line' property without a 'url' property is verboten.
assertThrowsInstanceOf(function () { dbg.findScripts({line:1}); }, TypeError);

Просмотреть файл

@ -21,8 +21,8 @@ function test(x) {
}
function double(v) {
// NB: Math.cbrt() always returns a double value.
return Math.cbrt(v * v * v)
// NB: numberToDouble() always returns a double value.
return numberToDouble(v);
}
// Find the first power which will exceed the Int32 range by computing ⌈log_x(2 ^ 31)⌉.

Просмотреть файл

@ -21,8 +21,8 @@ function test(x, y, z) {
}
function double(v) {
// NB: Math.cbrt() always returns a double value.
return `Math.cbrt(${v * v * v})`;
// NB: numberToDouble() always returns a double value.
return `numberToDouble(${v})`;
}
function addTests(fn) {

Просмотреть файл

@ -19,8 +19,8 @@ function test(x, y, z) {
}
function double(v) {
// NB: Math.cbrt() always returns a double value.
return `Math.cbrt(${v * v * v})`;
// NB: numberToDouble() always returns a double value.
return `numberToDouble(${v})`;
}
function addTests(fn) {

Просмотреть файл

@ -7,8 +7,8 @@ function f(n) {
// for the TypedArray index conversion.
const r = n === 0 ? undefined : 0;
// Math.cbrt always returns a double number.
const k = Math.cbrt(0);
// numberToDouble always returns a double number.
const k = numberToDouble(0);
for (var i = 0; i < 10; ++i) {
assertEq(ta[k], r);

Просмотреть файл

@ -17,6 +17,10 @@ var expect = '';
if (typeof gczeal !== 'undefined')
gczeal(0)
if (typeof numberToDouble !== 'function') {
var numberToDouble = SpecialPowers.Cu.getJSTestingFunctions().numberToDouble;
}
test();
//-----------------------------------------------------------------------------
@ -493,9 +497,9 @@ function test()
check(() => (new Int32Array(0)).BYTES_PER_ELEMENT == 4);
check(() => Int16Array.BYTES_PER_ELEMENT == Uint16Array.BYTES_PER_ELEMENT);
// test various types of args; Math.sqrt(4) is used to ensure that the
// test various types of args; numberToDouble(2) is used to ensure that the
// function gets a double, and not a demoted int
check(() => (new Float32Array(Math.sqrt(4))).length == 2);
check(() => (new Float32Array(numberToDouble(2))).length == 2);
check(() => (new Float32Array({ length: 10 })).length == 10);
check(() => (new Float32Array({})).length == 0);
check(() => new Float32Array("3").length === 3);