From 6f80a45528479f255c2fd25e82ce012ffb70c50c Mon Sep 17 00:00:00 2001 From: Paul Isache Date: Tue, 6 Nov 2018 15:57:45 +0000 Subject: [PATCH] lib: combine contructor, tag, Object into a function combine these parts into a function to be used in multiple parts PR-URL: https://github.com/nodejs/node/pull/24171 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater --- lib/internal/util/inspect.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 4cff372b330ec1..ca06064085422c 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -400,6 +400,10 @@ function getKeys(value, showHidden) { return keys; } +function getCtxStyle(constructor, tag) { + return constructor || tag || 'Object'; +} + function formatProxy(ctx, proxy, recurseTimes) { if (recurseTimes != null) { if (recurseTimes < 0) @@ -741,7 +745,7 @@ function formatRaw(ctx, value, recurseTimes) { if (recurseTimes != null) { if (recurseTimes < 0) - return ctx.stylize(`[${constructor || tag || 'Object'}]`, 'special'); + return ctx.stylize(`[${getCtxStyle(constructor, tag)}]`, 'special'); recurseTimes -= 1; } @@ -793,7 +797,7 @@ function handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl) { ctx.seen.pop(); ctx.indentationLvl = indentationLvl; return ctx.stylize( - `[${constructor || tag || 'Object'}: Inspection interrupted ` + + `[${getCtxStyle(constructor, tag)}: Inspection interrupted ` + 'prematurely. Maximum call stack size exceeded.]', 'special' );