mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
util: inspect __proto__ key as written in object literal
Since util.inspect() gives object-literal-like output, handle the special `__proto__` key in the way that it would be handled in object literals. PR-URL: https://github.com/nodejs/node/pull/37713 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
1 parent
1022d3d947
commit
80af610d95
2 files changed
+9
No files matched your search
@@ -1718,6 +1718,8 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
|
||||
strEscapeSequencesReplacer, escapeFn
|
||||
);
|
||||
name = `[${ctx.stylize(tmp, 'symbol')}]`;
|
||||
} else if (key === '__proto__') {
|
||||
name = "['__proto__']";
|
||||
} else if (desc.enumerable === false) {
|
||||
const tmp = StringPrototypeReplace(key,
|
||||
strEscapeSequencesReplacer, escapeFn);
|
||||
|
||||
@@ -3095,3 +3095,10 @@ assert.strictEqual(
|
||||
']'
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
assert.strictEqual(
|
||||
util.inspect({ ['__proto__']: { a: 1 } }),
|
||||
"{ ['__proto__']: { a: 1 } }"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user