From fc6db1349aa75cb4b41128e62d6e423182f0b27e Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Fri, 9 Feb 2018 17:09:08 +0100 Subject: [PATCH] Proper fix, soft-detecting there is a custom inspect. --- build/files.js | 21 ++++++++++++++++++++- lib/internal/streams/BufferList.js | 13 +++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/build/files.js b/build/files.js index c66c17df42..f4c667a6da 100644 --- a/build/files.js +++ b/build/files.js @@ -319,9 +319,28 @@ module.exports['_stream_writable.js'] = [ , useCorkedRequest , addConstructors ] + module.exports['internal/streams/BufferList.js'] = [ - safeBufferFix + [ + /(?:var|const) (?:{ )Buffer(?: }) = require\('buffer'\)(?:\.Buffer)?;/, + ` +const Buffer = require('safe-buffer').Buffer +const util = require('util') + ` + ] , fixCopyBuffer + , [ + /$/, + ` + +if (util && util.inspect.custom) { + module.exports.prototype[util.inspect.custom] = function () { + const obj = util.inspect({ length: this.length }); + return \`\${this.constructor.name} \${obj}\`; + } +} +` + ] ] module.exports['internal/streams/destroy.js'] = [ diff --git a/lib/internal/streams/BufferList.js b/lib/internal/streams/BufferList.js index d467615978..f061d4c50a 100644 --- a/lib/internal/streams/BufferList.js +++ b/lib/internal/streams/BufferList.js @@ -1,11 +1,9 @@ 'use strict'; -/**/ - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Buffer = require('safe-buffer').Buffer; -/**/ +var util = require('util'); function copyBuffer(src, target, offset) { src.copy(target, offset); @@ -71,4 +69,11 @@ module.exports = function () { }; return BufferList; -}(); \ No newline at end of file +}(); + +if (util && util.inspect.custom) { + module.exports.prototype[util.inspect.custom] = function () { + var obj = util.inspect({ length: this.length }); + return this.constructor.name + ' ' + obj; + }; +} \ No newline at end of file