diff options
Diffstat (limited to 'lib/internal/util/inspect.js')
-rw-r--r-- | lib/internal/util/inspect.js | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 6ec27b9d1d..f7e5507882 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -99,7 +99,8 @@ const inspectDefaultOptions = Object.seal({ maxArrayLength: 100, breakLength: 60, compact: true, - sorted: false + sorted: false, + getters: false }); const kObjectType = 0; @@ -167,7 +168,8 @@ function inspect(value, opts) { maxArrayLength: inspectDefaultOptions.maxArrayLength, breakLength: inspectDefaultOptions.breakLength, compact: inspectDefaultOptions.compact, - sorted: inspectDefaultOptions.sorted + sorted: inspectDefaultOptions.sorted, + getters: inspectDefaultOptions.getters }; if (arguments.length > 1) { // Legacy... @@ -1131,10 +1133,30 @@ function formatProperty(ctx, value, recurseTimes, key, type) { } ctx.indentationLvl -= diff; } else if (desc.get !== undefined) { - if (desc.set !== undefined) { - str = ctx.stylize('[Getter/Setter]', 'special'); + const label = desc.set !== undefined ? 'Getter/Setter' : 'Getter'; + const s = ctx.stylize; + const sp = 'special'; + if (ctx.getters && (ctx.getters === true || + ctx.getters === 'get' && desc.set === undefined || + ctx.getters === 'set' && desc.set !== undefined)) { + try { + const tmp = value[key]; + ctx.indentationLvl += 2; + if (tmp === null) { + str = `${s(`[${label}:`, sp)} ${s('null', 'null')}${s(']', sp)}`; + } else if (typeof tmp === 'object') { + str = `${s(`[${label}]`, sp)} ${formatValue(ctx, tmp, recurseTimes)}`; + } else { + const primitive = formatPrimitive(s, tmp, ctx); + str = `${s(`[${label}:`, sp)} ${primitive}${s(']', sp)}`; + } + ctx.indentationLvl -= 2; + } catch (err) { + const message = `<Inspection threw (${err.message})>`; + str = `${s(`[${label}:`, sp)} ${message}${s(']', sp)}`; + } } else { - str = ctx.stylize('[Getter]', 'special'); + str = ctx.stylize(`[${label}]`, sp); } } else if (desc.set !== undefined) { str = ctx.stylize('[Setter]', 'special'); |