From 496d6023e0c372c76746c35fdba800fa943cbffc Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Tue, 3 Apr 2018 18:51:30 +0200 Subject: net,stream: remove DuplexBase `DuplexBase` was added to prevent the "no-half-open enforcer" from being inherited by `net.Socket`. The main reason to use it instead of `Duplex` was that it allowed to not copy the options object but since commit 5e3f516 the options object is copyed anyway so it is no longer useful. PR-URL: https://github.com/nodejs/node/pull/19779 Reviewed-By: Anna Henningsen Reviewed-By: Daniel Bevenius Reviewed-By: James M Snell --- lib/_stream_duplex.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'lib/_stream_duplex.js') diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index 522b94d660..b123cdcb4d 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -29,15 +29,33 @@ module.exports = Duplex; const util = require('util'); -const DuplexBase = require('internal/streams/duplex_base'); - -util.inherits(Duplex, DuplexBase); +const Readable = require('_stream_readable'); +const Writable = require('_stream_writable'); + +util.inherits(Duplex, Readable); + +{ + // Allow the keys array to be GC'ed. + const keys = Object.keys(Writable.prototype); + for (var v = 0; v < keys.length; v++) { + const method = keys[v]; + if (!Duplex.prototype[method]) + Duplex.prototype[method] = Writable.prototype[method]; + } +} function Duplex(options) { if (!(this instanceof Duplex)) return new Duplex(options); - DuplexBase.call(this, options); + Readable.call(this, options); + Writable.call(this, options); + + if (options && options.readable === false) + this.readable = false; + + if (options && options.writable === false) + this.writable = false; this.allowHalfOpen = true; if (options && options.allowHalfOpen === false) { -- cgit v1.2.3