@@ -30,26 +30,26 @@ void StreamBase::AddMethods(Environment* env,
3030
3131  enum  PropertyAttribute attributes =
3232      static_cast <PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
33-   t->InstanceTemplate ()->SetAccessor (env->fd_string (),
34-                                      GetFD<Base>,
35-                                      nullptr ,
36-                                      env->as_external (),
37-                                      v8::DEFAULT,
38-                                      attributes);
39- 
40-   t->InstanceTemplate ()->SetAccessor (env->external_stream_string (),
41-                                      GetExternal<Base>,
42-                                      nullptr ,
43-                                      env->as_external (),
44-                                      v8::DEFAULT,
45-                                      attributes);
46- 
47-   t->InstanceTemplate ()->SetAccessor (env->bytes_read_string (),
48-                                      GetBytesRead<Base>,
49-                                      nullptr ,
50-                                      env->as_external (),
51-                                      v8::DEFAULT,
52-                                      attributes);
33+   t->PrototypeTemplate ()->SetAccessor (env->fd_string (),
34+                                        GetFD<Base>,
35+                                        nullptr ,
36+                                        env->as_external (),
37+                                        v8::DEFAULT,
38+                                        attributes);
39+ 
40+   t->PrototypeTemplate ()->SetAccessor (env->external_stream_string (),
41+                                        GetExternal<Base>,
42+                                        nullptr ,
43+                                        env->as_external (),
44+                                        v8::DEFAULT,
45+                                        attributes);
46+ 
47+   t->PrototypeTemplate ()->SetAccessor (env->bytes_read_string (),
48+                                        GetBytesRead<Base>,
49+                                        nullptr ,
50+                                        env->as_external (),
51+                                        v8::DEFAULT,
52+                                        attributes);
5353
5454  env->SetProtoMethod (t, " readStart"  , JSMethod<Base, &StreamBase::ReadStart>);
5555  env->SetProtoMethod (t, " readStop"  , JSMethod<Base, &StreamBase::ReadStop>);
@@ -78,11 +78,10 @@ void StreamBase::AddMethods(Environment* env,
7878template  <class  Base >
7979void  StreamBase::GetFD (Local<String> key,
8080                       const  PropertyCallbackInfo<Value>& args) {
81-   Base* handle = Unwrap<Base>(args.Holder ());
82- 
8381  //  Mimic implementation of StreamBase::GetFD() and UDPWrap::GetFD().
82+   Base* handle;
8483  ASSIGN_OR_RETURN_UNWRAP (&handle,
85-                           args.Holder (),
84+                           args.This (),
8685                          args.GetReturnValue ().Set (UV_EINVAL));
8786
8887  StreamBase* wrap = static_cast <StreamBase*>(handle);
@@ -96,11 +95,10 @@ void StreamBase::GetFD(Local<String> key,
9695template  <class  Base >
9796void  StreamBase::GetBytesRead (Local<String> key,
9897                              const  PropertyCallbackInfo<Value>& args) {
99-   Base* handle = Unwrap<Base>(args.Holder ());
100- 
10198  //  The handle instance hasn't been set. So no bytes could have been read.
99+   Base* handle;
102100  ASSIGN_OR_RETURN_UNWRAP (&handle,
103-                           args.Holder (),
101+                           args.This (),
104102                          args.GetReturnValue ().Set (0 ));
105103
106104  StreamBase* wrap = static_cast <StreamBase*>(handle);
@@ -112,9 +110,8 @@ void StreamBase::GetBytesRead(Local<String> key,
112110template  <class  Base >
113111void  StreamBase::GetExternal (Local<String> key,
114112                             const  PropertyCallbackInfo<Value>& args) {
115-   Base* handle = Unwrap<Base>(args.Holder ());
116- 
117-   ASSIGN_OR_RETURN_UNWRAP (&handle, args.Holder ());
113+   Base* handle;
114+   ASSIGN_OR_RETURN_UNWRAP (&handle, args.This ());
118115
119116  StreamBase* wrap = static_cast <StreamBase*>(handle);
120117  Local<External> ext = External::New (args.GetIsolate (), wrap);
@@ -125,8 +122,7 @@ void StreamBase::GetExternal(Local<String> key,
125122template  <class  Base ,
126123          int  (StreamBase::*Method)(const  FunctionCallbackInfo<Value>& args)>
127124void StreamBase::JSMethod(const  FunctionCallbackInfo<Value>& args) {
128-   Base* handle = Unwrap<Base>(args.Holder ());
129- 
125+   Base* handle;
130126  ASSIGN_OR_RETURN_UNWRAP (&handle, args.Holder ());
131127
132128  StreamBase* wrap = static_cast <StreamBase*>(handle);
0 commit comments