util: use a shared symbol for util.inspect.custom

Define `util.inspect.custom` as
`Symbol.for("nodejs.util.inspect.custom")` rather than
`Symbol("util.inspect.custom")`. This allows `inspect` hooks to
easily/safely be defined in non-Node.js environments.

Fixes: https://github.com/nodejs/node/issues/20821
Refs: https://github.com/nodejs/node/pull/22684

Backport-PR-URL: https://github.com/nodejs/node/pull/23039
PR-URL: https://github.com/nodejs/node/pull/20857
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
This commit is contained in:
chocolateboy authored and Michaël Zasso committed 2018-09-24 21:37:50 +02:00
1 parent 077e7e0ce7
commit a2a1ebfecf
5 files changed
+69 -17

No files matched your search

+1 -1
View File
@@ -594,7 +594,7 @@ assert.throws(
'- {}\n' +
'+ {\n' +
"+ loop: 'forever',\n" +
'+ [Symbol(util.inspect.custom)]: [Function]\n' +
'+ [Symbol(nodejs.util.inspect.custom)]: [Function]\n' +
'+ }'
});