Skip to content

Commit 9398d84

Browse files
addaleaxBridgeAR
authored andcommitted
lib,src: remove usage of _externalStream
Since 4697e1b, it is no longer necessary to use `v8::External`s to pass `StreamBase` instances to native functions. PR-URL: #26510 Refs: #25142 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5ad9929 commit 9398d84

12 files changed

Lines changed: 29 additions & 37 deletions

‎lib/_http_server.js‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,11 @@ function connectionListenerInternal(server, socket) {
386386
socket.on=socketOnWrap;
387387

388388
// We only consume the socket if it has never been consumed before.
389-
if(socket._handle){
390-
varexternal=socket._handle._externalStream;
391-
if(!socket._handle._consumed&&external){
392-
parser._consumed=true;
393-
socket._handle._consumed=true;
394-
parser.consume(external);
395-
}
389+
if(socket._handle&&socket._handle.isStreamBase&&
390+
!socket._handle._consumed){
391+
parser._consumed=true;
392+
socket._handle._consumed=true;
393+
parser.consume(socket._handle);
396394
}
397395
parser[kOnExecute]=
398396
onParserExecute.bind(undefined,server,socket,parser,state);

‎lib/_tls_wrap.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,10 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
441441
constcontext=options.secureContext||
442442
options.credentials||
443443
tls.createSecureContext(options);
444-
constexternalStream=handle._externalStream;
445-
assert(typeofexternalStream==='object',
446-
'handle must be a LibuvStreamWrap');
444+
assert(handle.isStreamBase,'handle must be a StreamBase');
447445
assert(context.contextinstanceofNativeSecureContext,
448446
'context.context must be a NativeSecureContext');
449-
constres=tls_wrap.wrap(externalStream,
450-
context.context,
451-
!!options.isServer);
447+
constres=tls_wrap.wrap(handle,context.context,!!options.isServer);
452448
res._parent=handle;// C++ "wrap" object: TCPWrap, JSStream, ...
453449
res._parentWrap=wrap;// JS object: net.Socket, JSStreamSocket, ...
454450
res._secureContext=context;

‎lib/internal/http2/core.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ function setupHandle(socket, type, options) {
847847

848848
if(typeofoptions.selectPadding==='function')
849849
this[kSelectPadding]=options.selectPadding;
850-
handle.consume(socket._handle._externalStream);
850+
handle.consume(socket._handle);
851851

852852
this[kHandle]=handle;
853853

@@ -937,7 +937,7 @@ class Http2Session extends EventEmitter {
937937
constructor(type,options,socket){
938938
super();
939939

940-
if(!socket._handle||!socket._handle._externalStream){
940+
if(!socket._handle||!socket._handle.isStreamBase){
941941
socket=newJSStreamSocket(socket);
942942
}
943943

@@ -2097,8 +2097,7 @@ function startFilePipe(self, fd, offset, length) {
20972097
handle.onread=onPipedFileHandleRead;
20982098
handle.stream=self;
20992099

2100-
constpipe=newStreamPipe(handle._externalStream,
2101-
self[kHandle]._externalStream);
2100+
constpipe=newStreamPipe(handle,self[kHandle]);
21022101
pipe.onunpipe=onFileUnpipe;
21032102
pipe.start();
21042103

‎src/node_http2.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,8 +1837,8 @@ bool Http2Session::HasWritesOnSocketForStream(Http2Stream* stream) {
18371837
// (typically a net.Socket or tls.TLSSocket). The lifecycle of the two is
18381838
// tightly coupled with all data transfer between the two happening at the
18391839
// C++ layer via the StreamBase API.
1840-
voidHttp2Session::Consume(Local<External> external) {
1841-
StreamBase* stream = static_cast<StreamBase*>(external->Value());
1840+
voidHttp2Session::Consume(Local<Object> stream_obj) {
1841+
StreamBase* stream = StreamBase::FromObject(stream_obj);
18421842
stream->PushStreamListener(this);
18431843
Debug(this, "i/o stream consumed");
18441844
}
@@ -2429,8 +2429,8 @@ void Http2Session::New(const FunctionCallbackInfo<Value>& args) {
24292429
voidHttp2Session::Consume(const FunctionCallbackInfo<Value>& args) {
24302430
Http2Session* session;
24312431
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());
2432-
CHECK(args[0]->IsExternal());
2433-
session->Consume(args[0].As<External>());
2432+
CHECK(args[0]->IsObject());
2433+
session->Consume(args[0].As<Object>());
24342434
}
24352435

24362436
// Destroys the Http2Session instance and renders it unusable

‎src/node_http2.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ class Http2Session : public AsyncWrap, public StreamListener {
696696

697697
voidClose(uint32_t code = NGHTTP2_NO_ERROR,
698698
bool socket_closed = false);
699-
voidConsume(Local<External> external);
699+
voidConsume(Local<Object> stream);
700700
voidGoaway(uint32_t code, int32_t lastStreamID,
701701
constuint8_t* data, size_t len);
702702
voidAltSvc(int32_t id,

‎src/node_http_parser_impl.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,8 @@ class Parser : public AsyncWrap, public StreamListener {
556556
staticvoidConsume(const FunctionCallbackInfo<Value>& args) {
557557
Parser* parser;
558558
ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
559-
CHECK(args[0]->IsExternal());
560-
Local<External> stream_obj = args[0].As<External>();
561-
StreamBase* stream = static_cast<StreamBase*>(stream_obj->Value());
559+
CHECK(args[0]->IsObject());
560+
StreamBase* stream = StreamBase::FromObject(args[0].As<Object>());
562561
CHECK_NOT_NULL(stream);
563562
stream->PushStreamListener(parser);
564563
}

‎src/stream_base-inl.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespacenode {
1313

1414
using v8::Signature;
15-
using v8::External;
1615
using v8::FunctionCallbackInfo;
1716
using v8::FunctionTemplate;
1817
using v8::HandleScope;

‎src/stream_base.cc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace node {
1717
using v8::Array;
1818
using v8::ArrayBuffer;
1919
using v8::Context;
20+
using v8::External;
2021
using v8::FunctionCallbackInfo;
2122
using v8::HandleScope;
2223
using v8::Integer;
@@ -368,6 +369,9 @@ void StreamBase::AddMethods(Environment* env, Local<FunctionTemplate> t) {
368369
t, "writeUcs2String", JSMethod<&StreamBase::WriteString<UCS2>>);
369370
env->SetProtoMethod(
370371
t, "writeLatin1String", JSMethod<&StreamBase::WriteString<LATIN1>>);
372+
t->PrototypeTemplate()->Set(FIXED_ONE_BYTE_STRING(env->isolate(),
373+
"isStreamBase"),
374+
True(env->isolate()));
371375
}
372376

373377
voidStreamBase::GetFD(const FunctionCallbackInfo<Value>& args) {

‎src/stream_pipe.cc‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include"node_buffer.h"
44

55
using v8::Context;
6-
using v8::External;
76
using v8::Function;
87
using v8::FunctionCallbackInfo;
98
using v8::FunctionTemplate;
@@ -226,10 +225,10 @@ void StreamPipe::WritableListener::OnStreamRead(ssize_t nread,
226225

227226
voidStreamPipe::New(const FunctionCallbackInfo<Value>& args) {
228227
CHECK(args.IsConstructCall());
229-
CHECK(args[0]->IsExternal());
230-
CHECK(args[1]->IsExternal());
231-
auto source = static_cast<StreamBase*>(args[0].As<External>()->Value());
232-
auto sink = static_cast<StreamBase*>(args[1].As<External>()->Value());
228+
CHECK(args[0]->IsObject());
229+
CHECK(args[1]->IsObject());
230+
StreamBase* source = StreamBase::FromObject(args[0].As<Object>());
231+
StreamBase* sink = StreamBase::FromObject(args[1].As<Object>());
233232

234233
newStreamPipe(source, sink, args.This());
235234
}

‎src/tls_wrap.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,11 @@ void TLSWrap::Wrap(const FunctionCallbackInfo<Value>& args) {
150150
CHECK(args[1]->IsObject());
151151
CHECK(args[2]->IsBoolean());
152152

153-
Local<External> stream_obj = args[0].As<External>();
154153
Local<Object> sc = args[1].As<Object>();
155154
Kind kind = args[2]->IsTrue() ? SSLWrap<TLSWrap>::kServer :
156155
SSLWrap<TLSWrap>::kClient;
157156

158-
StreamBase* stream = static_cast<StreamBase*>(stream_obj->Value());
157+
StreamBase* stream = StreamBase::FromObject(args[0].As<Object>());
159158
CHECK_NOT_NULL(stream);
160159

161160
Local<Object> obj;

0 commit comments

Comments
 (0)