Skip to content

Commit

Permalink
Proper fix, soft-detecting there is a custom inspect.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Feb 9, 2018
1 parent 6ec7d8a commit fc6db13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
21 changes: 20 additions & 1 deletion build/files.js
Expand Up @@ -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'] = [
Expand Down
13 changes: 9 additions & 4 deletions lib/internal/streams/BufferList.js
@@ -1,11 +1,9 @@
'use strict';

/*<replacement>*/

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Buffer = require('safe-buffer').Buffer;
/*</replacement>*/
var util = require('util');

function copyBuffer(src, target, offset) {
src.copy(target, offset);
Expand Down Expand Up @@ -71,4 +69,11 @@ module.exports = function () {
};

return BufferList;
}();
}();

if (util && util.inspect.custom) {
module.exports.prototype[util.inspect.custom] = function () {
var obj = util.inspect({ length: this.length });
return this.constructor.name + ' ' + obj;
};
}

0 comments on commit fc6db13

Please sign in to comment.