Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6ac7eef

Browse filesBrowse files
bnoordhuisgibfahn
authored andcommitted
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: #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>
1 parent 3a54bb5 commit 6ac7eef
Copy full SHA for 6ac7eef

File tree

Expand file treeCollapse file tree

2 files changed

+34
-38
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-38
lines changed
Open diff view settings
Collapse file

‎src/stream_base-inl.h‎

Copy file name to clipboardExpand all lines: src/stream_base-inl.h
+27-31Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
8181
template <class Base>
8282
void 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,
9998
template <class Base>
10099
void 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,
115113
template <class Base>
116114
void 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,
128125
template <class Base,
129126
int (StreamBase::*Method)(const FunctionCallbackInfo<Value>& args)>
130127
void 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);
Collapse file

‎src/udp_wrap.cc‎

Copy file name to clipboardExpand all lines: src/udp_wrap.cc
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ void UDPWrap::Initialize(Local<Object> target,
113113

114114
enum PropertyAttribute attributes =
115115
static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
116-
t->InstanceTemplate()->SetAccessor(env->fd_string(),
117-
UDPWrap::GetFD,
118-
nullptr,
119-
env->as_external(),
120-
v8::DEFAULT,
121-
attributes);
116+
t->PrototypeTemplate()->SetAccessor(env->fd_string(),
117+
UDPWrap::GetFD,
118+
nullptr,
119+
env->as_external(),
120+
v8::DEFAULT,
121+
attributes);
122122

123123
env->SetProtoMethod(t, "bind", Bind);
124124
env->SetProtoMethod(t, "send", Send);
@@ -169,7 +169,7 @@ void UDPWrap::New(const FunctionCallbackInfo<Value>& args) {
169169
void UDPWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) {
170170
int fd = UV_EBADF;
171171
#if !defined(_WIN32)
172-
UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder());
172+
UDPWrap* wrap = Unwrap<UDPWrap>(args.This());
173173
if (wrap != nullptr)
174174
uv_fileno(reinterpret_cast<uv_handle_t*>(&wrap->handle_), &fd);
175175
#endif

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.