Skip to content

Commit 25bf1f5

Browse files
BridgeARtargos
authored andcommitted
stream: improve buffer list inspection
This makes sure the indentation level is correct, no matter if the inspected buffer list is inspected on a deeper level and custom inspect options are now passed through to the actual inspection. PR-URL: #23109 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 548934d commit 25bf1f5

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

‎lib/internal/streams/buffer_list.js‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,14 @@ module.exports = class BufferList{
158158
returnret;
159159
}
160160

161-
[inspect.custom](){
162-
constobj=inspect({length: this.length});
163-
return`${this.constructor.name}${obj}`;
161+
// Make sure the linked list only shows the minimal necessary information.
162+
[inspect.custom](_,options){
163+
returninspect(this,{
164+
...options,
165+
// Only inspect one level.
166+
depth: 0,
167+
// It should not recurse.
168+
customInspect: false
169+
});
164170
}
165171
};

‎test/parallel/test-stream2-readable-from-list.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require('../common');
2525
constassert=require('assert');
2626
constfromList=require('_stream_readable')._fromList;
2727
constBufferList=require('internal/streams/buffer_list');
28+
constutil=require('util');
2829

2930
functionbufferListFromArray(arr){
3031
constbl=newBufferList();
@@ -41,6 +42,16 @@ function bufferListFromArray(arr){
4142
Buffer.from('kuel')];
4243
list=bufferListFromArray(list);
4344

45+
assert.strictEqual(
46+
util.inspect([list],{compact: false}),
47+
`[
48+
BufferList{
49+
head: [Object],
50+
tail: [Object],
51+
length: 4
52+
}
53+
]`);
54+
4455
// read more than the first element.
4556
letret=fromList(6,{buffer: list,length: 16});
4657
assert.strictEqual(ret.toString(),'foogba');

0 commit comments

Comments
(0)