Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quic: set up FunctionTemplates more cleanly #33968

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/quic/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3723,7 +3723,7 @@ void QuicSession::Initialize(
session->SetClassName(class_name);
session->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<ObjectTemplate> sessiont = session->InstanceTemplate();
sessiont->SetInternalFieldCount(1);
sessiont->SetInternalFieldCount(QuicSession::kInternalFieldCount);
sessiont->Set(env->owner_symbol(), Null(env->isolate()));
AddMethods(env, session);
env->set_quicserversession_instance_template(sessiont);
Expand All @@ -3736,7 +3736,7 @@ void QuicSession::Initialize(
session->SetClassName(class_name);
session->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<ObjectTemplate> sessiont = session->InstanceTemplate();
sessiont->SetInternalFieldCount(1);
sessiont->SetInternalFieldCount(QuicSession::kInternalFieldCount);
sessiont->Set(env->owner_symbol(), Null(env->isolate()));
AddMethods(env, session);
env->SetProtoMethod(session,
Expand Down
16 changes: 11 additions & 5 deletions src/quic/node_quic_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,10 @@ void QuicEndpoint::Initialize(
Isolate* isolate = env->isolate();
Local<String> class_name = FIXED_ONE_BYTE_STRING(isolate, "QuicEndpoint");
Local<FunctionTemplate> endpoint = env->NewFunctionTemplate(NewQuicEndpoint);
endpoint->Inherit(BaseObject::GetConstructorTemplate(env));
endpoint->SetClassName(class_name);
endpoint->InstanceTemplate()->SetInternalFieldCount(1);
endpoint->InstanceTemplate()->SetInternalFieldCount(
QuicEndpoint::kInternalFieldCount);
env->SetProtoMethod(endpoint,
"waitForPendingCallbacks",
QuicEndpointWaitForPendingCallbacks);
Expand All @@ -1142,8 +1144,10 @@ void QuicSocket::Initialize(
Isolate* isolate = env->isolate();
Local<String> class_name = FIXED_ONE_BYTE_STRING(isolate, "QuicSocket");
Local<FunctionTemplate> socket = env->NewFunctionTemplate(NewQuicSocket);
socket->Inherit(AsyncWrap::GetConstructorTemplate(env));
socket->SetClassName(class_name);
socket->InstanceTemplate()->SetInternalFieldCount(1);
socket->InstanceTemplate()->SetInternalFieldCount(
QuicSocket::kInternalFieldCount);
socket->InstanceTemplate()->Set(env->owner_symbol(), Null(isolate));
env->SetProtoMethod(socket,
"addEndpoint",
Expand All @@ -1170,9 +1174,11 @@ void QuicSocket::Initialize(
target->Set(context, class_name,
socket->GetFunction(env->context()).ToLocalChecked()).FromJust();

// TODO(addaleax): None of these templates actually are constructor templates.
Local<ObjectTemplate> sendwrap_template = ObjectTemplate::New(isolate);
sendwrap_template->SetInternalFieldCount(1);
Local<FunctionTemplate> sendwrap_ctor = FunctionTemplate::New(isolate);
sendwrap_ctor->Inherit(AsyncWrap::GetConstructorTemplate(env));
sendwrap_ctor->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "SendWrap"));
Local<ObjectTemplate> sendwrap_template = sendwrap_ctor->InstanceTemplate();
sendwrap_template->SetInternalFieldCount(SendWrap::kInternalFieldCount);
env->set_quicsocketsendwrap_instance_template(sendwrap_template);
}

Expand Down