From 1f1b776bef7327fc94d33cd640bc7b7cfa2799e1 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 27 Sep 2018 00:35:42 +0200 Subject: [PATCH] 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. --- 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 a72bf37a31410b..aa254309a03a5c 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 f812f75e7ca8b5..00024b91200fff 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');