@@ -1663,7 +1663,9 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
1663
1663
'byteOffset: undefined,\n buffer: undefined }' ] ,
1664
1664
[ new SharedArrayBuffer ( 2 ) , '[SharedArrayBuffer: null prototype] ' +
1665
1665
'{ [Uint8Contents]: <00 00>, byteLength: undefined }' ] ,
1666
- [ / f o o b a r / , '[RegExp: null prototype] /foobar/' ]
1666
+ [ / f o o b a r / , '[RegExp: null prototype] /foobar/' ] ,
1667
+ [ new Date ( 'Sun, 14 Feb 2010 11:48:40 GMT' ) ,
1668
+ '[Date: null prototype] 2010-02-14T11:48:40.000Z' ]
1667
1669
] . forEach ( ( [ value , expected ] ) => {
1668
1670
assert . strictEqual (
1669
1671
util . inspect ( Object . setPrototypeOf ( value , null ) ) ,
@@ -1707,6 +1709,50 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
1707
1709
assert ( / \[ S y m b o l \( f o o \) ] : ' y e a h ' / . test ( res ) , res ) ;
1708
1710
} ) ;
1709
1711
1712
+ // Date null prototype checks
1713
+ {
1714
+ class CustomDate extends Date {
1715
+ }
1716
+
1717
+ const date = new CustomDate ( 'Sun, 14 Feb 2010 11:48:40 GMT' ) ;
1718
+ assert . strictEqual ( util . inspect ( date ) , 'CustomDate 2010-02-14T11:48:40.000Z' ) ;
1719
+
1720
+ // add properties
1721
+ date . foo = 'bar' ;
1722
+ assert . strictEqual ( util . inspect ( date ) ,
1723
+ '{ CustomDate 2010-02-14T11:48:40.000Z foo: \'bar\' }' ) ;
1724
+
1725
+ // check for null prototype
1726
+ Object . setPrototypeOf ( date , null ) ;
1727
+ assert . strictEqual ( util . inspect ( date ) ,
1728
+ '{ [Date: null prototype] 2010-02-14T11:48:40.000Z' +
1729
+ ' foo: \'bar\' }' ) ;
1730
+
1731
+ const anotherDate = new CustomDate ( 'Sun, 14 Feb 2010 11:48:40 GMT' ) ;
1732
+ Object . setPrototypeOf ( anotherDate , null ) ;
1733
+ assert . strictEqual ( util . inspect ( anotherDate ) ,
1734
+ '[Date: null prototype] 2010-02-14T11:48:40.000Z' ) ;
1735
+ }
1736
+
1737
+ // Check for invalid dates and null prototype
1738
+ {
1739
+ class CustomDate extends Date {
1740
+ }
1741
+
1742
+ const date = new CustomDate ( 'invalid_date' ) ;
1743
+ assert . strictEqual ( util . inspect ( date ) , 'CustomDate Invalid Date' ) ;
1744
+
1745
+ // add properties
1746
+ date . foo = 'bar' ;
1747
+ assert . strictEqual ( util . inspect ( date ) ,
1748
+ '{ CustomDate Invalid Date foo: \'bar\' }' ) ;
1749
+
1750
+ // check for null prototype
1751
+ Object . setPrototypeOf ( date , null ) ;
1752
+ assert . strictEqual ( util . inspect ( date ) ,
1753
+ '{ [Date: null prototype] Invalid Date foo: \'bar\' }' ) ;
1754
+ }
1755
+
1710
1756
assert . strictEqual ( inspect ( 1n ) , '1n' ) ;
1711
1757
assert . strictEqual ( inspect ( Object ( - 1n ) ) , '[BigInt: -1n]' ) ;
1712
1758
assert . strictEqual ( inspect ( Object ( 13n ) ) , '[BigInt: 13n]' ) ;
0 commit comments