@@ -1580,15 +1580,7 @@ assert.strictEqual(util.inspect('"\''), '`"\'`');
1580
1580
// eslint-disable-next-line no-template-curly-in-string
1581
1581
assert . strictEqual ( util . inspect ( '"\'${a}' ) , "'\"\\'${a}'" ) ;
1582
1582
1583
- {
1584
- assert . strictEqual (
1585
- util . inspect ( Object . setPrototypeOf ( / a / , null ) ) ,
1586
- '/undefined/undefined'
1587
- ) ;
1588
- }
1589
-
1590
- // Verify that throwing in valueOf and having no prototype still produces nice
1591
- // results.
1583
+ // Verify that throwing in valueOf and toString still produces nice results.
1592
1584
[
1593
1585
[ new String ( 55 ) , "[String: '55']" ] ,
1594
1586
[ new Boolean ( true ) , '[Boolean: true]' ] ,
@@ -1609,6 +1601,7 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
1609
1601
[ new Promise ( ( resolve ) => setTimeout ( resolve , 10 ) ) , 'Promise { <pending> }' ] ,
1610
1602
[ new WeakSet ( ) , 'WeakSet { <items unknown> }' ] ,
1611
1603
[ new WeakMap ( ) , 'WeakMap { <items unknown> }' ] ,
1604
+ [ / f o o b a r / g, '/foobar/g' ]
1612
1605
] . forEach ( ( [ value , expected ] ) => {
1613
1606
Object . defineProperty ( value , 'valueOf' , {
1614
1607
get ( ) {
@@ -1628,6 +1621,7 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
1628
1621
assert . notStrictEqual ( util . inspect ( value ) , expected ) ;
1629
1622
} ) ;
1630
1623
1624
+ // Verify that having no prototype still produces nice results.
1631
1625
[
1632
1626
[ [ 1 , 3 , 4 ] , '[Array: null prototype] [ 1, 3, 4 ]' ] ,
1633
1627
[ new Set ( [ 1 , 2 ] ) , '[Set: null prototype] { 1, 2 }' ] ,
@@ -1652,7 +1646,8 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
1652
1646
'[DataView: null prototype] {\n byteLength: undefined,\n ' +
1653
1647
'byteOffset: undefined,\n buffer: undefined }' ] ,
1654
1648
[ new SharedArrayBuffer ( 2 ) , '[SharedArrayBuffer: null prototype] ' +
1655
- '{ byteLength: undefined }' ]
1649
+ '{ byteLength: undefined }' ] ,
1650
+ [ / f o o b a r / , '[RegExp: null prototype] /foobar/' ]
1656
1651
] . forEach ( ( [ value , expected ] ) => {
1657
1652
assert . strictEqual (
1658
1653
util . inspect ( Object . setPrototypeOf ( value , null ) ) ,
@@ -1665,6 +1660,34 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
1665
1660
assert . notStrictEqual ( util . inspect ( value ) , expected ) ;
1666
1661
} ) ;
1667
1662
1663
+ // Verify that subclasses with and without prototype produce nice results.
1664
+ [
1665
+ [ RegExp , [ 'foobar' , 'g' ] , '/foobar/g' ]
1666
+ ] . forEach ( ( [ base , input , rawExpected ] ) => {
1667
+ class Foo extends base { }
1668
+ const value = new Foo ( ...input ) ;
1669
+ const symbol = value [ Symbol . toStringTag ] ;
1670
+ const expected = `Foo ${ symbol ? `[${ symbol } ] ` : '' } ${ rawExpected } ` ;
1671
+ const expectedWithoutProto = `[${ base . name } : null prototype] ${ rawExpected } ` ;
1672
+ assert . strictEqual ( util . inspect ( value ) , expected ) ;
1673
+ value . foo = 'bar' ;
1674
+ assert . notStrictEqual ( util . inspect ( value ) , expected ) ;
1675
+ delete value . foo ;
1676
+ assert . strictEqual (
1677
+ util . inspect ( Object . setPrototypeOf ( value , null ) ) ,
1678
+ expectedWithoutProto
1679
+ ) ;
1680
+ value . foo = 'bar' ;
1681
+ let res = util . inspect ( value ) ;
1682
+ assert . notStrictEqual ( res , expectedWithoutProto ) ;
1683
+ assert ( / f o o : ' b a r ' / . test ( res ) , res ) ;
1684
+ delete value . foo ;
1685
+ value [ Symbol ( 'foo' ) ] = 'yeah' ;
1686
+ res = util . inspect ( value ) ;
1687
+ assert . notStrictEqual ( res , expectedWithoutProto ) ;
1688
+ assert ( / \[ S y m b o l \( f o o \) ] : ' y e a h ' / . test ( res ) , res ) ;
1689
+ } ) ;
1690
+
1668
1691
assert . strictEqual ( inspect ( 1n ) , '1n' ) ;
1669
1692
assert . strictEqual ( inspect ( Object ( - 1n ) ) , '[BigInt: -1n]' ) ;
1670
1693
assert . strictEqual ( inspect ( Object ( 13n ) ) , '[BigInt: 13n]' ) ;
0 commit comments