summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/internal/util/inspect.js23
-rw-r--r--test/parallel/test-util-inspect.js9
2 files changed, 23 insertions, 9 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index dde2066294..3664c15484 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -119,6 +119,8 @@ const builtInObjects = new Set(
ObjectGetOwnPropertyNames(global).filter((e) => /^([A-Z][a-z]+)+$/.test(e))
);
+// These options must stay in sync with `getUserOptions`. So if any option will
+// be added or removed, `getUserOptions` must also be updated accordingly.
const inspectDefaultOptions = ObjectSeal({
showHidden: false,
depth: 2,
@@ -176,13 +178,20 @@ const meta = [
];
function getUserOptions(ctx) {
- const obj = { stylize: ctx.stylize };
- for (const key of ObjectKeys(inspectDefaultOptions)) {
- obj[key] = ctx[key];
- }
- if (ctx.userOptions === undefined)
- return obj;
- return { ...obj, ...ctx.userOptions };
+ return {
+ stylize: ctx.stylize,
+ showHidden: ctx.showHidden,
+ depth: ctx.depth,
+ colors: ctx.colors,
+ customInspect: ctx.customInspect,
+ showProxy: ctx.showProxy,
+ maxArrayLength: ctx.maxArrayLength,
+ breakLength: ctx.breakLength,
+ compact: ctx.compact,
+ sorted: ctx.sorted,
+ getters: ctx.getters,
+ ...ctx.userOptions
+ };
}
/**
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index fd699c85f0..0d905b1e72 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -884,6 +884,10 @@ util.inspect({ hasOwnProperty: null });
assert.strictEqual(opts.budget, undefined);
assert.strictEqual(opts.indentationLvl, undefined);
assert.strictEqual(opts.showHidden, false);
+ assert.deepStrictEqual(
+ new Set(Object.keys(util.inspect.defaultOptions).concat(['stylize'])),
+ new Set(Object.keys(opts))
+ );
opts.showHidden = true;
return { [util.inspect.custom]: common.mustCall((depth, opts2) => {
assert.deepStrictEqual(clone, opts2);
@@ -910,10 +914,11 @@ util.inspect({ hasOwnProperty: null });
}
{
- const subject = { [util.inspect.custom]: common.mustCall((depth) => {
+ const subject = { [util.inspect.custom]: common.mustCall((depth, opts) => {
assert.strictEqual(depth, null);
+ assert.strictEqual(opts.compact, true);
}) };
- util.inspect(subject, { depth: null });
+ util.inspect(subject, { depth: null, compact: true });
}
{