Skip to content

Commit 79df127

Browse files
author
Chenyu Yang
committed
inspector: correct %s format behavior with Symbol.toPrimitive
Ensure console.log("%s", obj) correctly invokes obj[Symbol.toPrimitive] for string conversion, fixing unexpected object display issue. Fixes: #50909
1 parent 454d080 commit 79df127

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/internal/util/inspect.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ const {
151151
const assert = require('internal/assert');
152152

153153
const { BuiltinModule } = require('internal/bootstrap/realm');
154+
const { SymbolToPrimitive } = primordials;
154155
const {
155156
validateObject,
156157
validateString,
@@ -2204,6 +2205,10 @@ function formatWithOptionsInternal(inspectOptions, args) {
22042205
tempArg === null ||
22052206
!hasBuiltInToString(tempArg)) {
22062207
tempStr = String(tempArg);
2208+
} else if (hasBuiltInToString(tempArg) &&
2209+
getProxyDetails(tempArg, false) === undefined &&
2210+
tempArg[SymbolToPrimitive] !== undefined) {
2211+
tempStr = tempArg[SymbolToPrimitive]('string');
22072212
} else {
22082213
tempStr = inspect(tempArg, {
22092214
...inspectOptions,

0 commit comments

Comments
 (0)