summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-09-27 00:35:42 +0200
committerDaniel Bevenius <daniel.bevenius@gmail.com>2018-10-02 10:34:34 +0200
commit9c3c0f42739137e7f3b52f659427233ceb735b54 (patch)
treeca4018d41e23d9cdc96690b0e24d91457e1b1691
parent250957b61e99053d805724315361d8ab352f1204 (diff)
downloadandroid-node-v8-9c3c0f42739137e7f3b52f659427233ceb735b54.tar.gz
android-node-v8-9c3c0f42739137e7f3b52f659427233ceb735b54.tar.bz2
android-node-v8-9c3c0f42739137e7f3b52f659427233ceb735b54.zip
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: https://github.com/nodejs/node/pull/23109 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--lib/internal/streams/buffer_list.js12
-rw-r--r--test/parallel/test-stream2-readable-from-list.js11
2 files changed, 20 insertions, 3 deletions
diff --git a/lib/internal/streams/buffer_list.js b/lib/internal/streams/buffer_list.js
index a72bf37a31..aa254309a0 100644
--- a/lib/internal/streams/buffer_list.js
+++ b/lib/internal/streams/buffer_list.js
@@ -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
+ });
}
};
diff --git a/test/parallel/test-stream2-readable-from-list.js b/test/parallel/test-stream2-readable-from-list.js
index f812f75e7c..00024b9120 100644
--- a/test/parallel/test-stream2-readable-from-list.js
+++ b/test/parallel/test-stream2-readable-from-list.js
@@ -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();
@@ -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');