src: remove templating from StreamBase
PR-URL: https://github.com/nodejs/node/pull/25142 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
254635198a
commit
4697e1b0d7
@ -27,6 +27,7 @@ JSStream::JSStream(Environment* env, Local<Object> obj)
|
|||||||
: AsyncWrap(env, obj, AsyncWrap::PROVIDER_JSSTREAM),
|
: AsyncWrap(env, obj, AsyncWrap::PROVIDER_JSSTREAM),
|
||||||
StreamBase(env) {
|
StreamBase(env) {
|
||||||
MakeWeak();
|
MakeWeak();
|
||||||
|
StreamBase::AttachToObject(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -203,7 +204,8 @@ void JSStream::Initialize(Local<Object> target,
|
|||||||
Local<String> jsStreamString =
|
Local<String> jsStreamString =
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream");
|
FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream");
|
||||||
t->SetClassName(jsStreamString);
|
t->SetClassName(jsStreamString);
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(1);
|
t->InstanceTemplate()
|
||||||
|
->SetInternalFieldCount(StreamBase::kStreamBaseField + 1);
|
||||||
t->Inherit(AsyncWrap::GetConstructorTemplate(env));
|
t->Inherit(AsyncWrap::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(t, "finishWrite", Finish<WriteWrap>);
|
env->SetProtoMethod(t, "finishWrite", Finish<WriteWrap>);
|
||||||
@ -211,7 +213,7 @@ void JSStream::Initialize(Local<Object> target,
|
|||||||
env->SetProtoMethod(t, "readBuffer", ReadBuffer);
|
env->SetProtoMethod(t, "readBuffer", ReadBuffer);
|
||||||
env->SetProtoMethod(t, "emitEOF", EmitEOF);
|
env->SetProtoMethod(t, "emitEOF", EmitEOF);
|
||||||
|
|
||||||
StreamBase::AddMethods<JSStream>(env, t);
|
StreamBase::AddMethods(env, t);
|
||||||
target->Set(env->context(),
|
target->Set(env->context(),
|
||||||
jsStreamString,
|
jsStreamString,
|
||||||
t->GetFunction(context).ToLocalChecked()).FromJust();
|
t->GetFunction(context).ToLocalChecked()).FromJust();
|
||||||
|
@ -111,6 +111,7 @@ FileHandle::FileHandle(Environment* env, Local<Object> obj, int fd)
|
|||||||
StreamBase(env),
|
StreamBase(env),
|
||||||
fd_(fd) {
|
fd_(fd) {
|
||||||
MakeWeak();
|
MakeWeak();
|
||||||
|
StreamBase::AttachToObject(GetObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
FileHandle* FileHandle::New(Environment* env, int fd, Local<Object> obj) {
|
FileHandle* FileHandle::New(Environment* env, int fd, Local<Object> obj) {
|
||||||
@ -2227,11 +2228,11 @@ void Initialize(Local<Object> target,
|
|||||||
env->SetProtoMethod(fd, "close", FileHandle::Close);
|
env->SetProtoMethod(fd, "close", FileHandle::Close);
|
||||||
env->SetProtoMethod(fd, "releaseFD", FileHandle::ReleaseFD);
|
env->SetProtoMethod(fd, "releaseFD", FileHandle::ReleaseFD);
|
||||||
Local<ObjectTemplate> fdt = fd->InstanceTemplate();
|
Local<ObjectTemplate> fdt = fd->InstanceTemplate();
|
||||||
fdt->SetInternalFieldCount(1);
|
fdt->SetInternalFieldCount(StreamBase::kStreamBaseField + 1);
|
||||||
Local<String> handleString =
|
Local<String> handleString =
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "FileHandle");
|
FIXED_ONE_BYTE_STRING(isolate, "FileHandle");
|
||||||
fd->SetClassName(handleString);
|
fd->SetClassName(handleString);
|
||||||
StreamBase::AddMethods<FileHandle>(env, fd);
|
StreamBase::AddMethods(env, fd);
|
||||||
target
|
target
|
||||||
->Set(context, handleString,
|
->Set(context, handleString,
|
||||||
fd->GetFunction(env->context()).ToLocalChecked())
|
fd->GetFunction(env->context()).ToLocalChecked())
|
||||||
|
@ -1868,6 +1868,7 @@ Http2Stream::Http2Stream(Http2Session* session,
|
|||||||
id_(id),
|
id_(id),
|
||||||
current_headers_category_(category) {
|
current_headers_category_(category) {
|
||||||
MakeWeak();
|
MakeWeak();
|
||||||
|
StreamBase::AttachToObject(GetObject());
|
||||||
statistics_.start_time = uv_hrtime();
|
statistics_.start_time = uv_hrtime();
|
||||||
|
|
||||||
// Limit the number of header pairs
|
// Limit the number of header pairs
|
||||||
@ -3008,9 +3009,9 @@ void Initialize(Local<Object> target,
|
|||||||
env->SetProtoMethod(stream, "rstStream", Http2Stream::RstStream);
|
env->SetProtoMethod(stream, "rstStream", Http2Stream::RstStream);
|
||||||
env->SetProtoMethod(stream, "refreshState", Http2Stream::RefreshState);
|
env->SetProtoMethod(stream, "refreshState", Http2Stream::RefreshState);
|
||||||
stream->Inherit(AsyncWrap::GetConstructorTemplate(env));
|
stream->Inherit(AsyncWrap::GetConstructorTemplate(env));
|
||||||
StreamBase::AddMethods<Http2Stream>(env, stream);
|
StreamBase::AddMethods(env, stream);
|
||||||
Local<ObjectTemplate> streamt = stream->InstanceTemplate();
|
Local<ObjectTemplate> streamt = stream->InstanceTemplate();
|
||||||
streamt->SetInternalFieldCount(1);
|
streamt->SetInternalFieldCount(StreamBase::kStreamBaseField + 1);
|
||||||
env->set_http2stream_constructor_template(streamt);
|
env->set_http2stream_constructor_template(streamt);
|
||||||
target->Set(context,
|
target->Set(context,
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Stream"),
|
FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Stream"),
|
||||||
|
@ -74,7 +74,8 @@ void PipeWrap::Initialize(Local<Object> target,
|
|||||||
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
||||||
Local<String> pipeString = FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe");
|
Local<String> pipeString = FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe");
|
||||||
t->SetClassName(pipeString);
|
t->SetClassName(pipeString);
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(1);
|
t->InstanceTemplate()
|
||||||
|
->SetInternalFieldCount(StreamBase::kStreamBaseField + 1);
|
||||||
|
|
||||||
t->Inherit(LibuvStreamWrap::GetConstructorTemplate(env));
|
t->Inherit(LibuvStreamWrap::GetConstructorTemplate(env));
|
||||||
|
|
||||||
|
@ -273,144 +273,16 @@ inline WriteWrap* StreamBase::CreateWriteWrap(
|
|||||||
return new SimpleWriteWrap<AsyncWrap>(this, object);
|
return new SimpleWriteWrap<AsyncWrap>(this, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Base>
|
inline void StreamBase::AttachToObject(v8::Local<v8::Object> obj) {
|
||||||
void StreamBase::AddMethods(Environment* env, Local<FunctionTemplate> t) {
|
obj->SetAlignedPointerInInternalField(kStreamBaseField, this);
|
||||||
HandleScope scope(env->isolate());
|
|
||||||
|
|
||||||
enum PropertyAttribute attributes =
|
|
||||||
static_cast<PropertyAttribute>(
|
|
||||||
v8::ReadOnly | v8::DontDelete | v8::DontEnum);
|
|
||||||
|
|
||||||
Local<Signature> signature = Signature::New(env->isolate(), t);
|
|
||||||
|
|
||||||
Local<FunctionTemplate> get_fd_templ =
|
|
||||||
env->NewFunctionTemplate(GetFD<Base>,
|
|
||||||
signature,
|
|
||||||
v8::ConstructorBehavior::kThrow,
|
|
||||||
v8::SideEffectType::kHasNoSideEffect);
|
|
||||||
|
|
||||||
Local<FunctionTemplate> get_external_templ =
|
|
||||||
env->NewFunctionTemplate(GetExternal<Base>,
|
|
||||||
signature,
|
|
||||||
v8::ConstructorBehavior::kThrow,
|
|
||||||
v8::SideEffectType::kHasNoSideEffect);
|
|
||||||
|
|
||||||
Local<FunctionTemplate> get_bytes_read_templ =
|
|
||||||
env->NewFunctionTemplate(GetBytesRead<Base>,
|
|
||||||
signature,
|
|
||||||
v8::ConstructorBehavior::kThrow,
|
|
||||||
v8::SideEffectType::kHasNoSideEffect);
|
|
||||||
|
|
||||||
Local<FunctionTemplate> get_bytes_written_templ =
|
|
||||||
env->NewFunctionTemplate(GetBytesWritten<Base>,
|
|
||||||
signature,
|
|
||||||
v8::ConstructorBehavior::kThrow,
|
|
||||||
v8::SideEffectType::kHasNoSideEffect);
|
|
||||||
|
|
||||||
t->PrototypeTemplate()->SetAccessorProperty(env->fd_string(),
|
|
||||||
get_fd_templ,
|
|
||||||
Local<FunctionTemplate>(),
|
|
||||||
attributes);
|
|
||||||
|
|
||||||
t->PrototypeTemplate()->SetAccessorProperty(env->external_stream_string(),
|
|
||||||
get_external_templ,
|
|
||||||
Local<FunctionTemplate>(),
|
|
||||||
attributes);
|
|
||||||
|
|
||||||
t->PrototypeTemplate()->SetAccessorProperty(env->bytes_read_string(),
|
|
||||||
get_bytes_read_templ,
|
|
||||||
Local<FunctionTemplate>(),
|
|
||||||
attributes);
|
|
||||||
|
|
||||||
t->PrototypeTemplate()->SetAccessorProperty(env->bytes_written_string(),
|
|
||||||
get_bytes_written_templ,
|
|
||||||
Local<FunctionTemplate>(),
|
|
||||||
attributes);
|
|
||||||
|
|
||||||
env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStartJS>);
|
|
||||||
env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStopJS>);
|
|
||||||
env->SetProtoMethod(t, "shutdown", JSMethod<Base, &StreamBase::Shutdown>);
|
|
||||||
env->SetProtoMethod(t, "writev", JSMethod<Base, &StreamBase::Writev>);
|
|
||||||
env->SetProtoMethod(t,
|
|
||||||
"writeBuffer",
|
|
||||||
JSMethod<Base, &StreamBase::WriteBuffer>);
|
|
||||||
env->SetProtoMethod(t,
|
|
||||||
"writeAsciiString",
|
|
||||||
JSMethod<Base, &StreamBase::WriteString<ASCII> >);
|
|
||||||
env->SetProtoMethod(t,
|
|
||||||
"writeUtf8String",
|
|
||||||
JSMethod<Base, &StreamBase::WriteString<UTF8> >);
|
|
||||||
env->SetProtoMethod(t,
|
|
||||||
"writeUcs2String",
|
|
||||||
JSMethod<Base, &StreamBase::WriteString<UCS2> >);
|
|
||||||
env->SetProtoMethod(t,
|
|
||||||
"writeLatin1String",
|
|
||||||
JSMethod<Base, &StreamBase::WriteString<LATIN1> >);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline StreamBase* StreamBase::FromObject(v8::Local<v8::Object> obj) {
|
||||||
|
if (obj->GetAlignedPointerFromInternalField(0) == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
template <class Base>
|
return static_cast<StreamBase*>(
|
||||||
void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) {
|
obj->GetAlignedPointerFromInternalField(kStreamBaseField));
|
||||||
// Mimic implementation of StreamBase::GetFD() and UDPWrap::GetFD().
|
|
||||||
Base* handle;
|
|
||||||
ASSIGN_OR_RETURN_UNWRAP(&handle,
|
|
||||||
args.This(),
|
|
||||||
args.GetReturnValue().Set(UV_EINVAL));
|
|
||||||
|
|
||||||
StreamBase* wrap = static_cast<StreamBase*>(handle);
|
|
||||||
if (!wrap->IsAlive())
|
|
||||||
return args.GetReturnValue().Set(UV_EINVAL);
|
|
||||||
|
|
||||||
args.GetReturnValue().Set(wrap->GetFD());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Base>
|
|
||||||
void StreamBase::GetBytesRead(const FunctionCallbackInfo<Value>& args) {
|
|
||||||
Base* handle;
|
|
||||||
ASSIGN_OR_RETURN_UNWRAP(&handle,
|
|
||||||
args.This(),
|
|
||||||
args.GetReturnValue().Set(0));
|
|
||||||
|
|
||||||
StreamBase* wrap = static_cast<StreamBase*>(handle);
|
|
||||||
// uint64_t -> double. 53bits is enough for all real cases.
|
|
||||||
args.GetReturnValue().Set(static_cast<double>(wrap->bytes_read_));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Base>
|
|
||||||
void StreamBase::GetBytesWritten(const FunctionCallbackInfo<Value>& args) {
|
|
||||||
Base* handle;
|
|
||||||
ASSIGN_OR_RETURN_UNWRAP(&handle,
|
|
||||||
args.This(),
|
|
||||||
args.GetReturnValue().Set(0));
|
|
||||||
|
|
||||||
StreamBase* wrap = static_cast<StreamBase*>(handle);
|
|
||||||
// uint64_t -> double. 53bits is enough for all real cases.
|
|
||||||
args.GetReturnValue().Set(static_cast<double>(wrap->bytes_written_));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Base>
|
|
||||||
void StreamBase::GetExternal(const FunctionCallbackInfo<Value>& args) {
|
|
||||||
Base* handle;
|
|
||||||
ASSIGN_OR_RETURN_UNWRAP(&handle, args.This());
|
|
||||||
|
|
||||||
StreamBase* wrap = static_cast<StreamBase*>(handle);
|
|
||||||
Local<External> ext = External::New(args.GetIsolate(), wrap);
|
|
||||||
args.GetReturnValue().Set(ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class Base,
|
|
||||||
int (StreamBase::*Method)(const FunctionCallbackInfo<Value>& args)>
|
|
||||||
void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) {
|
|
||||||
Base* handle;
|
|
||||||
ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder());
|
|
||||||
|
|
||||||
StreamBase* wrap = static_cast<StreamBase*>(handle);
|
|
||||||
if (!wrap->IsAlive())
|
|
||||||
return args.GetReturnValue().Set(UV_EINVAL);
|
|
||||||
|
|
||||||
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(handle);
|
|
||||||
args.GetReturnValue().Set((wrap->*Method)(args));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -327,6 +327,93 @@ Local<Object> StreamBase::GetObject() {
|
|||||||
return GetAsyncWrap()->object();
|
return GetAsyncWrap()->object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StreamBase::AddMethod(Environment* env,
|
||||||
|
Local<Signature> signature,
|
||||||
|
enum PropertyAttribute attributes,
|
||||||
|
Local<FunctionTemplate> t,
|
||||||
|
JSMethodFunction* stream_method,
|
||||||
|
Local<String> string) {
|
||||||
|
Local<FunctionTemplate> templ =
|
||||||
|
env->NewFunctionTemplate(stream_method,
|
||||||
|
signature,
|
||||||
|
v8::ConstructorBehavior::kThrow,
|
||||||
|
v8::SideEffectType::kHasNoSideEffect);
|
||||||
|
t->PrototypeTemplate()->SetAccessorProperty(
|
||||||
|
string, templ, Local<FunctionTemplate>(), attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StreamBase::AddMethods(Environment* env, Local<FunctionTemplate> t) {
|
||||||
|
HandleScope scope(env->isolate());
|
||||||
|
|
||||||
|
enum PropertyAttribute attributes = static_cast<PropertyAttribute>(
|
||||||
|
v8::ReadOnly | v8::DontDelete | v8::DontEnum);
|
||||||
|
Local<Signature> sig = Signature::New(env->isolate(), t);
|
||||||
|
|
||||||
|
AddMethod(env, sig, attributes, t, GetFD, env->fd_string());
|
||||||
|
AddMethod(
|
||||||
|
env, sig, attributes, t, GetExternal, env->external_stream_string());
|
||||||
|
AddMethod(env, sig, attributes, t, GetBytesRead, env->bytes_read_string());
|
||||||
|
AddMethod(
|
||||||
|
env, sig, attributes, t, GetBytesWritten, env->bytes_written_string());
|
||||||
|
env->SetProtoMethod(t, "readStart", JSMethod<&StreamBase::ReadStartJS>);
|
||||||
|
env->SetProtoMethod(t, "readStop", JSMethod<&StreamBase::ReadStopJS>);
|
||||||
|
env->SetProtoMethod(t, "shutdown", JSMethod<&StreamBase::Shutdown>);
|
||||||
|
env->SetProtoMethod(t, "writev", JSMethod<&StreamBase::Writev>);
|
||||||
|
env->SetProtoMethod(t, "writeBuffer", JSMethod<&StreamBase::WriteBuffer>);
|
||||||
|
env->SetProtoMethod(
|
||||||
|
t, "writeAsciiString", JSMethod<&StreamBase::WriteString<ASCII>>);
|
||||||
|
env->SetProtoMethod(
|
||||||
|
t, "writeUtf8String", JSMethod<&StreamBase::WriteString<UTF8>>);
|
||||||
|
env->SetProtoMethod(
|
||||||
|
t, "writeUcs2String", JSMethod<&StreamBase::WriteString<UCS2>>);
|
||||||
|
env->SetProtoMethod(
|
||||||
|
t, "writeLatin1String", JSMethod<&StreamBase::WriteString<LATIN1>>);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) {
|
||||||
|
// Mimic implementation of StreamBase::GetFD() and UDPWrap::GetFD().
|
||||||
|
StreamBase* wrap = StreamBase::FromObject(args.This().As<Object>());
|
||||||
|
if (wrap == nullptr) return args.GetReturnValue().Set(UV_EINVAL);
|
||||||
|
|
||||||
|
if (!wrap->IsAlive()) return args.GetReturnValue().Set(UV_EINVAL);
|
||||||
|
|
||||||
|
args.GetReturnValue().Set(wrap->GetFD());
|
||||||
|
}
|
||||||
|
|
||||||
|
void StreamBase::GetBytesRead(const FunctionCallbackInfo<Value>& args) {
|
||||||
|
StreamBase* wrap = StreamBase::FromObject(args.This().As<Object>());
|
||||||
|
if (wrap == nullptr) return args.GetReturnValue().Set(0);
|
||||||
|
|
||||||
|
// uint64_t -> double. 53bits is enough for all real cases.
|
||||||
|
args.GetReturnValue().Set(static_cast<double>(wrap->bytes_read_));
|
||||||
|
}
|
||||||
|
|
||||||
|
void StreamBase::GetBytesWritten(const FunctionCallbackInfo<Value>& args) {
|
||||||
|
StreamBase* wrap = StreamBase::FromObject(args.This().As<Object>());
|
||||||
|
if (wrap == nullptr) return args.GetReturnValue().Set(0);
|
||||||
|
|
||||||
|
// uint64_t -> double. 53bits is enough for all real cases.
|
||||||
|
args.GetReturnValue().Set(static_cast<double>(wrap->bytes_written_));
|
||||||
|
}
|
||||||
|
|
||||||
|
void StreamBase::GetExternal(const FunctionCallbackInfo<Value>& args) {
|
||||||
|
StreamBase* wrap = StreamBase::FromObject(args.This().As<Object>());
|
||||||
|
if (wrap == nullptr) return;
|
||||||
|
|
||||||
|
Local<External> ext = External::New(args.GetIsolate(), wrap);
|
||||||
|
args.GetReturnValue().Set(ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <int (StreamBase::*Method)(const FunctionCallbackInfo<Value>& args)>
|
||||||
|
void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) {
|
||||||
|
StreamBase* wrap = StreamBase::FromObject(args.Holder().As<Object>());
|
||||||
|
if (wrap == nullptr) return;
|
||||||
|
|
||||||
|
if (!wrap->IsAlive()) return args.GetReturnValue().Set(UV_EINVAL);
|
||||||
|
|
||||||
|
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(wrap->GetAsyncWrap());
|
||||||
|
args.GetReturnValue().Set((wrap->*Method)(args));
|
||||||
|
}
|
||||||
|
|
||||||
int StreamResource::DoTryWrite(uv_buf_t** bufs, size_t* count) {
|
int StreamResource::DoTryWrite(uv_buf_t** bufs, size_t* count) {
|
||||||
// No TryWrite by default
|
// No TryWrite by default
|
||||||
|
@ -25,6 +25,7 @@ struct StreamWriteResult {
|
|||||||
size_t bytes;
|
size_t bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using JSMethodFunction = void(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
|
||||||
class StreamReq {
|
class StreamReq {
|
||||||
public:
|
public:
|
||||||
@ -259,9 +260,9 @@ class StreamResource {
|
|||||||
|
|
||||||
class StreamBase : public StreamResource {
|
class StreamBase : public StreamResource {
|
||||||
public:
|
public:
|
||||||
template <class Base>
|
static constexpr int kStreamBaseField = 1;
|
||||||
static inline void AddMethods(Environment* env,
|
static void AddMethods(Environment* env,
|
||||||
v8::Local<v8::FunctionTemplate> target);
|
v8::Local<v8::FunctionTemplate> target);
|
||||||
|
|
||||||
virtual bool IsAlive() = 0;
|
virtual bool IsAlive() = 0;
|
||||||
virtual bool IsClosing() = 0;
|
virtual bool IsClosing() = 0;
|
||||||
@ -305,6 +306,8 @@ class StreamBase : public StreamResource {
|
|||||||
virtual AsyncWrap* GetAsyncWrap() = 0;
|
virtual AsyncWrap* GetAsyncWrap() = 0;
|
||||||
virtual v8::Local<v8::Object> GetObject();
|
virtual v8::Local<v8::Object> GetObject();
|
||||||
|
|
||||||
|
static StreamBase* FromObject(v8::Local<v8::Object> obj);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit StreamBase(Environment* env);
|
explicit StreamBase(Environment* env);
|
||||||
|
|
||||||
@ -317,20 +320,13 @@ class StreamBase : public StreamResource {
|
|||||||
template <enum encoding enc>
|
template <enum encoding enc>
|
||||||
int WriteString(const v8::FunctionCallbackInfo<v8::Value>& args);
|
int WriteString(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
|
||||||
template <class Base>
|
|
||||||
static void GetFD(const v8::FunctionCallbackInfo<v8::Value>& args);
|
static void GetFD(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
|
||||||
template <class Base>
|
|
||||||
static void GetExternal(const v8::FunctionCallbackInfo<v8::Value>& args);
|
static void GetExternal(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
|
||||||
template <class Base>
|
|
||||||
static void GetBytesRead(const v8::FunctionCallbackInfo<v8::Value>& args);
|
static void GetBytesRead(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
|
||||||
template <class Base>
|
|
||||||
static void GetBytesWritten(const v8::FunctionCallbackInfo<v8::Value>& args);
|
static void GetBytesWritten(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
void AttachToObject(v8::Local<v8::Object> obj);
|
||||||
|
|
||||||
template <class Base,
|
template <int (StreamBase::*Method)(
|
||||||
int (StreamBase::*Method)(
|
|
||||||
const v8::FunctionCallbackInfo<v8::Value>& args)>
|
const v8::FunctionCallbackInfo<v8::Value>& args)>
|
||||||
static void JSMethod(const v8::FunctionCallbackInfo<v8::Value>& args);
|
static void JSMethod(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
|
||||||
@ -348,6 +344,12 @@ class StreamBase : public StreamResource {
|
|||||||
EmitToJSStreamListener default_listener_;
|
EmitToJSStreamListener default_listener_;
|
||||||
|
|
||||||
void SetWriteResult(const StreamWriteResult& res);
|
void SetWriteResult(const StreamWriteResult& res);
|
||||||
|
static void AddMethod(Environment* env,
|
||||||
|
v8::Local<v8::Signature> sig,
|
||||||
|
enum v8::PropertyAttribute attributes,
|
||||||
|
v8::Local<v8::FunctionTemplate> t,
|
||||||
|
JSMethodFunction* stream_method,
|
||||||
|
v8::Local<v8::String> str);
|
||||||
|
|
||||||
friend class WriteWrap;
|
friend class WriteWrap;
|
||||||
friend class ShutdownWrap;
|
friend class ShutdownWrap;
|
||||||
|
@ -123,6 +123,7 @@ LibuvStreamWrap::LibuvStreamWrap(Environment* env,
|
|||||||
provider),
|
provider),
|
||||||
StreamBase(env),
|
StreamBase(env),
|
||||||
stream_(stream) {
|
stream_(stream) {
|
||||||
|
StreamBase::AttachToObject(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -134,6 +135,8 @@ Local<FunctionTemplate> LibuvStreamWrap::GetConstructorTemplate(
|
|||||||
tmpl->SetClassName(
|
tmpl->SetClassName(
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), "LibuvStreamWrap"));
|
FIXED_ONE_BYTE_STRING(env->isolate(), "LibuvStreamWrap"));
|
||||||
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
|
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
|
||||||
|
tmpl->InstanceTemplate()->SetInternalFieldCount(
|
||||||
|
StreamBase::kStreamBaseField + 1);
|
||||||
Local<FunctionTemplate> get_write_queue_size =
|
Local<FunctionTemplate> get_write_queue_size =
|
||||||
FunctionTemplate::New(env->isolate(),
|
FunctionTemplate::New(env->isolate(),
|
||||||
GetWriteQueueSize,
|
GetWriteQueueSize,
|
||||||
@ -145,7 +148,7 @@ Local<FunctionTemplate> LibuvStreamWrap::GetConstructorTemplate(
|
|||||||
Local<FunctionTemplate>(),
|
Local<FunctionTemplate>(),
|
||||||
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
|
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
|
||||||
env->SetProtoMethod(tmpl, "setBlocking", SetBlocking);
|
env->SetProtoMethod(tmpl, "setBlocking", SetBlocking);
|
||||||
StreamBase::AddMethods<LibuvStreamWrap>(env, tmpl);
|
StreamBase::AddMethods(env, tmpl);
|
||||||
env->set_libuv_stream_wrap_ctor_template(tmpl);
|
env->set_libuv_stream_wrap_ctor_template(tmpl);
|
||||||
}
|
}
|
||||||
return tmpl;
|
return tmpl;
|
||||||
|
@ -79,7 +79,8 @@ void TCPWrap::Initialize(Local<Object> target,
|
|||||||
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
||||||
Local<String> tcpString = FIXED_ONE_BYTE_STRING(env->isolate(), "TCP");
|
Local<String> tcpString = FIXED_ONE_BYTE_STRING(env->isolate(), "TCP");
|
||||||
t->SetClassName(tcpString);
|
t->SetClassName(tcpString);
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(1);
|
t->InstanceTemplate()
|
||||||
|
->SetInternalFieldCount(StreamBase::kStreamBaseField + 1);
|
||||||
|
|
||||||
// Init properties
|
// Init properties
|
||||||
t->InstanceTemplate()->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "reading"),
|
t->InstanceTemplate()->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "reading"),
|
||||||
|
@ -58,6 +58,7 @@ TLSWrap::TLSWrap(Environment* env,
|
|||||||
StreamBase(env),
|
StreamBase(env),
|
||||||
sc_(sc) {
|
sc_(sc) {
|
||||||
MakeWeak();
|
MakeWeak();
|
||||||
|
StreamBase::AttachToObject(GetObject());
|
||||||
|
|
||||||
// sc comes from an Unwrap. Make sure it was assigned.
|
// sc comes from an Unwrap. Make sure it was assigned.
|
||||||
CHECK_NOT_NULL(sc);
|
CHECK_NOT_NULL(sc);
|
||||||
@ -958,6 +959,8 @@ void TLSWrap::Initialize(Local<Object> target,
|
|||||||
Local<String> tlsWrapString =
|
Local<String> tlsWrapString =
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap");
|
FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap");
|
||||||
t->SetClassName(tlsWrapString);
|
t->SetClassName(tlsWrapString);
|
||||||
|
t->InstanceTemplate()
|
||||||
|
->SetInternalFieldCount(StreamBase::kStreamBaseField + 1);
|
||||||
|
|
||||||
Local<FunctionTemplate> get_write_queue_size =
|
Local<FunctionTemplate> get_write_queue_size =
|
||||||
FunctionTemplate::New(env->isolate(),
|
FunctionTemplate::New(env->isolate(),
|
||||||
@ -978,7 +981,7 @@ void TLSWrap::Initialize(Local<Object> target,
|
|||||||
env->SetProtoMethod(t, "destroySSL", DestroySSL);
|
env->SetProtoMethod(t, "destroySSL", DestroySSL);
|
||||||
env->SetProtoMethod(t, "enableCertCb", EnableCertCb);
|
env->SetProtoMethod(t, "enableCertCb", EnableCertCb);
|
||||||
|
|
||||||
StreamBase::AddMethods<TLSWrap>(env, t);
|
StreamBase::AddMethods(env, t);
|
||||||
SSLWrap<TLSWrap>::AddMethods(env, t);
|
SSLWrap<TLSWrap>::AddMethods(env, t);
|
||||||
|
|
||||||
env->SetProtoMethod(t, "getServername", GetServername);
|
env->SetProtoMethod(t, "getServername", GetServername);
|
||||||
|
@ -51,7 +51,8 @@ void TTYWrap::Initialize(Local<Object> target,
|
|||||||
|
|
||||||
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
||||||
t->SetClassName(ttyString);
|
t->SetClassName(ttyString);
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(1);
|
t->InstanceTemplate()
|
||||||
|
->SetInternalFieldCount(StreamBase::kStreamBaseField + 1);
|
||||||
t->Inherit(LibuvStreamWrap::GetConstructorTemplate(env));
|
t->Inherit(LibuvStreamWrap::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethodNoSideEffect(t, "getWindowSize", TTYWrap::GetWindowSize);
|
env->SetProtoMethodNoSideEffect(t, "getWindowSize", TTYWrap::GetWindowSize);
|
||||||
|
@ -55,7 +55,7 @@ function connectClient(server) {
|
|||||||
|
|
||||||
tlsConnection.write('foo', 'utf8', common.mustCall(() => {
|
tlsConnection.write('foo', 'utf8', common.mustCall(() => {
|
||||||
assert(netSocket);
|
assert(netSocket);
|
||||||
netSocket.setTimeout(1, common.mustCall(() => {
|
netSocket.setTimeout(common.platformTimeout(10), common.mustCall(() => {
|
||||||
assert(tlsSocket);
|
assert(tlsSocket);
|
||||||
// This breaks if TLSSocket is already managing the socket:
|
// This breaks if TLSSocket is already managing the socket:
|
||||||
netSocket.destroy();
|
netSocket.destroy();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user