diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2017-10-25 10:02:54 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-10-29 11:39:42 +0100 |
commit | de61f97c3dbc1a07911349f8360f94be127ca28a (patch) | |
tree | 816dd1e73d8f8cefaea56e367ab483c7a6accdcc /src/stream_base-inl.h | |
parent | 7c3d6ccbf2101580d7704f8c37de09ef109ba841 (diff) | |
download | android-node-v8-de61f97c3dbc1a07911349f8360f94be127ca28a.tar.gz android-node-v8-de61f97c3dbc1a07911349f8360f94be127ca28a.tar.bz2 android-node-v8-de61f97c3dbc1a07911349f8360f94be127ca28a.zip |
src: move handle properties to prototype
Reduce the size of wrap objects by moving a couple of accessors from the
instance template to the prototype template. They occupied one slot per
instance instead of one slot per class.
This commit fixes some instances of unwrapping twice since that code had
to be updated anyway to use `args.This()` instead of `args.Holder()`.
PR-URL: https://github.com/nodejs/node/pull/16482
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r-- | src/stream_base-inl.h | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 25293d2d06..562af2a533 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -33,26 +33,26 @@ void StreamBase::AddMethods(Environment* env, enum PropertyAttribute attributes = static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete); - t->InstanceTemplate()->SetAccessor(env->fd_string(), - GetFD<Base>, - nullptr, - env->as_external(), - v8::DEFAULT, - attributes); - - t->InstanceTemplate()->SetAccessor(env->external_stream_string(), - GetExternal<Base>, - nullptr, - env->as_external(), - v8::DEFAULT, - attributes); - - t->InstanceTemplate()->SetAccessor(env->bytes_read_string(), - GetBytesRead<Base>, - nullptr, - env->as_external(), - v8::DEFAULT, - attributes); + t->PrototypeTemplate()->SetAccessor(env->fd_string(), + GetFD<Base>, + nullptr, + env->as_external(), + v8::DEFAULT, + attributes); + + t->PrototypeTemplate()->SetAccessor(env->external_stream_string(), + GetExternal<Base>, + nullptr, + env->as_external(), + v8::DEFAULT, + attributes); + + t->PrototypeTemplate()->SetAccessor(env->bytes_read_string(), + GetBytesRead<Base>, + nullptr, + env->as_external(), + v8::DEFAULT, + attributes); env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>); env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>); @@ -81,11 +81,10 @@ void StreamBase::AddMethods(Environment* env, template <class Base> void StreamBase::GetFD(Local<String> key, const PropertyCallbackInfo<Value>& args) { - Base* handle = Unwrap<Base>(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<StreamBase*>(handle); @@ -99,11 +98,10 @@ void StreamBase::GetFD(Local<String> key, template <class Base> void StreamBase::GetBytesRead(Local<String> key, const PropertyCallbackInfo<Value>& args) { - Base* handle = Unwrap<Base>(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<StreamBase*>(handle); @@ -115,9 +113,8 @@ void StreamBase::GetBytesRead(Local<String> key, template <class Base> void StreamBase::GetExternal(Local<String> key, const PropertyCallbackInfo<Value>& args) { - Base* handle = Unwrap<Base>(args.Holder()); - - ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder()); + Base* handle; + ASSIGN_OR_RETURN_UNWRAP(&handle, args.This()); StreamBase* wrap = static_cast<StreamBase*>(handle); Local<External> ext = External::New(args.GetIsolate(), wrap); @@ -128,8 +125,7 @@ void StreamBase::GetExternal(Local<String> key, template <class Base, int (StreamBase::*Method)(const FunctionCallbackInfo<Value>& args)> void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) { - Base* handle = Unwrap<Base>(args.Holder()); - + Base* handle; ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder()); StreamBase* wrap = static_cast<StreamBase*>(handle); |