@@ -33,26 +33,26 @@ void StreamBase::AddMethods(Environment* env,
3333
3434 enum PropertyAttribute attributes =
3535 static_cast <PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
36- t->InstanceTemplate ()->SetAccessor (env->fd_string (),
37- GetFD<Base>,
38- nullptr ,
39- env->as_external (),
40- v8::DEFAULT,
41- attributes);
42-
43- t->InstanceTemplate ()->SetAccessor (env->external_stream_string (),
44- GetExternal<Base>,
45- nullptr ,
46- env->as_external (),
47- v8::DEFAULT,
48- attributes);
49-
50- t->InstanceTemplate ()->SetAccessor (env->bytes_read_string (),
51- GetBytesRead<Base>,
52- nullptr ,
53- env->as_external (),
54- v8::DEFAULT,
55- attributes);
36+ t->PrototypeTemplate ()->SetAccessor (env->fd_string (),
37+ GetFD<Base>,
38+ nullptr ,
39+ env->as_external (),
40+ v8::DEFAULT,
41+ attributes);
42+
43+ t->PrototypeTemplate ()->SetAccessor (env->external_stream_string (),
44+ GetExternal<Base>,
45+ nullptr ,
46+ env->as_external (),
47+ v8::DEFAULT,
48+ attributes);
49+
50+ t->PrototypeTemplate ()->SetAccessor (env->bytes_read_string (),
51+ GetBytesRead<Base>,
52+ nullptr ,
53+ env->as_external (),
54+ v8::DEFAULT,
55+ attributes);
5656
5757 env->SetProtoMethod (t, " readStart" , JSMethod<Base, &StreamBase::ReadStart>);
5858 env->SetProtoMethod (t, " readStop" , JSMethod<Base, &StreamBase::ReadStop>);
@@ -81,11 +81,10 @@ void StreamBase::AddMethods(Environment* env,
8181template <class Base >
8282void StreamBase::GetFD (Local<String> key,
8383 const PropertyCallbackInfo<Value>& args) {
84- Base* handle = Unwrap<Base>(args.Holder ());
85-
8684 // Mimic implementation of StreamBase::GetFD() and UDPWrap::GetFD().
85+ Base* handle;
8786 ASSIGN_OR_RETURN_UNWRAP (&handle,
88- args.Holder (),
87+ args.This (),
8988 args.GetReturnValue ().Set (UV_EINVAL));
9089
9190 StreamBase* wrap = static_cast <StreamBase*>(handle);
@@ -99,11 +98,10 @@ void StreamBase::GetFD(Local<String> key,
9998template <class Base >
10099void StreamBase::GetBytesRead (Local<String> key,
101100 const PropertyCallbackInfo<Value>& args) {
102- Base* handle = Unwrap<Base>(args.Holder ());
103-
104101 // The handle instance hasn't been set. So no bytes could have been read.
102+ Base* handle;
105103 ASSIGN_OR_RETURN_UNWRAP (&handle,
106- args.Holder (),
104+ args.This (),
107105 args.GetReturnValue ().Set (0 ));
108106
109107 StreamBase* wrap = static_cast <StreamBase*>(handle);
@@ -115,9 +113,8 @@ void StreamBase::GetBytesRead(Local<String> key,
115113template <class Base >
116114void StreamBase::GetExternal (Local<String> key,
117115 const PropertyCallbackInfo<Value>& args) {
118- Base* handle = Unwrap<Base>(args.Holder ());
119-
120- ASSIGN_OR_RETURN_UNWRAP (&handle, args.Holder ());
116+ Base* handle;
117+ ASSIGN_OR_RETURN_UNWRAP (&handle, args.This ());
121118
122119 StreamBase* wrap = static_cast <StreamBase*>(handle);
123120 Local<External> ext = External::New (args.GetIsolate (), wrap);
@@ -128,8 +125,7 @@ void StreamBase::GetExternal(Local<String> key,
128125template <class Base ,
129126 int (StreamBase::*Method)(const FunctionCallbackInfo<Value>& args)>
130127void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) {
131- Base* handle = Unwrap<Base>(args.Holder ());
132-
128+ Base* handle;
133129 ASSIGN_OR_RETURN_UNWRAP (&handle, args.Holder ());
134130
135131 StreamBase* wrap = static_cast <StreamBase*>(handle);
0 commit comments