Skip to content
Closed
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
20 changes: 20 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,26 @@ assert.strictEqual(
"'foobar', { x: 1 } },\n inc: [Getter: NaN]\n}");
}

// Property getter returning a function.
{
const getterFn = {
get getString() { return 'foo'; },
string: 'foo',
get getObject() { return { nested: true }; },
object: { nested: true },
get getFunction() { return function fn() {}; },
function: function fn() {},
};
assert.strictEqual(
inspect(getterFn, { getters: true }),
"{ getString: [Getter: 'foo'],\n" +
" string: 'foo',\n" +
' getObject: [Getter] { nested: true },\n' +
" object: { nested: true },\n" +
' getFunction: [Getter] [Function: fn],\n' +
' function: [Function: fn] }');
}

// Property getter throwing an error.
{
const error = new Error('Oops');
Expand Down
Loading