Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup: exclude method properties for now
  • Loading branch information
BridgeAR committed Dec 6, 2019
commit 922d66de2e4235d708a8e738e5b5c28b20680918
4 changes: 2 additions & 2 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ changes:
* `options` {Object}
* `showHidden` {boolean} If `true`, `object`'s non-enumerable symbols and
properties are included in the formatted result. [`WeakMap`][] and
[`WeakSet`][] entries are also included as well as prototype properties.
**Default:** `false`.
[`WeakSet`][] entries are also included as well as prototype properties
(excluding method properties). **Default:** `false`.
* `depth` {number} Specifies the number of times to recurse while formatting
`object`. This is useful for inspecting large objects. To recurse up to
the maximum call stack size pass `Infinity` or `null`.
Expand Down
11 changes: 8 additions & 3 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,12 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, isProto, output) {
(depth !== 0 && keySet.has(key))) {
continue;
}
const value = formatProperty(ctx, obj, recurseTimes, key, kObjectType);
const desc = ObjectGetOwnPropertyDescriptor(obj, key);
if (typeof desc.value === 'function') {
continue;
}
const value = formatProperty(
ctx, obj, recurseTimes, key, kObjectType, desc);
if (ctx.colors) {
// Faint!
output.push(`\u001b[2m${value}\u001b[22m`);
Expand Down Expand Up @@ -1509,10 +1514,10 @@ function formatPromise(ctx, value, recurseTimes) {
return output;
}

function formatProperty(ctx, value, recurseTimes, key, type) {
function formatProperty(ctx, value, recurseTimes, key, type, desc) {
let name, str;
let extra = ' ';
const desc = ObjectGetOwnPropertyDescriptor(value, key) ||
desc = desc || ObjectGetOwnPropertyDescriptor(value, key) ||
{ value: value[key], enumerable: true };
if (desc.value !== undefined) {
const diff = (type !== kObjectType || ctx.compact !== true) ? 2 : 3;
Expand Down
17 changes: 2 additions & 15 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2619,13 +2619,7 @@ assert.strictEqual(
' prop2: true,\n' +
' abc: true,\n' +
" [xyz]: [Getter: 'YES!'],\n" +
' [Symbol(nodejs.util.inspect.custom)]: ' +
'[Function: [nodejs.util.inspect.custom]] {\n' +
' [length]: 2,\n' +
" [name]: '[nodejs.util.inspect.custom]'\n" +
' },\n' +
' [def]: [Getter/Setter: false],\n' +
" [func]: [Function: func] { [length]: 1, [name]: 'func' }\n" +
' [def]: [Getter/Setter: false]\n' +
'}'
);
assert.strictEqual(
Expand All @@ -2636,14 +2630,7 @@ assert.strictEqual(
' prop2: \x1B[33mtrue\x1B[39m,\n' +
' abc: \x1B[33mtrue\x1B[39m,\n' +
' \x1B[2m[xyz]: \x1B[36m[Getter]\x1B[39m\x1B[22m,\n' +
' \x1B[2m[\x1B[32mSymbol(nodejs.util.inspect.custom)\x1B[39m]:' +
' [Function: [nodejs.util.inspect.custom]] {\n' +
' [length]: \x1B[33m2\x1B[39m,\n' +
" [name]: \x1B[32m'[nodejs.util.inspect.custom]'\x1B[39m\n" +
' }\x1B[22m,\n' +
' \x1B[2m[def]: \x1B[36m[Getter/Setter]\x1B[39m\x1B[22m,\n' +
' \x1B[2m[func]: [Function: func] { [length]: \x1B[33m1\x1B[39m,' +
" [name]: \x1B[32m'func'\x1B[39m }\x1B[22m\n" +
' \x1B[2m[def]: \x1B[36m[Getter/Setter]\x1B[39m\x1B[22m\n' +
'}'
);
}