@@ -33,11 +33,51 @@ assert.strictEqual(util.inspect(1), '1');
33
33
assert . strictEqual ( util . inspect ( false ) , 'false' ) ;
34
34
assert . strictEqual ( util . inspect ( '' ) , "''" ) ;
35
35
assert . strictEqual ( util . inspect ( 'hello' ) , "'hello'" ) ;
36
- assert . strictEqual ( util . inspect ( function ( ) { } ) , '[Function]' ) ;
37
- assert . strictEqual ( util . inspect ( ( ) => { } ) , '[Function]' ) ;
38
- assert . strictEqual ( util . inspect ( async function ( ) { } ) , '[AsyncFunction]' ) ;
39
- assert . strictEqual ( util . inspect ( async ( ) => { } ) , '[AsyncFunction]' ) ;
40
- assert . strictEqual ( util . inspect ( function * ( ) { } ) , '[GeneratorFunction]' ) ;
36
+ assert . strictEqual ( util . inspect ( function abc ( ) { } ) , '[Function: abc]' ) ;
37
+ assert . strictEqual ( util . inspect ( ( ) => { } ) , '[Function (anonymous)]' ) ;
38
+ assert . strictEqual (
39
+ util . inspect ( async function ( ) { } ) ,
40
+ '[AsyncFunction (anonymous)]'
41
+ ) ;
42
+ assert . strictEqual ( util . inspect ( async ( ) => { } ) , '[AsyncFunction (anonymous)]' ) ;
43
+
44
+ // Special function inspection.
45
+ {
46
+ const fn = ( ( ) => function * ( ) { } ) ( ) ;
47
+ assert . strictEqual (
48
+ util . inspect ( fn ) ,
49
+ '[GeneratorFunction (anonymous)]'
50
+ ) ;
51
+ Object . setPrototypeOf ( fn , Object . getPrototypeOf ( async ( ) => { } ) ) ;
52
+ assert . strictEqual (
53
+ util . inspect ( fn ) ,
54
+ '[GeneratorFunction (anonymous)] AsyncFunction'
55
+ ) ;
56
+ Object . defineProperty ( fn , 'name' , { value : 5 , configurable : true } ) ;
57
+ assert . strictEqual (
58
+ util . inspect ( fn ) ,
59
+ '[GeneratorFunction: 5] AsyncFunction'
60
+ ) ;
61
+ Object . defineProperty ( fn , Symbol . toStringTag , {
62
+ value : 'Foobar' ,
63
+ configurable : true
64
+ } ) ;
65
+ assert . strictEqual (
66
+ util . inspect ( { [ '5' ] : fn } ) ,
67
+ "{ '5': [GeneratorFunction: 5] AsyncFunction [Foobar] }"
68
+ ) ;
69
+ Object . defineProperty ( fn , 'name' , { value : '5' , configurable : true } ) ;
70
+ Object . setPrototypeOf ( fn , null ) ;
71
+ assert . strictEqual (
72
+ util . inspect ( fn ) ,
73
+ '[GeneratorFunction (null prototype): 5] [Foobar]'
74
+ ) ;
75
+ assert . strictEqual (
76
+ util . inspect ( { [ '5' ] : fn } ) ,
77
+ "{ '5': [GeneratorFunction (null prototype): 5] [Foobar] }"
78
+ ) ;
79
+ }
80
+
41
81
assert . strictEqual ( util . inspect ( undefined ) , 'undefined' ) ;
42
82
assert . strictEqual ( util . inspect ( null ) , 'null' ) ;
43
83
assert . strictEqual ( util . inspect ( / f o o ( b a r \n ) ? / gi) , '/foo(bar\\n)?/gi' ) ;
@@ -59,8 +99,9 @@ assert.strictEqual(util.inspect({}), '{}');
59
99
assert . strictEqual ( util . inspect ( { a : 1 } ) , '{ a: 1 }' ) ;
60
100
assert . strictEqual ( util . inspect ( { a : function ( ) { } } ) , '{ a: [Function: a] }' ) ;
61
101
assert . strictEqual ( util . inspect ( { a : ( ) => { } } ) , '{ a: [Function: a] }' ) ;
62
- assert . strictEqual ( util . inspect ( { a : async function ( ) { } } ) ,
63
- '{ a: [AsyncFunction: a] }' ) ;
102
+ // eslint-disable-next-line func-name-matching
103
+ assert . strictEqual ( util . inspect ( { a : async function abc ( ) { } } ) ,
104
+ '{ a: [AsyncFunction: abc] }' ) ;
64
105
assert . strictEqual ( util . inspect ( { a : async ( ) => { } } ) ,
65
106
'{ a: [AsyncFunction: a] }' ) ;
66
107
assert . strictEqual ( util . inspect ( { a : function * ( ) { } } ) ,
@@ -411,7 +452,10 @@ assert.strictEqual(
411
452
{
412
453
const value = ( ( ) => function ( ) { } ) ( ) ;
413
454
value . aprop = 42 ;
414
- assert . strictEqual ( util . inspect ( value ) , '[Function] { aprop: 42 }' ) ;
455
+ assert . strictEqual (
456
+ util . inspect ( value ) ,
457
+ '[Function (anonymous)] { aprop: 42 }'
458
+ ) ;
415
459
}
416
460
417
461
// Regular expressions with properties.
@@ -1441,7 +1485,7 @@ util.inspect(process);
1441
1485
out = util . inspect ( o , { compact : false , breakLength : 3 } ) ;
1442
1486
expect = [
1443
1487
'{' ,
1444
- ' a: [Function],' ,
1488
+ ' a: [Function (anonymous) ],' ,
1445
1489
' b: [Number: 3]' ,
1446
1490
'}'
1447
1491
] . join ( '\n' ) ;
@@ -1450,7 +1494,7 @@ util.inspect(process);
1450
1494
out = util . inspect ( o , { compact : false , breakLength : 3 , showHidden : true } ) ;
1451
1495
expect = [
1452
1496
'{' ,
1453
- ' a: [Function] {' ,
1497
+ ' a: [Function (anonymous) ] {' ,
1454
1498
' [length]: 0,' ,
1455
1499
" [name]: ''" ,
1456
1500
' },' ,
@@ -1767,8 +1811,8 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
1767
1811
[ new Number ( 55 ) , '[Number: 55]' ] ,
1768
1812
[ Object ( BigInt ( 55 ) ) , '[BigInt: 55n]' ] ,
1769
1813
[ Object ( Symbol ( 'foo' ) ) , '[Symbol: Symbol(foo)]' ] ,
1770
- [ function ( ) { } , '[Function]' ] ,
1771
- [ ( ) => { } , '[Function]' ] ,
1814
+ [ function ( ) { } , '[Function (anonymous) ]' ] ,
1815
+ [ ( ) => { } , '[Function (anonymous) ]' ] ,
1772
1816
[ [ 1 , 2 ] , '[ 1, 2 ]' ] ,
1773
1817
[ [ , , 5 , , , , ] , '[ <2 empty items>, 5, <3 empty items> ]' ] ,
1774
1818
[ { a : 5 } , '{ a: 5 }' ] ,
@@ -1957,10 +2001,14 @@ assert.strictEqual(
1957
2001
let value = ( function ( ) { return function ( ) { } ; } ) ( ) ;
1958
2002
Object . setPrototypeOf ( value , null ) ;
1959
2003
Object . setPrototypeOf ( obj , value ) ;
1960
- assert . strictEqual ( util . inspect ( obj ) , '<[Function]> { a: true }' ) ;
2004
+ assert . strictEqual (
2005
+ util . inspect ( obj ) ,
2006
+ '<[Function (null prototype) (anonymous)]> { a: true }'
2007
+ ) ;
1961
2008
assert . strictEqual (
1962
2009
util . inspect ( obj , { colors : true } ) ,
1963
- '<\u001b[36m[Function]\u001b[39m> { a: \u001b[33mtrue\u001b[39m }'
2010
+ '<\u001b[36m[Function (null prototype) (anonymous)]\u001b[39m> ' +
2011
+ '{ a: \u001b[33mtrue\u001b[39m }'
1964
2012
) ;
1965
2013
1966
2014
obj = { a : true } ;
0 commit comments