From 9c3c0f42739137e7f3b52f659427233ceb735b54 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 27 Sep 2018 00:35:42 +0200 Subject: 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 Reviewed-By: James M Snell --- lib/internal/streams/buffer_list.js | 12 +++++++++--- test/parallel/test-stream2-readable-from-list.js | 11 +++++++++++ 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'); -- cgit v1.2.3