Bug 1941380 - Cap console log string substitution precision for floating point numbers. r=baku,devtools-reviewers,jdescottes.
Test cases are added to check we're handling things correctly. Differential Revision: https://phabricator.services.mozilla.com/D236109
This commit is contained in:
@@ -293,6 +293,37 @@ function getExpectedRuntimeConsoleCalls(documentFilename) {
|
|||||||
level: "log",
|
level: "log",
|
||||||
arguments: ["Float from number: 1.300000"],
|
arguments: ["Float from number: 1.300000"],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
...defaultProperties,
|
||||||
|
level: "log",
|
||||||
|
arguments: ["Float from number with precision: 1.00"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...defaultProperties,
|
||||||
|
level: "log",
|
||||||
|
arguments: [
|
||||||
|
// Even if a precision of 200 was requested, it's capped at 15
|
||||||
|
`Float from number with high precision: 2.${"0".repeat(15)}`,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...defaultProperties,
|
||||||
|
level: "log",
|
||||||
|
arguments: ["Integer from number: 3"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...defaultProperties,
|
||||||
|
level: "log",
|
||||||
|
arguments: ["Integer from number with precision: 04"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...defaultProperties,
|
||||||
|
level: "log",
|
||||||
|
arguments: [
|
||||||
|
// The precision is not capped for integers
|
||||||
|
`Integer from number with high precision: ${"5".padStart(200, "0")}`,
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
...defaultProperties,
|
...defaultProperties,
|
||||||
level: "log",
|
level: "log",
|
||||||
@@ -552,6 +583,11 @@ async function logRuntimeMessages(browser, executeInIframe) {
|
|||||||
console.log("Float from not a number: %f", "foo");
|
console.log("Float from not a number: %f", "foo");
|
||||||
console.log("Float from string: %f", "1.2");
|
console.log("Float from string: %f", "1.2");
|
||||||
console.log("Float from number: %f", 1.3);
|
console.log("Float from number: %f", 1.3);
|
||||||
|
console.log("Float from number with precision: %.2f", 1);
|
||||||
|
console.log("Float from number with high precision: %.200f", 2);
|
||||||
|
console.log("Integer from number: %i", 3.14);
|
||||||
|
console.log("Integer from number with precision: %.2i", 4);
|
||||||
|
console.log("Integer from number with high precision: %.200i", 5);
|
||||||
console.log("BigInt %d and %i", 123n, 456n);
|
console.log("BigInt %d and %i", 123n, 456n);
|
||||||
console.log(
|
console.log(
|
||||||
"%cmessage with %cstyle",
|
"%cmessage with %cstyle",
|
||||||
|
|||||||
@@ -2046,7 +2046,7 @@ static bool ProcessArguments(JSContext* aCx, const Sequence<JS::Value>& aData,
|
|||||||
output.AppendFloat(v);
|
output.AppendFloat(v);
|
||||||
} else {
|
} else {
|
||||||
nsCString format;
|
nsCString format;
|
||||||
MakeFormatString(format, integer, mantissa, 'f');
|
MakeFormatString(format, integer, std::min(mantissa, 15), 'f');
|
||||||
output.AppendPrintf(format.get(), v);
|
output.AppendPrintf(format.get(), v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user