util: convert inspect.styles and inspect.colors to prototype-less objects
Use a prototype-less object for inspect.styles and inspect.colors to allow modification of Object.prototype in the REPL. Fixes: https://github.com/nodejs/node/issues/11614 PR-URL: https://github.com/nodejs/node/pull/11624 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This commit is contained in:
parent
fd17e8b8d2
commit
aab0d202f8
@ -166,7 +166,7 @@ Object.defineProperty(inspect, 'defaultOptions', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
||||||
inspect.colors = {
|
inspect.colors = Object.assign(Object.create(null), {
|
||||||
'bold': [1, 22],
|
'bold': [1, 22],
|
||||||
'italic': [3, 23],
|
'italic': [3, 23],
|
||||||
'underline': [4, 24],
|
'underline': [4, 24],
|
||||||
@ -180,10 +180,10 @@ inspect.colors = {
|
|||||||
'magenta': [35, 39],
|
'magenta': [35, 39],
|
||||||
'red': [31, 39],
|
'red': [31, 39],
|
||||||
'yellow': [33, 39]
|
'yellow': [33, 39]
|
||||||
};
|
});
|
||||||
|
|
||||||
// Don't use 'blue' not visible on cmd.exe
|
// Don't use 'blue' not visible on cmd.exe
|
||||||
inspect.styles = {
|
inspect.styles = Object.assign(Object.create(null), {
|
||||||
'special': 'cyan',
|
'special': 'cyan',
|
||||||
'number': 'yellow',
|
'number': 'yellow',
|
||||||
'boolean': 'yellow',
|
'boolean': 'yellow',
|
||||||
@ -194,7 +194,7 @@ inspect.styles = {
|
|||||||
'date': 'magenta',
|
'date': 'magenta',
|
||||||
// "name": intentionally not styling
|
// "name": intentionally not styling
|
||||||
'regexp': 'red'
|
'regexp': 'red'
|
||||||
};
|
});
|
||||||
|
|
||||||
const customInspectSymbol = internalUtil.customInspectSymbol;
|
const customInspectSymbol = internalUtil.customInspectSymbol;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user