@@ -1645,8 +1645,10 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
1645
1645
'[DataView: null prototype] {\n byteLength: undefined,\n ' +
1646
1646
'byteOffset: undefined,\n buffer: undefined }' ] ,
1647
1647
[ new SharedArrayBuffer ( 2 ) , '[SharedArrayBuffer: null prototype] ' +
1648
- '{ byteLength: undefined }' ] ,
1649
- [ / f o o b a r / , '[RegExp: null prototype] /foobar/' ]
1648
+ '{ byteLength: undefined }' ] ,
1649
+ [ / f o o b a r / , '[RegExp: null prototype] /foobar/' ] ,
1650
+ [ new Date ( 'Sun, 14 Feb 2010 11:48:40 GMT' ) ,
1651
+ '[Date: null prototype] 2010-02-14T11:48:40.000Z' ]
1650
1652
] . forEach ( ( [ value , expected ] ) => {
1651
1653
assert . strictEqual (
1652
1654
util . inspect ( Object . setPrototypeOf ( value , null ) ) ,
@@ -1690,6 +1692,50 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
1690
1692
assert ( / \[ S y m b o l \( f o o \) ] : ' y e a h ' / . test ( res ) , res ) ;
1691
1693
} ) ;
1692
1694
1695
+ // Date null prototype checks
1696
+ {
1697
+ class CustomDate extends Date {
1698
+ }
1699
+
1700
+ const date = new CustomDate ( 'Sun, 14 Feb 2010 11:48:40 GMT' ) ;
1701
+ assert . strictEqual ( util . inspect ( date ) , 'CustomDate 2010-02-14T11:48:40.000Z' ) ;
1702
+
1703
+ // add properties
1704
+ date . foo = 'bar' ;
1705
+ assert . strictEqual ( util . inspect ( date ) ,
1706
+ '{ CustomDate 2010-02-14T11:48:40.000Z foo: \'bar\' }' ) ;
1707
+
1708
+ // check for null prototype
1709
+ Object . setPrototypeOf ( date , null ) ;
1710
+ assert . strictEqual ( util . inspect ( date ) ,
1711
+ '{ [Date: null prototype] 2010-02-14T11:48:40.000Z' +
1712
+ ' foo: \'bar\' }' ) ;
1713
+
1714
+ const anotherDate = new CustomDate ( 'Sun, 14 Feb 2010 11:48:40 GMT' ) ;
1715
+ Object . setPrototypeOf ( anotherDate , null ) ;
1716
+ assert . strictEqual ( util . inspect ( anotherDate ) ,
1717
+ '[Date: null prototype] 2010-02-14T11:48:40.000Z' ) ;
1718
+ }
1719
+
1720
+ // Check for invalid dates and null prototype
1721
+ {
1722
+ class CustomDate extends Date {
1723
+ }
1724
+
1725
+ const date = new CustomDate ( 'invalid_date' ) ;
1726
+ assert . strictEqual ( util . inspect ( date ) , 'CustomDate Invalid Date' ) ;
1727
+
1728
+ // add properties
1729
+ date . foo = 'bar' ;
1730
+ assert . strictEqual ( util . inspect ( date ) ,
1731
+ '{ CustomDate Invalid Date foo: \'bar\' }' ) ;
1732
+
1733
+ // check for null prototype
1734
+ Object . setPrototypeOf ( date , null ) ;
1735
+ assert . strictEqual ( util . inspect ( date ) ,
1736
+ '{ [Date: null prototype] Invalid Date foo: \'bar\' }' ) ;
1737
+ }
1738
+
1693
1739
assert . strictEqual ( inspect ( 1n ) , '1n' ) ;
1694
1740
assert . strictEqual ( inspect ( Object ( - 1n ) ) , '[BigInt: -1n]' ) ;
1695
1741
assert . strictEqual ( inspect ( Object ( 13n ) ) , '[BigInt: 13n]' ) ;
0 commit comments