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

+9-3
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,14 @@ module.exports = class BufferList {
158158
return ret;
159159
}
160160

161-
[inspect.custom]() {
162-
const obj = 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+
return inspect(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

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require('../common');
2525
const assert = require('assert');
2626
const fromList = require('_stream_readable')._fromList;
2727
const BufferList = require('internal/streams/buffer_list');
28+
const util = require('util');
2829

2930
function bufferListFromArray(arr) {
3031
const bl = new BufferList();
@@ -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
let ret = fromList(6, { buffer: list, length: 16 });
4657
assert.strictEqual(ret.toString(), 'foogba');

0 commit comments

Comments
 (0)