Skip to content

Commit bc66356

Browse files
sam-githubtargos
authored andcommitted
src: use consistent names for JSStream
Its confusing to call a js class with a handle a "Wrap", usually it's the C++ handle that is called a Wrap (tcp_wrap, tls_wrap, ...). Its derived from Socket, and makes a JS stream look like a Socket, so call it that. Also, remove use of lib/_stream_wrap.js so it can be deprecated some time. PR-URL: #25153 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
1 parent f6b2ea8 commit bc66356

12 files changed

Lines changed: 28 additions & 22 deletions

‎lib/_stream_wrap.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
'use strict';
22

3-
module.exports=require('internal/wrap_js_stream');
3+
module.exports=require('internal/js_stream_socket');

‎lib/_tls_wrap.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const net = require('net');
2929
consttls=require('tls');
3030
constutil=require('util');
3131
constcommon=require('_tls_common');
32-
const{ StreamWrap }=require('_stream_wrap');
32+
constJSStreamSocket=require('internal/js_stream_socket');
3333
const{ Buffer }=require('buffer');
3434
constdebug=util.debuglog('tls');
3535
const{TCP,constants: TCPConstants}=internalBinding('tcp_wrap');
@@ -308,12 +308,14 @@ function TLSSocket(socket, opts) {
308308
this.authorizationError=null;
309309
this[kRes]=null;
310310

311-
// Wrap plain JS Stream into StreamWrap
312311
varwrap;
313312
if((socketinstanceofnet.Socket&&socket._handle)||!socket){
314313
wrap=socket;
315314
}else{
316-
wrap=newStreamWrap(socket);
315+
// TLS expects to interact from C++ with a net.Socket that has a C++ stream
316+
// handle, but a JS stream doesn't have one. Wrap it up to make it look like
317+
// a socket.
318+
wrap=newJSStreamSocket(socket);
317319
wrap.once('close',()=>this.destroy());
318320
}
319321

‎lib/internal/http2/core.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const util = require('util');
2222

2323
const{ kIncomingMessage }=require('_http_common');
2424
const{ kServerResponse }=require('_http_server');
25-
const{ StreamWrap }=require('_stream_wrap');
25+
constJSStreamSocket=require('internal/js_stream_socket');
2626

2727
const{
2828
defaultTriggerAsyncIdScope,
@@ -935,7 +935,7 @@ class Http2Session extends EventEmitter {
935935
super();
936936

937937
if(!socket._handle||!socket._handle._externalStream){
938-
socket=newStreamWrap(socket);
938+
socket=newJSStreamSocket(socket);
939939
}
940940

941941
// No validation is performed on the input parameters because this
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const util = require('util');
55
const{ Socket }=require('net');
66
const{ JSStream }=internalBinding('js_stream');
77
constuv=internalBinding('uv');
8-
constdebug=util.debuglog('stream_wrap');
8+
constdebug=util.debuglog('stream_socket');
99
const{ owner_symbol }=require('internal/async_hooks').symbols;
1010
const{ERR_STREAM_WRAP}=require('internal/errors').codes;
1111

@@ -29,17 +29,17 @@ function onwrite(req, bufs) { return this[owner_symbol].doWrite(req, bufs); }
2929
* can skip going through the JS layer and let TLS access the raw C++ handle
3030
* of a net.Socket. The flipside of this is that, to maintain composability,
3131
* we need a way to create "fake" net.Socket instances that call back into a
32-
* "real" JavaScript stream. JSStreamWrap is exactly this.
32+
* "real" JavaScript stream. JSStreamSocket is exactly this.
3333
*/
34-
classJSStreamWrapextendsSocket{
34+
classJSStreamSocketextendsSocket{
3535
constructor(stream){
3636
consthandle=newJSStream();
3737
handle.close=(cb)=>{
3838
debug('close');
3939
this.doClose(cb);
4040
};
4141
// Inside of the following functions, `this` refers to the handle
42-
// and `this[owner_symbol]` refers to this JSStreamWrap instance.
42+
// and `this[owner_symbol]` refers to this JSStreamSocket instance.
4343
handle.isClosing=isClosing;
4444
handle.onreadstart=onreadstart;
4545
handle.onreadstop=onreadstop;
@@ -88,9 +88,10 @@ class JSStreamWrap extends Socket {
8888
this.read(0);
8989
}
9090

91-
// Legacy
91+
// Allow legacy requires in the test suite to keep working:
92+
// const { StreamWrap } = require('internal/js_stream_socket')
9293
staticgetStreamWrap(){
93-
returnJSStreamWrap;
94+
returnJSStreamSocket;
9495
}
9596

9697
isClosing(){
@@ -223,4 +224,4 @@ class JSStreamWrap extends Socket {
223224
}
224225
}
225226

226-
module.exports=JSStreamWrap;
227+
module.exports=JSStreamSocket;

‎node.gyp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
'lib/internal/fs/watchers.js',
125125
'lib/internal/http.js',
126126
'lib/internal/inspector_async_hook.js',
127+
'lib/internal/js_stream_socket.js',
127128
'lib/internal/linkedlist.js',
128129
'lib/internal/modules/cjs/helpers.js',
129130
'lib/internal/modules/cjs/loader.js',
@@ -186,7 +187,6 @@
186187
'lib/internal/streams/state.js',
187188
'lib/internal/streams/pipeline.js',
188189
'lib/internal/streams/end-of-stream.js',
189-
'lib/internal/wrap_js_stream.js',
190190
'deps/v8/tools/splaytree.js',
191191
'deps/v8/tools/codemap.js',
192192
'deps/v8/tools/consarray.js',

‎test/parallel/test-stream-wrap-drain.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
'use strict';
33
constcommon=require('../common');
44
constassert=require('assert');
5-
const{ StreamWrap }=require('_stream_wrap');
5+
const{ StreamWrap }=require('internal/js_stream_socket');
66
const{ Duplex }=require('stream');
77
const{ internalBinding }=require('internal/test/binding');
88
const{ ShutdownWrap }=internalBinding('stream_wrap');
99

10-
// This test makes sure that when an instance of JSStreamWrap is waiting for
10+
// This test makes sure that when a wrapped stream is waiting for
1111
// a "drain" event to `doShutdown`, the instance will work correctly when a
1212
// "drain" event emitted.
1313
{

‎test/parallel/test-stream-wrap-encoding.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// Flags: --expose-internals
12
'use strict';
23
constcommon=require('../common');
34

4-
constStreamWrap=require('_stream_wrap');
5+
constStreamWrap=require('internal/js_stream_socket');
56
constDuplex=require('stream').Duplex;
67

78
{

‎test/parallel/test-stream-wrap.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const common = require('../common');
44
constassert=require('assert');
55

66
const{ internalBinding }=require('internal/test/binding');
7-
constStreamWrap=require('_stream_wrap');
7+
constStreamWrap=require('internal/js_stream_socket');
88
const{ Duplex }=require('stream');
99
const{ ShutdownWrap }=internalBinding('stream_wrap');
1010

‎test/parallel/test-wrap-js-stream-destroy.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// Flags: --expose-internals
12
'use strict';
23

34
constcommon=require('../common');
4-
constStreamWrap=require('_stream_wrap');
5+
constStreamWrap=require('internal/js_stream_socket');
56
constnet=require('net');
67

78
// This test ensures that when we directly call `socket.destroy()` without

‎test/parallel/test-wrap-js-stream-duplex.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// Flags: --expose-internals
12
'use strict';
23
constcommon=require('../common');
34
constassert=require('assert');
4-
constStreamWrap=require('_stream_wrap');
5+
constStreamWrap=require('internal/js_stream_socket');
56
const{ PassThrough }=require('stream');
67
const{ Socket }=require('net');
78

0 commit comments

Comments
 (0)