diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 8857843a3b421b..23a3f6e8cd7c1c 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -30,26 +30,26 @@ void StreamBase::AddMethods(Environment* env, enum PropertyAttribute attributes = static_cast(v8::ReadOnly | v8::DontDelete); - t->InstanceTemplate()->SetAccessor(env->fd_string(), - GetFD, - nullptr, - env->as_external(), - v8::DEFAULT, - attributes); - - t->InstanceTemplate()->SetAccessor(env->external_stream_string(), - GetExternal, - nullptr, - env->as_external(), - v8::DEFAULT, - attributes); - - t->InstanceTemplate()->SetAccessor(env->bytes_read_string(), - GetBytesRead, - nullptr, - env->as_external(), - v8::DEFAULT, - attributes); + t->PrototypeTemplate()->SetAccessor(env->fd_string(), + GetFD, + nullptr, + env->as_external(), + v8::DEFAULT, + attributes); + + t->PrototypeTemplate()->SetAccessor(env->external_stream_string(), + GetExternal, + nullptr, + env->as_external(), + v8::DEFAULT, + attributes); + + t->PrototypeTemplate()->SetAccessor(env->bytes_read_string(), + GetBytesRead, + nullptr, + env->as_external(), + v8::DEFAULT, + attributes); env->SetProtoMethod(t, "readStart", JSMethod); env->SetProtoMethod(t, "readStop", JSMethod); @@ -78,11 +78,10 @@ void StreamBase::AddMethods(Environment* env, template void StreamBase::GetFD(Local key, const PropertyCallbackInfo& args) { - Base* handle = Unwrap(args.Holder()); - // Mimic implementation of StreamBase::GetFD() and UDPWrap::GetFD(). + Base* handle; ASSIGN_OR_RETURN_UNWRAP(&handle, - args.Holder(), + args.This(), args.GetReturnValue().Set(UV_EINVAL)); StreamBase* wrap = static_cast(handle); @@ -96,11 +95,10 @@ void StreamBase::GetFD(Local key, template void StreamBase::GetBytesRead(Local key, const PropertyCallbackInfo& args) { - Base* handle = Unwrap(args.Holder()); - // The handle instance hasn't been set. So no bytes could have been read. + Base* handle; ASSIGN_OR_RETURN_UNWRAP(&handle, - args.Holder(), + args.This(), args.GetReturnValue().Set(0)); StreamBase* wrap = static_cast(handle); @@ -112,9 +110,8 @@ void StreamBase::GetBytesRead(Local key, template void StreamBase::GetExternal(Local key, const PropertyCallbackInfo& args) { - Base* handle = Unwrap(args.Holder()); - - ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder()); + Base* handle; + ASSIGN_OR_RETURN_UNWRAP(&handle, args.This()); StreamBase* wrap = static_cast(handle); Local ext = External::New(args.GetIsolate(), wrap); @@ -125,8 +122,7 @@ void StreamBase::GetExternal(Local key, template & args)> void StreamBase::JSMethod(const FunctionCallbackInfo& args) { - Base* handle = Unwrap(args.Holder()); - + Base* handle; ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder()); StreamBase* wrap = static_cast(handle); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 28970839afa0c3..7d2f8d7ebbbd5f 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -79,12 +79,12 @@ void UDPWrap::Initialize(Local target, enum PropertyAttribute attributes = static_cast(v8::ReadOnly | v8::DontDelete); - t->InstanceTemplate()->SetAccessor(env->fd_string(), - UDPWrap::GetFD, - nullptr, - env->as_external(), - v8::DEFAULT, - attributes); + t->PrototypeTemplate()->SetAccessor(env->fd_string(), + UDPWrap::GetFD, + nullptr, + env->as_external(), + v8::DEFAULT, + attributes); env->SetProtoMethod(t, "bind", Bind); env->SetProtoMethod(t, "send", Send); @@ -137,7 +137,7 @@ void UDPWrap::New(const FunctionCallbackInfo& args) { void UDPWrap::GetFD(Local, const PropertyCallbackInfo& args) { int fd = UV_EBADF; #if !defined(_WIN32) - UDPWrap* wrap = Unwrap(args.Holder()); + UDPWrap* wrap = Unwrap(args.This()); if (wrap != nullptr) uv_fileno(reinterpret_cast(&wrap->handle_), &fd); #endif