util: fix indentationLvl when exceeding max call stack size

The inspection indentation level was not always reset to it's former
value in case the maximum call stack size was exceeded.

PR-URL: https://github.com/nodejs/node/pull/22787
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater 2018-09-10 08:16:12 +02:00
parent 9c6f59ed3a
commit 08d983c3b9
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -880,6 +880,7 @@ function formatRaw(ctx, value, recurseTimes) {
ctx.seen.push(value);
let output;
const indentationLvl = ctx.indentationLvl;
try {
output = formatter(ctx, value, recurseTimes, keys);
if (skip === false) {
@ -889,7 +890,7 @@ function formatRaw(ctx, value, recurseTimes) {
}
}
} catch (err) {
return handleMaxCallStackSize(ctx, err, constructor, tag);
return handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl);
}
ctx.seen.pop();
@ -910,9 +911,10 @@ function formatRaw(ctx, value, recurseTimes) {
return res;
}
function handleMaxCallStackSize(ctx, err, constructor, tag) {
function handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl) {
if (errors.isStackOverflowError(err)) {
ctx.seen.pop();
ctx.indentationLvl = indentationLvl;
return ctx.stylize(
`[${constructor || tag || 'Object'}: Inspection interrupted ` +
'prematurely. Maximum call stack size exceeded.]',