Skip to content
Open
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
26 changes: 14 additions & 12 deletions src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1708,12 +1708,13 @@ void NativeKeyObject::CreateNativeKeyObjectClass(
Local<Value> callback = args[0];
CHECK(callback->IsFunction());

Local<FunctionTemplate> t =
NewFunctionTemplate(isolate, NativeKeyObject::New);
t->InstanceTemplate()->SetInternalFieldCount(
NativeKeyObject::kInternalFieldCount);
CHECK(env->crypto_key_object_constructor_template().IsEmpty());
env->set_crypto_key_object_constructor_template(t);
Local<FunctionTemplate> t = env->crypto_key_object_constructor_template();
if (t.IsEmpty()) {
t = NewFunctionTemplate(isolate, NativeKeyObject::New);
t->InstanceTemplate()->SetInternalFieldCount(
NativeKeyObject::kInternalFieldCount);
env->set_crypto_key_object_constructor_template(t);
}

Local<Value> ctor;
if (!t->GetFunction(env->context()).ToLocal(&ctor))
Expand Down Expand Up @@ -1945,12 +1946,13 @@ void NativeCryptoKey::CreateCryptoKeyClass(
Local<Value> callback = args[0];
CHECK(callback->IsFunction());

Local<FunctionTemplate> t =
NewFunctionTemplate(isolate, NativeCryptoKey::New);
t->InstanceTemplate()->SetInternalFieldCount(
NativeCryptoKey::kInternalFieldCount);
CHECK(env->crypto_cryptokey_constructor_template().IsEmpty());
env->set_crypto_cryptokey_constructor_template(t);
Local<FunctionTemplate> t = env->crypto_cryptokey_constructor_template();
if (t.IsEmpty()) {
t = NewFunctionTemplate(isolate, NativeCryptoKey::New);
t->InstanceTemplate()->SetInternalFieldCount(
NativeCryptoKey::kInternalFieldCount);
env->set_crypto_cryptokey_constructor_template(t);
}

Local<Value> ctor;
if (!t->GetFunction(env->context()).ToLocal(&ctor)) return;
Expand Down
7 changes: 5 additions & 2 deletions src/dtls/dtls_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ Local<FunctionTemplate> DTLSContext::GetConstructorTemplate(Environment* env) {
void DTLSContext::InitPerContext(Local<Object> target,
Local<Context> context,
Environment* env) {
SetConstructorFunction(
context, target, "DTLSContext", GetConstructorTemplate(env));
SetConstructorFunction(context,
target,
"DTLSContext",
GetConstructorTemplate(env),
SetConstructorFunctionFlag::NONE);
}

void DTLSContext::RegisterExternalReferences(
Expand Down
7 changes: 5 additions & 2 deletions src/dtls/dtls_endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ Local<FunctionTemplate> DTLSEndpoint::GetConstructorTemplate(Environment* env) {
void DTLSEndpoint::InitPerContext(Local<Object> target,
Local<Context> context,
Environment* env) {
SetConstructorFunction(
context, target, "DTLSEndpoint", GetConstructorTemplate(env));
SetConstructorFunction(context,
target,
"DTLSEndpoint",
GetConstructorTemplate(env),
SetConstructorFunctionFlag::NONE);
}

void DTLSEndpoint::RegisterExternalReferences(
Expand Down
7 changes: 5 additions & 2 deletions src/dtls/dtls_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ Local<FunctionTemplate> DTLSSession::GetConstructorTemplate(Environment* env) {
void DTLSSession::InitPerContext(Local<Object> target,
Local<Context> context,
Environment* env) {
SetConstructorFunction(
context, target, "DTLSSession", GetConstructorTemplate(env));
SetConstructorFunction(context,
target,
"DTLSSession",
GetConstructorTemplate(env),
SetConstructorFunctionFlag::NONE);
}

void DTLSSession::RegisterExternalReferences(
Expand Down
6 changes: 3 additions & 3 deletions src/env_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@
V(v8_heap_statistics_template, v8::DictionaryTemplate) \
V(histogram_ctor_template, v8::FunctionTemplate) \
V(http2settings_constructor_template, v8::ObjectTemplate) \
V(http2stream_constructor_template, v8::ObjectTemplate) \
V(http2stream_constructor_template, v8::FunctionTemplate) \
V(http2ping_constructor_template, v8::ObjectTemplate) \
V(i18n_converter_template, v8::ObjectTemplate) \
V(intervalhistogram_constructor_template, v8::FunctionTemplate) \
Expand All @@ -475,7 +475,7 @@
V(pipe_constructor_template, v8::FunctionTemplate) \
V(script_context_constructor_template, v8::FunctionTemplate) \
V(secure_context_constructor_template, v8::FunctionTemplate) \
V(shutdown_wrap_template, v8::ObjectTemplate) \
V(shutdown_wrap_template, v8::FunctionTemplate) \
V(soa_record_template, v8::DictionaryTemplate) \
V(socketaddress_constructor_template, v8::FunctionTemplate) \
V(space_stats_template, v8::DictionaryTemplate) \
Expand All @@ -494,7 +494,7 @@
V(urlpatterncomponentresult_template, v8::DictionaryTemplate) \
V(urlpatterninit_template, v8::DictionaryTemplate) \
V(urlpatternresult_template, v8::DictionaryTemplate) \
V(write_wrap_template, v8::ObjectTemplate) \
V(write_wrap_template, v8::FunctionTemplate) \
V(worker_cpu_profile_taker_template, v8::ObjectTemplate) \
V(worker_cpu_usage_taker_template, v8::ObjectTemplate) \
V(worker_heap_profile_taker_template, v8::ObjectTemplate) \
Expand Down
7 changes: 6 additions & 1 deletion src/node_ffi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,7 @@ Local<FunctionTemplate> DynamicLibrary::GetConstructorTemplate(
static_cast<PropertyAttribute>(ReadOnly | DontDelete);

tmpl = NewFunctionTemplate(isolate, DynamicLibrary::New);
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "DynamicLibrary"));
tmpl->InstanceTemplate()->SetInternalFieldCount(
DynamicLibrary::kInternalFieldCount);
Local<Signature> signature = Signature::New(isolate, tmpl);
Expand Down Expand Up @@ -1308,7 +1309,11 @@ static void Initialize(Local<Object> target,

// Create the DynamicLibrary template
Local<FunctionTemplate> dl_tmpl = DynamicLibrary::GetConstructorTemplate(env);
SetConstructorFunction(context, target, "DynamicLibrary", dl_tmpl);
SetConstructorFunction(context,
target,
"DynamicLibrary",
dl_tmpl,
SetConstructorFunctionFlag::NONE);
SetMethod(context, target, "toString", ToString);
SetMethod(context, target, "toBuffer", ToBuffer);
SetMethod(context, target, "toArrayBuffer", ToArrayBuffer);
Expand Down
74 changes: 43 additions & 31 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,7 @@ Http2Stream* Http2Stream::New(Http2Session* session,
Local<Object> obj;
if (!session->env()
->http2stream_constructor_template()
->InstanceTemplate()
->NewInstance(session->env()->context())
.ToLocal(&obj)) {
return nullptr;
Expand Down Expand Up @@ -3614,37 +3615,48 @@ void Initialize(Local<Object> target,
SetMethod(context, target, "packSettings", PackSettings);
SetMethod(context, target, "setCallbackFunctions", SetCallbackFunctions);

Local<FunctionTemplate> ping = FunctionTemplate::New(env->isolate());
ping->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Ping"));
ping->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<ObjectTemplate> pingt = ping->InstanceTemplate();
pingt->SetInternalFieldCount(Http2Ping::kInternalFieldCount);
env->set_http2ping_constructor_template(pingt);

Local<FunctionTemplate> setting = FunctionTemplate::New(env->isolate());
setting->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<ObjectTemplate> settingt = setting->InstanceTemplate();
settingt->SetInternalFieldCount(Http2Settings::kInternalFieldCount);
env->set_http2settings_constructor_template(settingt);

Local<FunctionTemplate> stream = FunctionTemplate::New(env->isolate());
SetProtoMethod(isolate, stream, "id", Http2Stream::GetID);
SetProtoMethod(isolate, stream, "destroy", Http2Stream::Destroy);
SetProtoMethod(isolate, stream, "priority", Http2Stream::Priority);
SetProtoMethod(isolate, stream, "pushPromise", Http2Stream::PushPromise);
SetProtoMethod(isolate, stream, "info", Http2Stream::Info);
SetProtoMethod(isolate, stream, "trailers", Http2Stream::Trailers);
SetProtoMethod(
isolate, stream, "disableAutoTrailers", Http2Stream::DisableAutoTrailers);
SetProtoMethod(isolate, stream, "respond", Http2Stream::Respond);
SetProtoMethod(isolate, stream, "rstStream", Http2Stream::RstStream);
SetProtoMethod(isolate, stream, "refreshState", Http2Stream::RefreshState);
stream->Inherit(AsyncWrap::GetConstructorTemplate(env));
StreamBase::AddMethods(env, stream);
Local<ObjectTemplate> streamt = stream->InstanceTemplate();
streamt->SetInternalFieldCount(Http2Stream::kInternalFieldCount);
env->set_http2stream_constructor_template(streamt);
SetConstructorFunction(context, target, "Http2Stream", stream);
if (env->http2ping_constructor_template().IsEmpty()) {
Local<FunctionTemplate> ping = FunctionTemplate::New(env->isolate());
ping->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Ping"));
ping->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<ObjectTemplate> pingt = ping->InstanceTemplate();
pingt->SetInternalFieldCount(Http2Ping::kInternalFieldCount);
env->set_http2ping_constructor_template(pingt);
}

if (env->http2settings_constructor_template().IsEmpty()) {
Local<FunctionTemplate> setting = FunctionTemplate::New(env->isolate());
setting->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<ObjectTemplate> settingt = setting->InstanceTemplate();
settingt->SetInternalFieldCount(Http2Settings::kInternalFieldCount);
env->set_http2settings_constructor_template(settingt);
}

Local<FunctionTemplate> stream = env->http2stream_constructor_template();
if (stream.IsEmpty()) {
stream = FunctionTemplate::New(env->isolate());
SetProtoMethod(isolate, stream, "id", Http2Stream::GetID);
SetProtoMethod(isolate, stream, "destroy", Http2Stream::Destroy);
SetProtoMethod(isolate, stream, "priority", Http2Stream::Priority);
SetProtoMethod(isolate, stream, "pushPromise", Http2Stream::PushPromise);
SetProtoMethod(isolate, stream, "info", Http2Stream::Info);
SetProtoMethod(isolate, stream, "trailers", Http2Stream::Trailers);
SetProtoMethod(isolate,
stream,
"disableAutoTrailers",
Http2Stream::DisableAutoTrailers);
SetProtoMethod(isolate, stream, "respond", Http2Stream::Respond);
SetProtoMethod(isolate, stream, "rstStream", Http2Stream::RstStream);
SetProtoMethod(isolate, stream, "refreshState", Http2Stream::RefreshState);
stream->Inherit(AsyncWrap::GetConstructorTemplate(env));
StreamBase::AddMethods(env, stream);
stream->InstanceTemplate()->SetInternalFieldCount(
Http2Stream::kInternalFieldCount);
stream->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "Http2Stream"));
env->set_http2stream_constructor_template(stream);
}
SetConstructorFunction(
context, target, "Http2Stream", stream, SetConstructorFunctionFlag::NONE);

Local<FunctionTemplate> session =
NewFunctionTemplate(isolate, Http2Session::New);
Expand Down
10 changes: 7 additions & 3 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4632,9 +4632,13 @@ static void Initialize(Local<Object> target,
SetConstructorFunction(context,
target,
"StatementSync",
StatementSync::GetConstructorTemplate(env));
SetConstructorFunction(
context, target, "Session", Session::GetConstructorTemplate(env));
StatementSync::GetConstructorTemplate(env),
SetConstructorFunctionFlag::NONE);
SetConstructorFunction(context,
target,
"Session",
Session::GetConstructorTemplate(env),
SetConstructorFunctionFlag::NONE);

target->Set(context, env->constants_string(), constants).Check();

Expand Down
28 changes: 16 additions & 12 deletions src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,28 @@ void PipeWrap::Initialize(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
Isolate* isolate = env->isolate();

Local<FunctionTemplate> t = NewFunctionTemplate(isolate, New);
t->InstanceTemplate()->SetInternalFieldCount(PipeWrap::kInternalFieldCount);
Local<FunctionTemplate> t = env->pipe_constructor_template();
if (t.IsEmpty()) {
t = NewFunctionTemplate(isolate, New);
t->InstanceTemplate()->SetInternalFieldCount(PipeWrap::kInternalFieldCount);

t->Inherit(LibuvStreamWrap::GetConstructorTemplate(env));
t->Inherit(LibuvStreamWrap::GetConstructorTemplate(env));

SetProtoMethod(isolate, t, "bind", Bind);
SetProtoMethod(isolate, t, "listen", Listen);
SetProtoMethod(isolate, t, "connect", Connect);
SetProtoMethod(isolate, t, "open", Open);
SetProtoMethod(isolate, t, "bind", Bind);
SetProtoMethod(isolate, t, "listen", Listen);
SetProtoMethod(isolate, t, "connect", Connect);
SetProtoMethod(isolate, t, "open", Open);

#ifdef _WIN32
SetProtoMethod(isolate, t, "setPendingInstances", SetPendingInstances);
SetProtoMethod(isolate, t, "setPendingInstances", SetPendingInstances);
#endif

SetProtoMethod(isolate, t, "fchmod", Fchmod);

SetConstructorFunction(context, target, "Pipe", t);
env->set_pipe_constructor_template(t);
SetProtoMethod(isolate, t, "fchmod", Fchmod);
t->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "Pipe"));
env->set_pipe_constructor_template(t);
}
SetConstructorFunction(
context, target, "Pipe", t, SetConstructorFunctionFlag::NONE);

// Create FunctionTemplate for PipeConnectWrap.
auto cwt = AsyncWrap::MakeLazilyInitializedJSTemplate(env);
Expand Down
4 changes: 4 additions & 0 deletions src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int StreamBase::Shutdown(v8::Local<v8::Object> req_wrap_obj) {

if (req_wrap_obj.IsEmpty()) {
if (!env->shutdown_wrap_template()
->InstanceTemplate()
->NewInstance(env->context())
.ToLocal(&req_wrap_obj)) {
return UV_EBUSY;
Expand Down Expand Up @@ -103,6 +104,7 @@ StreamWriteResult StreamBase::Write(uv_buf_t* bufs,

if (req_wrap_obj.IsEmpty()) {
if (!env->write_wrap_template()
->InstanceTemplate()
->NewInstance(env->context())
.ToLocal(&req_wrap_obj)) {
return StreamWriteResult{false, UV_EBUSY, nullptr, 0, {}};
Expand Down Expand Up @@ -332,6 +334,7 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
if (lazy_req) {
// Sending a handle requires a request object up front to reference it.
if (!env->write_wrap_template()
->InstanceTemplate()
->NewInstance(env->context())
.ToLocal(&req_wrap_obj)) {
return UV_EBUSY;
Expand Down Expand Up @@ -447,6 +450,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
if (lazy_req && req_wrap_obj.IsEmpty()) {
// Sending a handle requires a request object up front to reference it.
if (!env->write_wrap_template()
->InstanceTemplate()
->NewInstance(env->context())
.ToLocal(&req_wrap_obj)) {
return UV_EBUSY;
Expand Down
Loading
Loading