lib,src: remove usage of _externalStream

Since 4697e1b0d792f50863bbbcad25a95b84e6746501, it is no longer
necessary to use `v8::External`s to pass `StreamBase` instances
to native functions.

PR-URL: https://github.com/nodejs/node/pull/26510
Refs: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Anna Henningsen 2019-03-08 09:47:45 +01:00 committed by Daniel Bevenius
parent a445244a0c
commit 560466c773
12 changed files with 29 additions and 37 deletions

View File

@ -390,13 +390,11 @@ function connectionListenerInternal(server, socket) {
socket.on = socketOnWrap; socket.on = socketOnWrap;
// We only consume the socket if it has never been consumed before. // We only consume the socket if it has never been consumed before.
if (socket._handle) { if (socket._handle && socket._handle.isStreamBase &&
var external = socket._handle._externalStream; !socket._handle._consumed) {
if (!socket._handle._consumed && external) { parser._consumed = true;
parser._consumed = true; socket._handle._consumed = true;
socket._handle._consumed = true; parser.consume(socket._handle);
parser.consume(external);
}
} }
parser[kOnExecute] = parser[kOnExecute] =
onParserExecute.bind(undefined, server, socket, parser, state); onParserExecute.bind(undefined, server, socket, parser, state);

View File

@ -444,14 +444,10 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
const context = options.secureContext || const context = options.secureContext ||
options.credentials || options.credentials ||
tls.createSecureContext(options); tls.createSecureContext(options);
const externalStream = handle._externalStream; assert(handle.isStreamBase, 'handle must be a StreamBase');
assert(typeof externalStream === 'object',
'handle must be a LibuvStreamWrap');
assert(context.context instanceof NativeSecureContext, assert(context.context instanceof NativeSecureContext,
'context.context must be a NativeSecureContext'); 'context.context must be a NativeSecureContext');
const res = tls_wrap.wrap(externalStream, const res = tls_wrap.wrap(handle, context.context, !!options.isServer);
context.context,
!!options.isServer);
res._parent = handle; // C++ "wrap" object: TCPWrap, JSStream, ... res._parent = handle; // C++ "wrap" object: TCPWrap, JSStream, ...
res._parentWrap = wrap; // JS object: net.Socket, JSStreamSocket, ... res._parentWrap = wrap; // JS object: net.Socket, JSStreamSocket, ...
res._secureContext = context; res._secureContext = context;

View File

@ -843,7 +843,7 @@ function setupHandle(socket, type, options) {
if (typeof options.selectPadding === 'function') if (typeof options.selectPadding === 'function')
this[kSelectPadding] = options.selectPadding; this[kSelectPadding] = options.selectPadding;
handle.consume(socket._handle._externalStream); handle.consume(socket._handle);
this[kHandle] = handle; this[kHandle] = handle;
@ -933,7 +933,7 @@ class Http2Session extends EventEmitter {
constructor(type, options, socket) { constructor(type, options, socket) {
super(); super();
if (!socket._handle || !socket._handle._externalStream) { if (!socket._handle || !socket._handle.isStreamBase) {
socket = new JSStreamSocket(socket); socket = new JSStreamSocket(socket);
} }
@ -2092,8 +2092,7 @@ function startFilePipe(self, fd, offset, length) {
handle.onread = onPipedFileHandleRead; handle.onread = onPipedFileHandleRead;
handle.stream = self; handle.stream = self;
const pipe = new StreamPipe(handle._externalStream, const pipe = new StreamPipe(handle, self[kHandle]);
self[kHandle]._externalStream);
pipe.onunpipe = onFileUnpipe; pipe.onunpipe = onFileUnpipe;
pipe.start(); pipe.start();

View File

@ -1837,8 +1837,8 @@ bool Http2Session::HasWritesOnSocketForStream(Http2Stream* stream) {
// (typically a net.Socket or tls.TLSSocket). The lifecycle of the two is // (typically a net.Socket or tls.TLSSocket). The lifecycle of the two is
// tightly coupled with all data transfer between the two happening at the // tightly coupled with all data transfer between the two happening at the
// C++ layer via the StreamBase API. // C++ layer via the StreamBase API.
void Http2Session::Consume(Local<External> external) { void Http2Session::Consume(Local<Object> stream_obj) {
StreamBase* stream = static_cast<StreamBase*>(external->Value()); StreamBase* stream = StreamBase::FromObject(stream_obj);
stream->PushStreamListener(this); stream->PushStreamListener(this);
Debug(this, "i/o stream consumed"); Debug(this, "i/o stream consumed");
} }
@ -2429,8 +2429,8 @@ void Http2Session::New(const FunctionCallbackInfo<Value>& args) {
void Http2Session::Consume(const FunctionCallbackInfo<Value>& args) { void Http2Session::Consume(const FunctionCallbackInfo<Value>& args) {
Http2Session* session; Http2Session* session;
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder()); ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());
CHECK(args[0]->IsExternal()); CHECK(args[0]->IsObject());
session->Consume(args[0].As<External>()); session->Consume(args[0].As<Object>());
} }
// Destroys the Http2Session instance and renders it unusable // Destroys the Http2Session instance and renders it unusable

View File

@ -696,7 +696,7 @@ class Http2Session : public AsyncWrap, public StreamListener {
void Close(uint32_t code = NGHTTP2_NO_ERROR, void Close(uint32_t code = NGHTTP2_NO_ERROR,
bool socket_closed = false); bool socket_closed = false);
void Consume(Local<External> external); void Consume(Local<Object> stream);
void Goaway(uint32_t code, int32_t lastStreamID, void Goaway(uint32_t code, int32_t lastStreamID,
const uint8_t* data, size_t len); const uint8_t* data, size_t len);
void AltSvc(int32_t id, void AltSvc(int32_t id,

View File

@ -556,9 +556,8 @@ class Parser : public AsyncWrap, public StreamListener {
static void Consume(const FunctionCallbackInfo<Value>& args) { static void Consume(const FunctionCallbackInfo<Value>& args) {
Parser* parser; Parser* parser;
ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder()); ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
CHECK(args[0]->IsExternal()); CHECK(args[0]->IsObject());
Local<External> stream_obj = args[0].As<External>(); StreamBase* stream = StreamBase::FromObject(args[0].As<Object>());
StreamBase* stream = static_cast<StreamBase*>(stream_obj->Value());
CHECK_NOT_NULL(stream); CHECK_NOT_NULL(stream);
stream->PushStreamListener(parser); stream->PushStreamListener(parser);
} }

View File

@ -12,7 +12,6 @@
namespace node { namespace node {
using v8::Signature; using v8::Signature;
using v8::External;
using v8::FunctionCallbackInfo; using v8::FunctionCallbackInfo;
using v8::FunctionTemplate; using v8::FunctionTemplate;
using v8::HandleScope; using v8::HandleScope;

View File

@ -17,6 +17,7 @@ namespace node {
using v8::Array; using v8::Array;
using v8::ArrayBuffer; using v8::ArrayBuffer;
using v8::Context; using v8::Context;
using v8::External;
using v8::FunctionCallbackInfo; using v8::FunctionCallbackInfo;
using v8::HandleScope; using v8::HandleScope;
using v8::Integer; using v8::Integer;
@ -368,6 +369,9 @@ void StreamBase::AddMethods(Environment* env, Local<FunctionTemplate> t) {
t, "writeUcs2String", JSMethod<&StreamBase::WriteString<UCS2>>); t, "writeUcs2String", JSMethod<&StreamBase::WriteString<UCS2>>);
env->SetProtoMethod( env->SetProtoMethod(
t, "writeLatin1String", JSMethod<&StreamBase::WriteString<LATIN1>>); t, "writeLatin1String", JSMethod<&StreamBase::WriteString<LATIN1>>);
t->PrototypeTemplate()->Set(FIXED_ONE_BYTE_STRING(env->isolate(),
"isStreamBase"),
True(env->isolate()));
} }
void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) { void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) {

View File

@ -3,7 +3,6 @@
#include "node_buffer.h" #include "node_buffer.h"
using v8::Context; using v8::Context;
using v8::External;
using v8::Function; using v8::Function;
using v8::FunctionCallbackInfo; using v8::FunctionCallbackInfo;
using v8::FunctionTemplate; using v8::FunctionTemplate;
@ -226,10 +225,10 @@ void StreamPipe::WritableListener::OnStreamRead(ssize_t nread,
void StreamPipe::New(const FunctionCallbackInfo<Value>& args) { void StreamPipe::New(const FunctionCallbackInfo<Value>& args) {
CHECK(args.IsConstructCall()); CHECK(args.IsConstructCall());
CHECK(args[0]->IsExternal()); CHECK(args[0]->IsObject());
CHECK(args[1]->IsExternal()); CHECK(args[1]->IsObject());
auto source = static_cast<StreamBase*>(args[0].As<External>()->Value()); StreamBase* source = StreamBase::FromObject(args[0].As<Object>());
auto sink = static_cast<StreamBase*>(args[1].As<External>()->Value()); StreamBase* sink = StreamBase::FromObject(args[1].As<Object>());
new StreamPipe(source, sink, args.This()); new StreamPipe(source, sink, args.This());
} }

View File

@ -151,12 +151,11 @@ void TLSWrap::Wrap(const FunctionCallbackInfo<Value>& args) {
CHECK(args[1]->IsObject()); CHECK(args[1]->IsObject());
CHECK(args[2]->IsBoolean()); CHECK(args[2]->IsBoolean());
Local<External> stream_obj = args[0].As<External>();
Local<Object> sc = args[1].As<Object>(); Local<Object> sc = args[1].As<Object>();
Kind kind = args[2]->IsTrue() ? SSLWrap<TLSWrap>::kServer : Kind kind = args[2]->IsTrue() ? SSLWrap<TLSWrap>::kServer :
SSLWrap<TLSWrap>::kClient; SSLWrap<TLSWrap>::kClient;
StreamBase* stream = static_cast<StreamBase*>(stream_obj->Value()); StreamBase* stream = StreamBase::FromObject(args[0].As<Object>());
CHECK_NOT_NULL(stream); CHECK_NOT_NULL(stream);
Local<Object> obj; Local<Object> obj;

View File

@ -268,8 +268,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
// TLSWrap is exposed, but needs to be instantiated via tls_wrap.wrap(). // TLSWrap is exposed, but needs to be instantiated via tls_wrap.wrap().
const tls_wrap = internalBinding('tls_wrap'); const tls_wrap = internalBinding('tls_wrap');
testInitialized( testInitialized(tls_wrap.wrap(tcp, credentials.context, true), 'TLSWrap');
tls_wrap.wrap(tcp._externalStream, credentials.context, true), 'TLSWrap');
} }
{ {

View File

@ -40,12 +40,12 @@ function execAndClose() {
throw e; throw e;
}); });
parser.consume(socket._handle._externalStream); parser.consume(socket._handle);
parser.onIncoming = function onIncoming() { parser.onIncoming = function onIncoming() {
process.stdout.write('+'); process.stdout.write('+');
gotResponses++; gotResponses++;
parser.unconsume(socket._handle._externalStream); parser.unconsume();
httpCommon.freeParser(parser); httpCommon.freeParser(parser);
socket.destroy(); socket.destroy();
setImmediate(execAndClose); setImmediate(execAndClose);