Skip to content

Commit

Permalink
stream: improve buffer list inspection
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
BridgeAR authored and targos committed Oct 3, 2018
1 parent 548934d commit 25bf1f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/internal/streams/buffer_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,14 @@ module.exports = class BufferList {
return ret;
}

[inspect.custom]() {
const obj = inspect({ length: this.length });
return `${this.constructor.name} ${obj}`;
// Make sure the linked list only shows the minimal necessary information.
[inspect.custom](_, options) {
return inspect(this, {
...options,
// Only inspect one level.
depth: 0,
// It should not recurse.
customInspect: false
});
}
};
11 changes: 11 additions & 0 deletions test/parallel/test-stream2-readable-from-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require('../common');
const assert = require('assert');
const fromList = require('_stream_readable')._fromList;
const BufferList = require('internal/streams/buffer_list');
const util = require('util');

function bufferListFromArray(arr) {
const bl = new BufferList();
Expand All @@ -41,6 +42,16 @@ function bufferListFromArray(arr) {
Buffer.from('kuel') ];
list = bufferListFromArray(list);

assert.strictEqual(
util.inspect([ list ], { compact: false }),
`[
BufferList {
head: [Object],
tail: [Object],
length: 4
}
]`);

// read more than the first element.
let ret = fromList(6, { buffer: list, length: 16 });
assert.strictEqual(ret.toString(), 'foogba');
Expand Down

0 comments on commit 25bf1f5

Please sign in to comment.