@@ -258,15 +258,15 @@ assert.strictEqual(
258
258
name : { value : 'Tim' , enumerable : true } ,
259
259
hidden : { value : 'secret' }
260
260
} ) , { showHidden : true } ) ,
261
- "{ name: 'Tim', [hidden]: 'secret' }"
261
+ "[Object: null prototype] { name: 'Tim', [hidden]: 'secret' }"
262
262
) ;
263
263
264
264
assert . strictEqual (
265
265
util . inspect ( Object . create ( null , {
266
266
name : { value : 'Tim' , enumerable : true } ,
267
267
hidden : { value : 'secret' }
268
268
} ) ) ,
269
- "{ name: 'Tim' }"
269
+ "[Object: null prototype] { name: 'Tim' }"
270
270
) ;
271
271
272
272
// Dynamic properties.
@@ -502,11 +502,17 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
502
502
set : function ( ) { }
503
503
}
504
504
} ) ;
505
- assert . strictEqual ( util . inspect ( getter , true ) , '{ [a]: [Getter] }' ) ;
506
- assert . strictEqual ( util . inspect ( setter , true ) , '{ [b]: [Setter] }' ) ;
505
+ assert . strictEqual (
506
+ util . inspect ( getter , true ) ,
507
+ '[Object: null prototype] { [a]: [Getter] }'
508
+ ) ;
509
+ assert . strictEqual (
510
+ util . inspect ( setter , true ) ,
511
+ '[Object: null prototype] { [b]: [Setter] }'
512
+ ) ;
507
513
assert . strictEqual (
508
514
util . inspect ( getterAndSetter , true ) ,
509
- '{ [c]: [Getter/Setter] }'
515
+ '[Object: null prototype] { [c]: [Getter/Setter] }'
510
516
) ;
511
517
}
512
518
@@ -1134,7 +1140,7 @@ if (typeof Symbol !== 'undefined') {
1134
1140
1135
1141
{
1136
1142
const x = Object . create ( null ) ;
1137
- assert . strictEqual ( util . inspect ( x ) , '{}' ) ;
1143
+ assert . strictEqual ( util . inspect ( x ) , '[Object: null prototype] {}' ) ;
1138
1144
}
1139
1145
1140
1146
{
@@ -1274,7 +1280,7 @@ util.inspect(process);
1274
1280
1275
1281
assert . strictEqual ( util . inspect (
1276
1282
Object . create ( null , { [ Symbol . toStringTag ] : { value : 'foo' } } ) ) ,
1277
- '[foo] {}' ) ;
1283
+ '[Object: null prototype] [ foo] {}' ) ;
1278
1284
1279
1285
assert . strictEqual ( util . inspect ( new Foo ( ) ) , "Foo [bar] { foo: 'bar' }" ) ;
1280
1286
@@ -1618,20 +1624,12 @@ util.inspect(process);
1618
1624
'prematurely. Maximum call stack size exceeded.]' ) ) ;
1619
1625
}
1620
1626
1621
- // Verify the output in case the value has no prototype.
1622
- // Sadly, these cases can not be fully inspected :(
1623
- [
1624
- [ / a / , '/undefined/undefined' ] ,
1625
- [ new DataView ( new ArrayBuffer ( 2 ) ) ,
1626
- 'DataView {\n byteLength: undefined,\n byteOffset: undefined,\n ' +
1627
- 'buffer: undefined }' ] ,
1628
- [ new SharedArrayBuffer ( 2 ) , 'SharedArrayBuffer { byteLength: undefined }' ]
1629
- ] . forEach ( ( [ value , expected ] ) => {
1627
+ {
1630
1628
assert . strictEqual (
1631
- util . inspect ( Object . setPrototypeOf ( value , null ) ) ,
1632
- expected
1629
+ util . inspect ( Object . setPrototypeOf ( / a / , null ) ) ,
1630
+ '/undefined/undefined'
1633
1631
) ;
1634
- } ) ;
1632
+ }
1635
1633
1636
1634
// Verify that throwing in valueOf and having no prototype still produces nice
1637
1635
// results.
@@ -1667,6 +1665,39 @@ util.inspect(process);
1667
1665
}
1668
1666
} ) ;
1669
1667
assert . strictEqual ( util . inspect ( value ) , expected ) ;
1668
+ value . foo = 'bar' ;
1669
+ assert . notStrictEqual ( util . inspect ( value ) , expected ) ;
1670
+ delete value . foo ;
1671
+ value [ Symbol ( 'foo' ) ] = 'yeah' ;
1672
+ assert . notStrictEqual ( util . inspect ( value ) , expected ) ;
1673
+ } ) ;
1674
+
1675
+ [
1676
+ [ [ 1 , 3 , 4 ] , '[Array: null prototype] [ 1, 3, 4 ]' ] ,
1677
+ [ new Set ( [ 1 , 2 ] ) , '[Set: null prototype] { 1, 2 }' ] ,
1678
+ [ new Map ( [ [ 1 , 2 ] ] ) , '[Map: null prototype] { 1 => 2 }' ] ,
1679
+ [ new Promise ( ( resolve ) => setTimeout ( resolve , 10 ) ) ,
1680
+ '[Promise: null prototype] { <pending> }' ] ,
1681
+ [ new WeakSet ( ) , '[WeakSet: null prototype] { [items unknown] }' ] ,
1682
+ [ new WeakMap ( ) , '[WeakMap: null prototype] { [items unknown] }' ] ,
1683
+ [ new Uint8Array ( 2 ) , '[Uint8Array: null prototype] [ 0, 0 ]' ] ,
1684
+ [ new Uint16Array ( 2 ) , '[Uint16Array: null prototype] [ 0, 0 ]' ] ,
1685
+ [ new Uint32Array ( 2 ) , '[Uint32Array: null prototype] [ 0, 0 ]' ] ,
1686
+ [ new Int8Array ( 2 ) , '[Int8Array: null prototype] [ 0, 0 ]' ] ,
1687
+ [ new Int16Array ( 2 ) , '[Int16Array: null prototype] [ 0, 0 ]' ] ,
1688
+ [ new Int32Array ( 2 ) , '[Int32Array: null prototype] [ 0, 0 ]' ] ,
1689
+ [ new Float32Array ( 2 ) , '[Float32Array: null prototype] [ 0, 0 ]' ] ,
1690
+ [ new Float64Array ( 2 ) , '[Float64Array: null prototype] [ 0, 0 ]' ] ,
1691
+ [ new BigInt64Array ( 2 ) , '[BigInt64Array: null prototype] [ 0, 0 ]' ] ,
1692
+ [ new BigUint64Array ( 2 ) , '[BigUint64Array: null prototype] [ 0, 0 ]' ] ,
1693
+ [ new ArrayBuffer ( 16 ) , '[ArrayBuffer: null prototype] ' +
1694
+ '{ byteLength: undefined }' ] ,
1695
+ [ new DataView ( new ArrayBuffer ( 16 ) ) ,
1696
+ '[DataView: null prototype] {\n byteLength: undefined,\n ' +
1697
+ 'byteOffset: undefined,\n buffer: undefined }' ] ,
1698
+ [ new SharedArrayBuffer ( 2 ) , '[SharedArrayBuffer: null prototype] ' +
1699
+ '{ byteLength: undefined }' ]
1700
+ ] . forEach ( ( [ value , expected ] ) => {
1670
1701
assert . strictEqual (
1671
1702
util . inspect ( Object . setPrototypeOf ( value , null ) ) ,
1672
1703
expected
@@ -1748,3 +1779,30 @@ assert.strictEqual(
1748
1779
'[ 3, 2, 1, [Symbol(a)]: false, [Symbol(b)]: true, a: 1, b: 2, c: 3 ]'
1749
1780
) ;
1750
1781
}
1782
+
1783
+ // Manipulate the prototype to one that we can not handle.
1784
+ {
1785
+ let obj = { a : true } ;
1786
+ let value = ( function ( ) { return function ( ) { } ; } ) ( ) ;
1787
+ Object . setPrototypeOf ( value , null ) ;
1788
+ Object . setPrototypeOf ( obj , value ) ;
1789
+ assert . strictEqual ( util . inspect ( obj ) , '{ a: true }' ) ;
1790
+
1791
+ obj = { a : true } ;
1792
+ value = [ ] ;
1793
+ Object . setPrototypeOf ( value , null ) ;
1794
+ Object . setPrototypeOf ( obj , value ) ;
1795
+ assert . strictEqual ( util . inspect ( obj ) , '{ a: true }' ) ;
1796
+ }
1797
+
1798
+ // Check that the fallback always works.
1799
+ {
1800
+ const obj = new Set ( [ 1 , 2 ] ) ;
1801
+ const iterator = obj [ Symbol . iterator ] ;
1802
+ Object . setPrototypeOf ( obj , null ) ;
1803
+ Object . defineProperty ( obj , Symbol . iterator , {
1804
+ value : iterator ,
1805
+ configurable : true
1806
+ } ) ;
1807
+ assert . strictEqual ( util . inspect ( obj ) , '[Set: null prototype] { 1, 2 }' ) ;
1808
+ }
0 commit comments