Skip to content

Commit 1b7434d

Browse files
addaleaxjasnell
authored andcommitted
quic: set up FunctionTemplates more cleanly
- Use `kInternalFieldCount`, similar to 0fac393. - Always inherit from the correct parent template, similar to 8a7201b. - Always provide a template class name. PR-URL: #33968 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent df144d2 commit 1b7434d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/quic/node_quic_session.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3723,7 +3723,7 @@ void QuicSession::Initialize(
37233723
session->SetClassName(class_name);
37243724
session->Inherit(AsyncWrap::GetConstructorTemplate(env));
37253725
Local<ObjectTemplate> sessiont = session->InstanceTemplate();
3726-
sessiont->SetInternalFieldCount(1);
3726+
sessiont->SetInternalFieldCount(QuicSession::kInternalFieldCount);
37273727
sessiont->Set(env->owner_symbol(), Null(env->isolate()));
37283728
AddMethods(env, session);
37293729
env->set_quicserversession_instance_template(sessiont);
@@ -3736,7 +3736,7 @@ void QuicSession::Initialize(
37363736
session->SetClassName(class_name);
37373737
session->Inherit(AsyncWrap::GetConstructorTemplate(env));
37383738
Local<ObjectTemplate> sessiont = session->InstanceTemplate();
3739-
sessiont->SetInternalFieldCount(1);
3739+
sessiont->SetInternalFieldCount(QuicSession::kInternalFieldCount);
37403740
sessiont->Set(env->owner_symbol(), Null(env->isolate()));
37413741
AddMethods(env, session);
37423742
env->SetProtoMethod(session,

src/quic/node_quic_socket.cc

+11-5
Original file line numberDiff line numberDiff line change
@@ -1121,8 +1121,10 @@ void QuicEndpoint::Initialize(
11211121
Isolate* isolate = env->isolate();
11221122
Local<String> class_name = FIXED_ONE_BYTE_STRING(isolate, "QuicEndpoint");
11231123
Local<FunctionTemplate> endpoint = env->NewFunctionTemplate(NewQuicEndpoint);
1124+
endpoint->Inherit(BaseObject::GetConstructorTemplate(env));
11241125
endpoint->SetClassName(class_name);
1125-
endpoint->InstanceTemplate()->SetInternalFieldCount(1);
1126+
endpoint->InstanceTemplate()->SetInternalFieldCount(
1127+
QuicEndpoint::kInternalFieldCount);
11261128
env->SetProtoMethod(endpoint,
11271129
"waitForPendingCallbacks",
11281130
QuicEndpointWaitForPendingCallbacks);
@@ -1142,8 +1144,10 @@ void QuicSocket::Initialize(
11421144
Isolate* isolate = env->isolate();
11431145
Local<String> class_name = FIXED_ONE_BYTE_STRING(isolate, "QuicSocket");
11441146
Local<FunctionTemplate> socket = env->NewFunctionTemplate(NewQuicSocket);
1147+
socket->Inherit(AsyncWrap::GetConstructorTemplate(env));
11451148
socket->SetClassName(class_name);
1146-
socket->InstanceTemplate()->SetInternalFieldCount(1);
1149+
socket->InstanceTemplate()->SetInternalFieldCount(
1150+
QuicSocket::kInternalFieldCount);
11471151
socket->InstanceTemplate()->Set(env->owner_symbol(), Null(isolate));
11481152
env->SetProtoMethod(socket,
11491153
"addEndpoint",
@@ -1170,9 +1174,11 @@ void QuicSocket::Initialize(
11701174
target->Set(context, class_name,
11711175
socket->GetFunction(env->context()).ToLocalChecked()).FromJust();
11721176

1173-
// TODO(addaleax): None of these templates actually are constructor templates.
1174-
Local<ObjectTemplate> sendwrap_template = ObjectTemplate::New(isolate);
1175-
sendwrap_template->SetInternalFieldCount(1);
1177+
Local<FunctionTemplate> sendwrap_ctor = FunctionTemplate::New(isolate);
1178+
sendwrap_ctor->Inherit(AsyncWrap::GetConstructorTemplate(env));
1179+
sendwrap_ctor->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SendWrap"));
1180+
Local<ObjectTemplate> sendwrap_template = sendwrap_ctor->InstanceTemplate();
1181+
sendwrap_template->SetInternalFieldCount(SendWrap::kInternalFieldCount);
11761182
env->set_quicsocketsendwrap_instance_template(sendwrap_template);
11771183
}
11781184

0 commit comments

Comments
 (0)