Repository navigation
console.log("%s", { [Symbol.toPrimitive]: () => "hello" }) shows the object, not "hello" #50909
Copy link
Copy link
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.consoleIssues and PRs related to the console subsystem.Issues and PRs related to the console subsystem.
Description
Activity
According to the spec, this is a bug in node.js
Spec:
Reacted by Jithil P Ponnan- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.consoleIssues and PRs related to the console subsystem.Issues and PRs related to the console subsystem.
on Nov 25, 2023 Looking into it.
I believe this is because
console.log("%s", o)callsinspectto obtain the object.node/lib/internal/util/inspect.js
Lines 2197 to 2216 in 2f40652
case 115: { // 's' const tempArg = args[++a]; if (typeof tempArg === 'number') { tempStr = formatNumberNoColor(tempArg, inspectOptions); } else if (typeof tempArg === 'bigint') { tempStr = formatBigIntNoColor(tempArg, inspectOptions); } else if (typeof tempArg !== 'object' || tempArg === null || !hasBuiltInToString(tempArg)) { tempStr = String(tempArg); } else { tempStr = inspect(tempArg, { ...inspectOptions, compact: 3, colors: false, depth: 0, }); } break; } - added a commit that references this issue
on May 11, 2024 - added a commit that references this issue
on May 12, 2024 - added a commit that references this issue
on May 12, 2024 - added a commit that references this issue
on Jun 20, 2024
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.consoleIssues and PRs related to the console subsystem.Issues and PRs related to the console subsystem.
Version
v21.2.0
Platform
Linux PIG-2016 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
inspect
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
deno does:
chrome browser does:
bun does:
firefox browser does:
makes sense; it has a stringifier so it should act just like it would if it had a toString() which Node.js does recognize:
What do you see instead?
Additional information
No response