From de61f97c3dbc1a07911349f8360f94be127ca28a Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 25 Oct 2017 10:02:54 +0200 Subject: src: move handle properties to prototype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Anna Henningsen --- src/stream_base-inl.h | 58 ++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) (limited to 'src/stream_base-inl.h') 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(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); @@ -81,11 +81,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); @@ -99,11 +98,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); @@ -115,9 +113,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); @@ -128,8 +125,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); -- cgit v1.2.3