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:
Anna Henningsen authored and Danielle Adams committed 2021-03-16 12:31:43 -04:00
1 parent 1022d3d947
commit 80af610d95
2 files changed
+9

No files matched your search

+2
View File
@@ -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);
+7
View File
@@ -3095,3 +3095,10 @@ assert.strictEqual(
']'
);
}
{
assert.strictEqual(
util.inspect({ ['__proto__']: { a: 1 } }),
"{ ['__proto__']: { a: 1 } }"
);
}