Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,7 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
const tmp = FunctionPrototypeCall(desc.get, original);
if (tmp === null) {
str = `${s(`[${label}:`, sp)} ${s('null', 'null')}${s(']', sp)}`;
} else if (typeof tmp === 'object') {
} else if (typeof tmp === 'object' || typeof tmp === 'function') {
str = `${s(`[${label}]`, sp)} ${formatValue(ctx, tmp, recurseTimes)}`;
} else {
const primitive = formatPrimitive(s, tmp, ctx);
Expand Down
22 changes: 14 additions & 8 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,15 @@
"'foobar', { x: 1 } },\n inc: [Getter: NaN]\n}");
}

// Getter returning a function.
// https://github.com/nodejs/node/issues/64838
{
const obj = { get foo() { return function bar(){}; } };

Check failure on line 2602 in test/parallel/test-util-inspect.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing space before opening brace
assert.strictEqual(
inspect(obj, { getters: true }),
'{ foo: [Getter] [Function: bar] }');
}

// Property getter throwing an error.
{
const error = new Error('Oops');
Expand Down Expand Up @@ -3524,16 +3533,14 @@
'\x1B[2mdef: \x1B[33m5\x1B[39m\x1B[22m }'
);

assert.match(
assert.strictEqual(
inspect(Object.getPrototypeOf(bar), { showHidden: true, getters: true }),
new RegExp('^' + RegExp.escape(
'<ref *1> Foo [Map] {\n' +
' [constructor]: [class Bar extends Foo] {\n' +
'<ref *2> Foo [Map] {\n' +
' [constructor]: <ref *1> [class Bar extends Foo] {\n' +
' [length]: 0,\n' +
" [name]: 'Bar',\n" +
' [prototype]: [Circular *1],\n' +
' [Symbol(Symbol.species)]: [Getter: <Inspection threw ' +
"(TypeError: Symbol.prototype.toString requires that 'this' be a Symbol") + '.*' + RegExp.escape(')>]\n' +
' [prototype]: [Circular *2],\n' +
' [Symbol(Symbol.species)]: [Getter] [Circular *1]\n' +
' },\n' +
" [xyz]: [Getter: 'YES!'],\n" +
' [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]] {\n' +
Expand All @@ -3543,7 +3550,6 @@
' [abc]: [Getter: true],\n' +
' [def]: [Getter/Setter: false]\n' +
'}'
) + '$', 's')
);

assert.strictEqual(
Expand Down
Loading