diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 193ae8524632a0..a9e49a65b628c7 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -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); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 1e305f0a45fb7c..da5b65ad60e0a0 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -2596,6 +2596,15 @@ assert.strictEqual( "'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(){}; } }; + assert.strictEqual( + inspect(obj, { getters: true }), + '{ foo: [Getter] [Function: bar] }'); +} + // Property getter throwing an error. { const error = new Error('Oops'); @@ -3524,16 +3533,14 @@ assert.strictEqual( '\x1B[2mdef: \x1B[33m5\x1B[39m\x1B[22m }' ); - assert.match( + assert.strictEqual( inspect(Object.getPrototypeOf(bar), { showHidden: true, getters: true }), - new RegExp('^' + RegExp.escape( - ' Foo [Map] {\n' + - ' [constructor]: [class Bar extends Foo] {\n' + + ' Foo [Map] {\n' + + ' [constructor]: [class Bar extends Foo] {\n' + ' [length]: 0,\n' + " [name]: 'Bar',\n" + - ' [prototype]: [Circular *1],\n' + - ' [Symbol(Symbol.species)]: [Getter: ]\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' + @@ -3543,7 +3550,6 @@ assert.strictEqual( ' [abc]: [Getter: true],\n' + ' [def]: [Getter/Setter: false]\n' + '}' - ) + '$', 's') ); assert.strictEqual(