@@ -258,15 +258,15 @@ assert.strictEqual(
258258 name : { value : 'Tim' , enumerable : true } ,
259259 hidden : { value : 'secret' }
260260 } ) , { showHidden : true } ) ,
261- "{ name: 'Tim', [hidden]: 'secret' }"
261+ "[Object: null prototype] { name: 'Tim', [hidden]: 'secret' }"
262262) ;
263263
264264assert . strictEqual (
265265 util . inspect ( Object . create ( null , {
266266 name : { value : 'Tim' , enumerable : true } ,
267267 hidden : { value : 'secret' }
268268 } ) ) ,
269- "{ name: 'Tim' }"
269+ "[Object: null prototype] { name: 'Tim' }"
270270) ;
271271
272272// Dynamic properties.
@@ -502,11 +502,17 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
502502 set : function ( ) { }
503503 }
504504 } ) ;
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+ ) ;
507513 assert . strictEqual (
508514 util . inspect ( getterAndSetter , true ) ,
509- '{ [c]: [Getter/Setter] }'
515+ '[Object: null prototype] { [c]: [Getter/Setter] }'
510516 ) ;
511517}
512518
@@ -1134,7 +1140,7 @@ if (typeof Symbol !== 'undefined') {
11341140
11351141{
11361142 const x = Object . create ( null ) ;
1137- assert . strictEqual ( util . inspect ( x ) , '{}' ) ;
1143+ assert . strictEqual ( util . inspect ( x ) , '[Object: null prototype] {}' ) ;
11381144}
11391145
11401146{
@@ -1274,7 +1280,7 @@ util.inspect(process);
12741280
12751281 assert . strictEqual ( util . inspect (
12761282 Object . create ( null , { [ Symbol . toStringTag ] : { value : 'foo' } } ) ) ,
1277- '[foo] {}' ) ;
1283+ '[Object: null prototype] [ foo] {}' ) ;
12781284
12791285 assert . strictEqual ( util . inspect ( new Foo ( ) ) , "Foo [bar] { foo: 'bar' }" ) ;
12801286
@@ -1618,20 +1624,12 @@ util.inspect(process);
16181624 'prematurely. Maximum call stack size exceeded.]' ) ) ;
16191625}
16201626
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+ {
16301628 assert . strictEqual (
1631- util . inspect ( Object . setPrototypeOf ( value , null ) ) ,
1632- expected
1629+ util . inspect ( Object . setPrototypeOf ( / a / , null ) ) ,
1630+ '/undefined/undefined'
16331631 ) ;
1634- } ) ;
1632+ }
16351633
16361634// Verify that throwing in valueOf and having no prototype still produces nice
16371635// results.
@@ -1667,6 +1665,39 @@ util.inspect(process);
16671665 }
16681666 } ) ;
16691667 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 ] ) => {
16701701 assert . strictEqual (
16711702 util . inspect ( Object . setPrototypeOf ( value , null ) ) ,
16721703 expected
@@ -1748,3 +1779,30 @@ assert.strictEqual(
17481779 '[ 3, 2, 1, [Symbol(a)]: false, [Symbol(b)]: true, a: 1, b: 2, c: 3 ]'
17491780 ) ;
17501781}
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