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:
Nicolas Chevobbe
2025-02-05 13:00:40 +00:00
parent e15e183ff3
commit ff34f67aa7
2 changed files with 37 additions and 1 deletions

View File

@@ -293,6 +293,37 @@ function getExpectedRuntimeConsoleCalls(documentFilename) {
level: "log",
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,
level: "log",
@@ -552,6 +583,11 @@ async function logRuntimeMessages(browser, executeInIframe) {
console.log("Float from not a number: %f", "foo");
console.log("Float from string: %f", "1.2");
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(
"%cmessage with %cstyle",