Skip to content
Merged
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
6 changes: 3 additions & 3 deletions lib/internal/util/inspect.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -989,7 +989,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray){
keys = getKeys(value, ctx.showHidden);
braces = ['{', '}'];
if (typeof value === 'function'){
base = getFunctionBase(value, constructor, tag);
base = getFunctionBase(ctx, value, constructor, tag);
if (keys.length === 0 && protoProps === undefined)
return ctx.stylize(base, 'special');
} else if (constructor === 'Object'){
Expand DownExpand Up@@ -1223,7 +1223,7 @@ function getClassBase(value, constructor, tag){
return `[${base}]`;
}

function getFunctionBase(value, constructor, tag){
function getFunctionBase(ctx, value, constructor, tag){
const stringified = FunctionPrototypeToString(value);
if (StringPrototypeStartsWith(stringified, 'class') && stringified[stringified.length - 1] === '}'){
const slice = StringPrototypeSlice(stringified, 5, -1);
Expand All@@ -1250,7 +1250,7 @@ function getFunctionBase(value, constructor, tag){
if (value.name === ''){
base += ' (anonymous)'
} else{
base += `: ${value.name}`;
base += `: ${typeof value.name === 'string' ? value.name : formatValue(ctx, value.name)}`;
}
base += ']'
if (constructor !== type && constructor !== null){
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3426,3 +3426,13 @@ assert.strictEqual(
Object.defineProperty(BuiltinPrototype, 'constructor', desc);
}
}

{
function f(){}
Object.defineProperty(f, 'name',{value: Symbol('f') });

assert.strictEqual(
util.inspect(f),
'[Function: Symbol(f)]',
);
}
Loading