@@ -38,6 +38,13 @@ const {
3838 kStringMaxLength
3939} = internalBinding ( 'buffer' ) ;
4040const { isAnyArrayBuffer } = internalBinding ( 'types' ) ;
41+ const {
42+ getOwnNonIndexProperties,
43+ propertyFilter : {
44+ ALL_PROPERTIES ,
45+ ONLY_ENUMERABLE
46+ }
47+ } = internalBinding ( 'util' ) ;
4148const {
4249 customInspectSymbol,
4350 isInsideNodeModules,
@@ -48,6 +55,10 @@ const {
4855 isArrayBufferView,
4956 isUint8Array
5057} = require ( 'internal/util/types' ) ;
58+ const {
59+ formatProperty,
60+ kObjectType
61+ } = require ( 'internal/util/inspect' ) ;
5162
5263const {
5364 ERR_BUFFER_OUT_OF_BOUNDS ,
@@ -671,10 +682,20 @@ Buffer.prototype.equals = function equals(otherBuffer) {
671682Buffer . prototype [ customInspectSymbol ] = function inspect ( recurseTimes , ctx ) {
672683 const max = exports . INSPECT_MAX_BYTES ;
673684 const actualMax = Math . min ( max , this . length ) ;
674- let str = this . hexSlice ( 0 , actualMax ) . replace ( / ( .{ 2 } ) / g, '$1 ' ) . trim ( ) ;
675685 const remaining = this . length - max ;
686+ let str = this . hexSlice ( 0 , actualMax ) . replace ( / ( .{ 2 } ) / g, '$1 ' ) . trim ( ) ;
676687 if ( remaining > 0 )
677688 str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
689+ // Inspect special properties as well, if possible.
690+ if ( ctx ) {
691+ const filter = ctx . showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE ;
692+ str += getOwnNonIndexProperties ( this , filter ) . reduce ( ( str , key ) => {
693+ // Using `formatProperty()` expects an indentationLvl to be set.
694+ ctx . indentationLvl = 0 ;
695+ str += `, ${ formatProperty ( ctx , this , recurseTimes , key , kObjectType ) } ` ;
696+ return str ;
697+ } , '' ) ;
698+ }
678699 return `<${ this . constructor . name } ${ str } >` ;
679700} ;
680701Buffer . prototype . inspect = Buffer . prototype [ customInspectSymbol ] ;
0 commit comments