diff --git a/lib/internal/wrap_js_stream.js b/lib/internal/wrap_js_stream.js index 146119f4cf6390..f7d2a376cc5e8b 100644 --- a/lib/internal/wrap_js_stream.js +++ b/lib/internal/wrap_js_stream.js @@ -11,6 +11,12 @@ const errors = require('internal/errors'); const kCurrentWriteRequest = Symbol('kCurrentWriteRequest'); const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest'); +function isClosing() { return this.owner.isClosing(); } +function onreadstart() { return this.owner.readStart(); } +function onreadstop() { return this.owner.readStop(); } +function onshutdown(req) { return this.owner.doShutdown(req); } +function onwrite(req, bufs) { return this.owner.doWrite(req, bufs); } + /* This class serves as a wrapper for when the C++ side of Node wants access * to a standard JS stream. For example, TLS or HTTP do not operate on network * resources conceptually, although that is the common case and what we are @@ -32,13 +38,11 @@ class JSStreamWrap extends Socket { }; // Inside of the following functions, `this` refers to the handle // and `this.owner` refers to this JSStreamWrap instance. - handle.isClosing = function() { return this.owner.isClosing(); }; - handle.onreadstart = function() { return this.owner.readStart(); }; - handle.onreadstop = function() { return this.owner.readStop(); }; - handle.onshutdown = function(req) { return this.owner.doShutdown(req); }; - handle.onwrite = function(req, bufs) { - return this.owner.doWrite(req, bufs); - }; + handle.isClosing = isClosing; + handle.onreadstart = onreadstart; + handle.onreadstop = onreadstop; + handle.onshutdown = onshutdown; + handle.onwrite = onwrite; stream.pause(); stream.on('error', (err) => this.emit('error', err));