Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2020-12-15 22:52:17 +0300
committerJames M Snell <jasnell@gmail.com>2021-01-03 23:58:09 +0300
commit28fe1ef63512acd40cfd1dd15918db494c92f45f (patch)
treefb65e10e0c966e2484a3f2151870738499d575b7
parent7cfa1bee418696c1c97c1f2466520ab4f4cc8791 (diff)
src: reduce duplicated boilerplate with new env utility fn
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/36536 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
-rw-r--r--src/README.md6
-rw-r--r--src/cares_wrap.cc27
-rw-r--r--src/crypto/crypto_cipher.cc5
-rw-r--r--src/crypto/crypto_context.cc7
-rw-r--r--src/crypto/crypto_dh.cc4
-rw-r--r--src/crypto/crypto_ecdh.cc4
-rw-r--r--src/crypto/crypto_hash.cc4
-rw-r--r--src/crypto/crypto_hmac.cc4
-rw-r--r--src/crypto/crypto_sig.cc8
-rw-r--r--src/crypto/crypto_util.h8
-rw-r--r--src/env-inl.h18
-rw-r--r--src/env.h8
-rw-r--r--src/fs_event_wrap.cc6
-rw-r--r--src/inspector_js_api.cc10
-rw-r--r--src/js_stream.cc8
-rw-r--r--src/js_udp_wrap.cc8
-rw-r--r--src/module_wrap.cc6
-rw-r--r--src/node_contextify.cc12
-rw-r--r--src/node_dir.cc10
-rw-r--r--src/node_file.cc16
-rw-r--r--src/node_http2.cc14
-rw-r--r--src/node_http_parser.cc5
-rw-r--r--src/node_messaging.cc26
-rw-r--r--src/node_perf.cc3
-rw-r--r--src/node_serdes.cc14
-rw-r--r--src/node_sockaddr.cc6
-rw-r--r--src/node_stat_watcher.cc7
-rw-r--r--src/node_trace_events.cc5
-rw-r--r--src/node_util.cc6
-rw-r--r--src/node_wasi.cc6
-rw-r--r--src/node_watchdog.cc9
-rw-r--r--src/node_worker.cc7
-rw-r--r--src/node_zlib.cc7
-rw-r--r--src/pipe_wrap.cc14
-rw-r--r--src/process_wrap.cc7
-rw-r--r--src/quic/node_quic_socket.cc14
-rw-r--r--src/quic/node_quic_stream.cc9
-rw-r--r--src/signal_wrap.cc8
-rw-r--r--src/stream_pipe.cc9
-rw-r--r--src/stream_wrap.cc15
-rw-r--r--src/tcp_wrap.cc13
-rw-r--r--src/udp_wrap.cc15
-rw-r--r--src/uv.cc9
43 files changed, 95 insertions, 312 deletions
diff --git a/src/README.md b/src/README.md
index 2be97e28b8f..aec56e7a7ba 100644
--- a/src/README.md
+++ b/src/README.md
@@ -405,11 +405,7 @@ void Initialize(Local<Object> target,
env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers);
- Local<String> channel_wrap_string =
- FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
- channel_wrap->SetClassName(channel_wrap_string);
- target->Set(env->context(), channel_wrap_string,
- channel_wrap->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "ChannelWrap", channel_wrap);
}
// Run the `Initialize` function when loading this module through
diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc
index 71766fa3917..2bf4211b118 100644
--- a/src/cares_wrap.cc
+++ b/src/cares_wrap.cc
@@ -2345,32 +2345,17 @@ void Initialize(Local<Object> target,
Local<FunctionTemplate> aiw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
aiw->Inherit(AsyncWrap::GetConstructorTemplate(env));
- Local<String> addrInfoWrapString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap");
- aiw->SetClassName(addrInfoWrapString);
- target->Set(env->context(),
- addrInfoWrapString,
- aiw->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "GetAddrInfoReqWrap", aiw);
Local<FunctionTemplate> niw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
niw->Inherit(AsyncWrap::GetConstructorTemplate(env));
- Local<String> nameInfoWrapString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap");
- niw->SetClassName(nameInfoWrapString);
- target->Set(env->context(),
- nameInfoWrapString,
- niw->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "GetNameInfoReqWrap", niw);
Local<FunctionTemplate> qrw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
qrw->Inherit(AsyncWrap::GetConstructorTemplate(env));
- Local<String> queryWrapString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap");
- qrw->SetClassName(queryWrapString);
- target->Set(env->context(),
- queryWrapString,
- qrw->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "QueryReqWrap", qrw);
Local<FunctionTemplate> channel_wrap =
env->NewFunctionTemplate(ChannelWrap::New);
@@ -2397,11 +2382,7 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(channel_wrap, "setLocalAddress", SetLocalAddress);
env->SetProtoMethod(channel_wrap, "cancel", Cancel);
- Local<String> channelWrapString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
- channel_wrap->SetClassName(channelWrapString);
- target->Set(env->context(), channelWrapString,
- channel_wrap->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "ChannelWrap", channel_wrap);
}
} // anonymous namespace
diff --git a/src/crypto/crypto_cipher.cc b/src/crypto/crypto_cipher.cc
index f3939d3477c..ddbf7114b67 100644
--- a/src/crypto/crypto_cipher.cc
+++ b/src/crypto/crypto_cipher.cc
@@ -265,10 +265,7 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethodNoSideEffect(t, "getAuthTag", GetAuthTag);
env->SetProtoMethod(t, "setAuthTag", SetAuthTag);
env->SetProtoMethod(t, "setAAD", SetAAD);
-
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "CipherBase"),
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "CipherBase", t);
env->SetMethodNoSideEffect(target, "getSSLCiphers", GetSSLCiphers);
env->SetMethodNoSideEffect(target, "getCiphers", GetCiphers);
diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc
index 612d2194849..874ae1c27c8 100644
--- a/src/crypto/crypto_context.cc
+++ b/src/crypto/crypto_context.cc
@@ -252,9 +252,6 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
t->InstanceTemplate()->SetInternalFieldCount(
SecureContext::kInternalFieldCount);
t->Inherit(BaseObject::GetConstructorTemplate(env));
- Local<String> secureContextString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext");
- t->SetClassName(secureContextString);
env->SetProtoMethod(t, "init", Init);
env->SetProtoMethod(t, "setKey", SetKey);
@@ -313,8 +310,8 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
Local<FunctionTemplate>(),
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
- target->Set(env->context(), secureContextString,
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "SecureContext", t);
+
env->set_secure_context_constructor_template(t);
env->SetMethodNoSideEffect(target, "getRootCertificates",
diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc
index a2720301cab..b40f06f4500 100644
--- a/src/crypto/crypto_dh.cc
+++ b/src/crypto/crypto_dh.cc
@@ -93,9 +93,7 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
Local<FunctionTemplate>(),
attributes);
- target->Set(env->context(),
- name,
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, name, t);
};
make(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"), New);
diff --git a/src/crypto/crypto_ecdh.cc b/src/crypto/crypto_ecdh.cc
index 277a5a731d3..efeb08b908e 100644
--- a/src/crypto/crypto_ecdh.cc
+++ b/src/crypto/crypto_ecdh.cc
@@ -52,9 +52,7 @@ void ECDH::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "setPublicKey", SetPublicKey);
env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey);
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH"),
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "ECDH", t);
env->SetMethodNoSideEffect(target, "ECDHConvertKey", ECDH::ConvertKey);
env->SetMethodNoSideEffect(target, "getCurves", ECDH::GetCurves);
diff --git a/src/crypto/crypto_hash.cc b/src/crypto/crypto_hash.cc
index d49a7c5d022..664ffb84721 100644
--- a/src/crypto/crypto_hash.cc
+++ b/src/crypto/crypto_hash.cc
@@ -50,9 +50,7 @@ void Hash::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "update", HashUpdate);
env->SetProtoMethod(t, "digest", HashDigest);
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "Hash"),
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Hash", t);
env->SetMethodNoSideEffect(target, "getHashes", GetHashes);
diff --git a/src/crypto/crypto_hmac.cc b/src/crypto/crypto_hmac.cc
index ff7c1603020..055541196d2 100644
--- a/src/crypto/crypto_hmac.cc
+++ b/src/crypto/crypto_hmac.cc
@@ -48,9 +48,7 @@ void Hmac::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "update", HmacUpdate);
env->SetProtoMethod(t, "digest", HmacDigest);
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "Hmac"),
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Hmac", t);
HmacJob::Initialize(env, target);
}
diff --git a/src/crypto/crypto_sig.cc b/src/crypto/crypto_sig.cc
index 59a9569ce81..a5a95878a9e 100644
--- a/src/crypto/crypto_sig.cc
+++ b/src/crypto/crypto_sig.cc
@@ -276,9 +276,7 @@ void Sign::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "update", SignUpdate);
env->SetProtoMethod(t, "sign", SignFinal);
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "Sign"),
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Sign", t);
env->SetMethod(target, "signOneShot", Sign::SignSync);
@@ -396,9 +394,7 @@ void Verify::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "update", VerifyUpdate);
env->SetProtoMethod(t, "verify", VerifyFinal);
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "Verify"),
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Verify", t);
env->SetMethod(target, "verifyOneShot", Verify::VerifySync);
}
diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h
index a8aa4a707f4..3f245910ed8 100644
--- a/src/crypto/crypto_util.h
+++ b/src/crypto/crypto_util.h
@@ -349,17 +349,11 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
Environment* env,
v8::Local<v8::Object> target) {
v8::Local<v8::FunctionTemplate> job = env->NewFunctionTemplate(new_fn);
- v8::Local<v8::String> class_name =
- OneByteString(env->isolate(), CryptoJobTraits::JobName);
- job->SetClassName(class_name);
job->Inherit(AsyncWrap::GetConstructorTemplate(env));
job->InstanceTemplate()->SetInternalFieldCount(
AsyncWrap::kInternalFieldCount);
env->SetProtoMethod(job, "run", Run);
- target->Set(
- env->context(),
- class_name,
- job->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, CryptoJobTraits::JobName, job);
}
private:
diff --git a/src/env-inl.h b/src/env-inl.h
index cd9f6daaaff..4cb68e1c5de 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -1024,6 +1024,24 @@ inline void Environment::SetInstanceMethod(v8::Local<v8::FunctionTemplate> that,
t->SetClassName(name_string);
}
+inline void Environment::SetConstructorFunction(
+ v8::Local<v8::Object> that,
+ const char* name,
+ v8::Local<v8::FunctionTemplate> tmpl) {
+ SetConstructorFunction(that, OneByteString(isolate(), name), tmpl);
+}
+
+inline void Environment::SetConstructorFunction(
+ v8::Local<v8::Object> that,
+ v8::Local<v8::String> name,
+ v8::Local<v8::FunctionTemplate> tmpl) {
+ tmpl->SetClassName(name);
+ that->Set(
+ context(),
+ name,
+ tmpl->GetFunction(context()).ToLocalChecked()).Check();
+}
+
void Environment::AddCleanupHook(CleanupCallback fn, void* arg) {
auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback {
fn, arg, cleanup_hook_counter_++
diff --git a/src/env.h b/src/env.h
index a0d59ff8728..9ac090e07cc 100644
--- a/src/env.h
+++ b/src/env.h
@@ -1233,6 +1233,14 @@ class Environment : public MemoryRetainer {
const char* name,
v8::FunctionCallback callback);
+ inline void SetConstructorFunction(v8::Local<v8::Object> that,
+ const char* name,
+ v8::Local<v8::FunctionTemplate> tmpl);
+
+ inline void SetConstructorFunction(v8::Local<v8::Object> that,
+ v8::Local<v8::String> name,
+ v8::Local<v8::FunctionTemplate> tmpl);
+
void AtExit(void (*cb)(void* arg), void* arg);
void RunAtExitCallbacks();
diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc
index faa650b7a10..b79da7e8362 100644
--- a/src/fs_event_wrap.cc
+++ b/src/fs_event_wrap.cc
@@ -95,11 +95,9 @@ void FSEventWrap::Initialize(Local<Object> target,
void* priv) {
Environment* env = Environment::GetCurrent(context);
- auto fsevent_string = FIXED_ONE_BYTE_STRING(env->isolate(), "FSEvent");
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
t->InstanceTemplate()->SetInternalFieldCount(
FSEventWrap::kInternalFieldCount);
- t->SetClassName(fsevent_string);
t->Inherit(HandleWrap::GetConstructorTemplate(env));
env->SetProtoMethod(t, "start", Start);
@@ -116,9 +114,7 @@ void FSEventWrap::Initialize(Local<Object> target,
Local<FunctionTemplate>(),
static_cast<PropertyAttribute>(ReadOnly | DontDelete | DontEnum));
- target->Set(env->context(),
- fsevent_string,
- t->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "FSEvent", t);
}
diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc
index c0791ce3194..8de1f8e7b0a 100644
--- a/src/inspector_js_api.cc
+++ b/src/inspector_js_api.cc
@@ -102,19 +102,17 @@ class JSBindingsConnection : public AsyncWrap {
}
static void Bind(Environment* env, Local<Object> target) {
- Local<String> class_name = ConnectionType::GetClassName(env);
Local<FunctionTemplate> tmpl =
env->NewFunctionTemplate(JSBindingsConnection::New);
tmpl->InstanceTemplate()->SetInternalFieldCount(
JSBindingsConnection::kInternalFieldCount);
- tmpl->SetClassName(class_name);
tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env));
env->SetProtoMethod(tmpl, "dispatch", JSBindingsConnection::Dispatch);
env->SetProtoMethod(tmpl, "disconnect", JSBindingsConnection::Disconnect);
- target->Set(env->context(),
- class_name,
- tmpl->GetFunction(env->context()).ToLocalChecked())
- .ToChecked();
+ env->SetConstructorFunction(
+ target,
+ ConnectionType::GetClassName(env),
+ tmpl);
}
static void New(const FunctionCallbackInfo<Value>& info) {
diff --git a/src/js_stream.cc b/src/js_stream.cc
index e4da0ce747e..399e073efba 100644
--- a/src/js_stream.cc
+++ b/src/js_stream.cc
@@ -19,7 +19,6 @@ using v8::HandleScope;
using v8::Int32;
using v8::Local;
using v8::Object;
-using v8::String;
using v8::Value;
@@ -200,9 +199,6 @@ void JSStream::Initialize(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
- Local<String> jsStreamString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream");
- t->SetClassName(jsStreamString);
t->InstanceTemplate()
->SetInternalFieldCount(StreamBase::kInternalFieldCount);
t->Inherit(AsyncWrap::GetConstructorTemplate(env));
@@ -213,9 +209,7 @@ void JSStream::Initialize(Local<Object> target,
env->SetProtoMethod(t, "emitEOF", EmitEOF);
StreamBase::AddMethods(env, t);
- target->Set(env->context(),
- jsStreamString,
- t->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "JSStream", t);
}
} // namespace node
diff --git a/src/js_udp_wrap.cc b/src/js_udp_wrap.cc
index c5168314118..6a9bda5cad1 100644
--- a/src/js_udp_wrap.cc
+++ b/src/js_udp_wrap.cc
@@ -16,7 +16,6 @@ using v8::HandleScope;
using v8::Int32;
using v8::Local;
using v8::Object;
-using v8::String;
using v8::Value;
// JSUDPWrap is a testing utility used by test/common/udppair.js
@@ -195,9 +194,6 @@ void JSUDPWrap::Initialize(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
- Local<String> js_udp_wrap_string =
- FIXED_ONE_BYTE_STRING(env->isolate(), "JSUDPWrap");
- t->SetClassName(js_udp_wrap_string);
t->InstanceTemplate()
->SetInternalFieldCount(UDPWrapBase::kUDPWrapBaseField + 1);
t->Inherit(AsyncWrap::GetConstructorTemplate(env));
@@ -207,9 +203,7 @@ void JSUDPWrap::Initialize(Local<Object> target,
env->SetProtoMethod(t, "onSendDone", OnSendDone);
env->SetProtoMethod(t, "onAfterBind", OnAfterBind);
- target->Set(env->context(),
- js_udp_wrap_string,
- t->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "JSUDPWrap", t);
}
diff --git a/src/module_wrap.cc b/src/module_wrap.cc
index 9302fa6f68d..0ac36d4aa63 100644
--- a/src/module_wrap.cc
+++ b/src/module_wrap.cc
@@ -722,10 +722,8 @@ void ModuleWrap::Initialize(Local<Object> target,
Local<Context> context,
void* priv) {
Environment* env = Environment::GetCurrent(context);
- Isolate* isolate = env->isolate();
Local<FunctionTemplate> tpl = env->NewFunctionTemplate(New);
- tpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"));
tpl->InstanceTemplate()->SetInternalFieldCount(
ModuleWrap::kInternalFieldCount);
tpl->Inherit(BaseObject::GetConstructorTemplate(env));
@@ -741,8 +739,8 @@ void ModuleWrap::Initialize(Local<Object> target,
env->SetProtoMethodNoSideEffect(tpl, "getStaticDependencySpecifiers",
GetStaticDependencySpecifiers);
- target->Set(env->context(), FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
- tpl->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "ModuleWrap", tpl);
+
env->SetMethod(target,
"setImportModuleDynamicallyCallback",
SetImportModuleDynamicallyCallback);
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index 0accd99c0c4..a0acdb75eed 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -1282,21 +1282,11 @@ void MicrotaskQueueWrap::New(const FunctionCallbackInfo<Value>& args) {
void MicrotaskQueueWrap::Init(Environment* env, Local<Object> target) {
HandleScope scope(env->isolate());
- Local<String> class_name =
- FIXED_ONE_BYTE_STRING(env->isolate(), "MicrotaskQueue");
-
Local<FunctionTemplate> tmpl = env->NewFunctionTemplate(New);
tmpl->InstanceTemplate()->SetInternalFieldCount(
ContextifyScript::kInternalFieldCount);
- tmpl->SetClassName(class_name);
-
- if (target->Set(env->context(),
- class_name,
- tmpl->GetFunction(env->context()).ToLocalChecked())
- .IsNothing()) {
- return;
- }
env->set_microtask_queue_ctor_template(tmpl);
+ env->SetConstructorFunction(target, "MicrotaskQueue", tmpl);
}
diff --git a/src/node_dir.cc b/src/node_dir.cc
index ac5739b9932..a8bb2a7083c 100644
--- a/src/node_dir.cc
+++ b/src/node_dir.cc
@@ -39,7 +39,6 @@ using v8::Null;
using v8::Number;
using v8::Object;
using v8::ObjectTemplate;
-using v8::String;
using v8::Value;
#define TRACE_NAME(name) "fs_dir.sync." #name
@@ -349,7 +348,6 @@ void Initialize(Local<Object> target,
Local<Context> context,
void* priv) {
Environment* env = Environment::GetCurrent(context);
- Isolate* isolate = env->isolate();
env->SetMethod(target, "opendir", OpenDir);
@@ -360,13 +358,7 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(dir, "close", DirHandle::Close);
Local<ObjectTemplate> dirt = dir->InstanceTemplate();
dirt->SetInternalFieldCount(DirHandle::kInternalFieldCount);
- Local<String> handleString =
- FIXED_ONE_BYTE_STRING(isolate, "DirHandle");
- dir->SetClassName(handleString);
- target
- ->Set(context, handleString,
- dir->GetFunction(env->context()).ToLocalChecked())
- .FromJust();
+ env->SetConstructorFunction(target, "DirHandle", dir);
env->set_dir_instance_template(dirt);
}
diff --git a/src/node_file.cc b/src/node_file.cc
index 077727e87b5..3e9a3076fd8 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -2471,13 +2471,7 @@ void Initialize(Local<Object> target,
fst->InstanceTemplate()->SetInternalFieldCount(
FSReqBase::kInternalFieldCount);
fst->Inherit(AsyncWrap::GetConstructorTemplate(env));
- Local<String> wrapString =
- FIXED_ONE_BYTE_STRING(isolate, "FSReqCallback");
- fst->SetClassName(wrapString);
- target
- ->Set(context, wrapString,
- fst->GetFunction(env->context()).ToLocalChecked())
- .Check();
+ env->SetConstructorFunction(target, "FSReqCallback", fst);
// Create FunctionTemplate for FileHandleReadWrap. There’s no need
// to do anything in the constructor, so we only store the instance template.
@@ -2508,14 +2502,8 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(fd, "releaseFD", FileHandle::ReleaseFD);
Local<ObjectTemplate> fdt = fd->InstanceTemplate();
fdt->SetInternalFieldCount(StreamBase::kInternalFieldCount);
- Local<String> handleString =
- FIXED_ONE_BYTE_STRING(isolate, "FileHandle");
- fd->SetClassName(handleString);
StreamBase::AddMethods(env, fd);
- target
- ->Set(context, handleString,
- fd->GetFunction(env->context()).ToLocalChecked())
- .Check();
+ env->SetConstructorFunction(target, "FileHandle", fd);
env->set_fd_constructor_template(fdt);
// Create FunctionTemplate for FileHandle::CloseReq
diff --git a/src/node_http2.cc b/src/node_http2.cc
index 1e2da918bf5..930167418e1 100644
--- a/src/node_http2.cc
+++ b/src/node_http2.cc
@@ -3054,9 +3054,6 @@ void Initialize(Local<Object> target,
env->SetMethod(target, "packSettings", PackSettings);
env->SetMethod(target, "setCallbackFunctions", SetCallbackFunctions);
- Local<String> http2SessionClassName =
- FIXED_ONE_BYTE_STRING(isolate, "Http2Session");
-
Local<FunctionTemplate> ping = FunctionTemplate::New(env->isolate());
ping->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Ping"));
ping->Inherit(AsyncWrap::GetConstructorTemplate(env));
@@ -3065,14 +3062,12 @@ void Initialize(Local<Object> target,
env->set_http2ping_constructor_template(pingt);
Local<FunctionTemplate> setting = FunctionTemplate::New(env->isolate());
- setting->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Setting"));
setting->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<ObjectTemplate> settingt = setting->InstanceTemplate();
settingt->SetInternalFieldCount(AsyncWrap::kInternalFieldCount);
env->set_http2settings_constructor_template(settingt);
Local<FunctionTemplate> stream = FunctionTemplate::New(env->isolate());
- stream->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Stream"));
env->SetProtoMethod(stream, "id", Http2Stream::GetID);
env->SetProtoMethod(stream, "destroy", Http2Stream::Destroy);
env->SetProtoMethod(stream, "priority", Http2Stream::Priority);
@@ -3087,13 +3082,10 @@ void Initialize(Local<Object> target,
Local<ObjectTemplate> streamt = stream->InstanceTemplate();
streamt->SetInternalFieldCount(StreamBase::kInternalFieldCount);
env->set_http2stream_constructor_template(streamt);
- target->Set(context,
- FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Stream"),
- stream->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Http2Stream", stream);
Local<FunctionTemplate> session =
env->NewFunctionTemplate(Http2Session::New);
- session->SetClassName(http2SessionClassName);
session->InstanceTemplate()->SetInternalFieldCount(
Http2Session::kInternalFieldCount);
session->Inherit(AsyncWrap::GetConstructorTemplate(env));
@@ -3119,9 +3111,7 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(
session, "remoteSettings",
Http2Session::RefreshSettings<nghttp2_session_get_remote_settings>);
- target->Set(context,
- http2SessionClassName,
- session->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Http2Session", session);
Local<Object> constants = Object::New(isolate);
diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc
index 706e6132db6..affc66585ed 100644
--- a/src/node_http_parser.cc
+++ b/src/node_http_parser.cc
@@ -956,7 +956,6 @@ void InitializeHttpParser(Local<Object> target,
Local<FunctionTemplate> t = env->NewFunctionTemplate(Parser::New);
t->InstanceTemplate()->SetInternalFieldCount(Parser::kInternalFieldCount);
- t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "HTTPParser"));
t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "REQUEST"),
Integer::New(env->isolate(), HTTP_REQUEST));
@@ -999,9 +998,7 @@ void InitializeHttpParser(Local<Object> target,
env->SetProtoMethod(t, "unconsume", Parser::Unconsume);
env->SetProtoMethod(t, "getCurrentBuffer", Parser::GetCurrentBuffer);
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "HTTPParser"),
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "HTTPParser", t);
}
} // anonymous namespace
diff --git a/src/node_messaging.cc b/src/node_messaging.cc
index 5f054c41c8e..78fb46ab6f2 100644
--- a/src/node_messaging.cc
+++ b/src/node_messaging.cc
@@ -1415,32 +1415,24 @@ static void InitMessaging(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
{
- Local<String> message_channel_string =
- FIXED_ONE_BYTE_STRING(env->isolate(), "MessageChannel");
- Local<FunctionTemplate> templ = env->NewFunctionTemplate(MessageChannel);
- templ->SetClassName(message_channel_string);
- target->Set(context,
- message_channel_string,
- templ->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(
+ target,
+ "MessageChannel",
+ env->NewFunctionTemplate(MessageChannel));
}
{
- Local<String> js_transferable_string =
- FIXED_ONE_BYTE_STRING(env->isolate(), "JSTransferable");
Local<FunctionTemplate> t = env->NewFunctionTemplate(JSTransferable::New);
t->Inherit(BaseObject::GetConstructorTemplate(env));
- t->SetClassName(js_transferable_string);
t->InstanceTemplate()->SetInternalFieldCount(
JSTransferable::kInternalFieldCount);
- target->Set(context,
- js_transferable_string,
- t->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "JSTransferable", t);
}
- target->Set(context,
- env->message_port_constructor_string(),
- GetMessagePortConstructorTemplate(env)
- ->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(
+ target,
+ env->message_port_constructor_string(),
+ GetMessagePortConstructorTemplate(env));
// These are not methods on the MessagePort prototype, because
// the browser equivalents do not provide them.
diff --git a/src/node_perf.cc b/src/node_perf.cc
index 1eddb00f48a..4d977d4ba61 100644
--- a/src/node_perf.cc
+++ b/src/node_perf.cc
@@ -705,8 +705,7 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(eldh, "enable", ELDHistogramEnable);
env->SetProtoMethod(eldh, "disable", ELDHistogramDisable);
env->SetProtoMethod(eldh, "reset", ELDHistogramReset);
- target->Set(context, eldh_classname,
- eldh->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, eldh_classname, eldh);
}
} // namespace performance
diff --git a/src/node_serdes.cc b/src/node_serdes.cc
index b51d315989c..879253f9bc2 100644
--- a/src/node_serdes.cc
+++ b/src/node_serdes.cc
@@ -475,13 +475,8 @@ void Initialize(Local<Object> target,
"_setTreatArrayBufferViewsAsHostObjects",
SerializerContext::SetTreatArrayBufferViewsAsHostObjects);
- Local<String> serializerString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "Serializer");
- ser->SetClassName(serializerString);
ser->ReadOnlyPrototype();
- target->Set(env->context(),
- serializerString,
- ser->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Serializer", ser);
Local<FunctionTemplate> des =
env->NewFunctionTemplate(DeserializerContext::New);
@@ -503,14 +498,9 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(des, "readDouble", DeserializerContext::ReadDouble);
env->SetProtoMethod(des, "_readRawBytes", DeserializerContext::ReadRawBytes);
- Local<String> deserializerString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "Deserializer");
des->SetLength(1);
des->ReadOnlyPrototype();
- des->SetClassName(deserializerString);
- target->Set(env->context(),
- deserializerString,
- des->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Deserializer", des);
}
} // anonymous namespace
diff --git a/src/node_sockaddr.cc b/src/node_sockaddr.cc
index 8d7c93255b0..3734453314a 100644
--- a/src/node_sockaddr.cc
+++ b/src/node_sockaddr.cc
@@ -18,7 +18,6 @@ using v8::FunctionTemplate;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
-using v8::String;
using v8::Value;
namespace {
@@ -675,11 +674,9 @@ void SocketAddressBlockListWrap::Initialize(
void* priv) {
Environment* env = Environment::GetCurrent(context);
- Local<String> name = FIXED_ONE_BYTE_STRING(env->isolate(), "BlockList");
Local<FunctionTemplate> t =
env->NewFunctionTemplate(SocketAddressBlockListWrap::New);
t->InstanceTemplate()->SetInternalFieldCount(BaseObject::kInternalFieldCount);
- t->SetClassName(name);
env->SetProtoMethod(t, "addAddress", SocketAddressBlockListWrap::AddAddress);
env->SetProtoMethod(t, "addRange", SocketAddressBlockListWrap::AddRange);
@@ -688,8 +685,7 @@ void SocketAddressBlockListWrap::Initialize(
env->SetProtoMethod(t, "getRules", SocketAddressBlockListWrap::GetRules);
env->set_blocklist_instance_template(t->InstanceTemplate());
- target->Set(env->context(), name,
- t->GetFunction(env->context()).ToLocalChecked()).FromJust();
+ env->SetConstructorFunction(target, "BlockList", t);
NODE_DEFINE_CONSTANT(target, AF_INET);
NODE_DEFINE_CONSTANT(target, AF_INET6);
diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc
index 70903525baa..344ea6bb7ea 100644
--- a/src/node_stat_watcher.cc
+++ b/src/node_stat_watcher.cc
@@ -38,7 +38,6 @@ using v8::HandleScope;
using v8::Integer;
using v8::Local;
using v8::Object;
-using v8::String;
using v8::Uint32;
using v8::Value;
@@ -49,15 +48,11 @@ void StatWatcher::Initialize(Environment* env, Local<Object> target) {
Local<FunctionTemplate> t = env->NewFunctionTemplate(StatWatcher::New);
t->InstanceTemplate()->SetInternalFieldCount(
StatWatcher::kInternalFieldCount);
- Local<String> statWatcherString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "StatWatcher");
- t->SetClassName(statWatcherString);
t->Inherit(HandleWrap::GetConstructorTemplate(env));
env->SetProtoMethod(t, "start", StatWatcher::Start);
- target->Set(env->context(), statWatcherString,
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "StatWatcher", t);
}
diff --git a/src/node_trace_events.cc b/src/node_trace_events.cc
index 9cefaa92270..af60aff4ab7 100644
--- a/src/node_trace_events.cc
+++ b/src/node_trace_events.cc
@@ -138,10 +138,7 @@ void NodeCategorySet::Initialize(Local<Object> target,
env->SetProtoMethod(category_set, "enable", NodeCategorySet::Enable);
env->SetProtoMethod(category_set, "disable", NodeCategorySet::Disable);
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "CategorySet"),
- category_set->GetFunction(env->context()).ToLocalChecked())
- .Check();
+ env->SetConstructorFunction(target, "CategorySet", category_set);
Local<String> isTraceCategoryEnabled =
FIXED_ONE_BYTE_STRING(env->isolate(), "isTraceCategoryEnabled");
diff --git a/src/node_util.cc b/src/node_util.cc
index 3eefa73739a..3f829081cb3 100644
--- a/src/node_util.cc
+++ b/src/node_util.cc
@@ -352,19 +352,15 @@ void Initialize(Local<Object> target,
env->should_abort_on_uncaught_toggle().GetJSArray())
.FromJust());
- Local<String> weak_ref_string =
- FIXED_ONE_BYTE_STRING(env->isolate(), "WeakReference");
Local<FunctionTemplate> weak_ref =
env->NewFunctionTemplate(WeakReference::New);
weak_ref->InstanceTemplate()->SetInternalFieldCount(
WeakReference::kInternalFieldCount);
- weak_ref->SetClassName(weak_ref_string);
weak_ref->Inherit(BaseObject::GetConstructorTemplate(env));
env->SetProtoMethod(weak_ref, "get", WeakReference::Get);
env->SetProtoMethod(weak_ref, "incRef", WeakReference::IncRef);
env->SetProtoMethod(weak_ref, "decRef", WeakReference::DecRef);
- target->Set(context, weak_ref_string,
- weak_ref->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "WeakReference", weak_ref);
env->SetMethod(target, "guessHandleType", GuessHandleType);
}
diff --git a/src/node_wasi.cc b/src/node_wasi.cc
index 4dd534af416..67d3966e201 100644
--- a/src/node_wasi.cc
+++ b/src/node_wasi.cc
@@ -1676,9 +1676,7 @@ static void Initialize(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
Local<FunctionTemplate> tmpl = env->NewFunctionTemplate(WASI::New);
- auto wasi_wrap_string = FIXED_ONE_BYTE_STRING(env->isolate(), "WASI");
tmpl->InstanceTemplate()->SetInternalFieldCount(WASI::kInternalFieldCount);
- tmpl->SetClassName(wasi_wrap_string);
tmpl->Inherit(BaseObject::GetConstructorTemplate(env));
env->SetProtoMethod(tmpl, "args_get", WASI::ArgsGet);
@@ -1731,9 +1729,7 @@ static void Initialize(Local<Object> target,
env->SetInstanceMethod(tmpl, "_setMemory", WASI::_SetMemory);
- target->Set(env->context(),
- wasi_wrap_string,
- tmpl->GetFunction(context).ToLocalChecked()).ToChecked();
+ env->SetConstructorFunction(target, "WASI", tmpl);
}
diff --git a/src/node_watchdog.cc b/src/node_watchdog.cc
index 8bd3b283b53..ff2a0229087 100644
--- a/src/node_watchdog.cc
+++ b/src/node_watchdog.cc
@@ -124,19 +124,12 @@ void TraceSigintWatchdog::Init(Environment* env, Local<Object> target) {
Local<FunctionTemplate> constructor = env->NewFunctionTemplate(New);
constructor->InstanceTemplate()->SetInternalFieldCount(
TraceSigintWatchdog::kInternalFieldCount);
- Local<v8::String> js_sigint_watch_dog =
- FIXED_ONE_BYTE_STRING(env->isolate(), "TraceSigintWatchdog");
- constructor->SetClassName(js_sigint_watch_dog);
constructor->Inherit(HandleWrap::GetConstructorTemplate(env));
env->SetProtoMethod(constructor, "start", Start);
env->SetProtoMethod(constructor, "stop", Stop);
- target
- ->Set(env->context(),
- js_sigint_watch_dog,
- constructor->GetFunction(env->context()).ToLocalChecked())
- .Check();
+ env->SetConstructorFunction(target, "TraceSigintWatchdog", constructor);
}
void TraceSigintWatchdog::New(const FunctionCallbackInfo<Value>& args) {
diff --git a/src/node_worker.cc b/src/node_worker.cc
index 7369e13768e..d163ec2461d 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -815,12 +815,7 @@ void InitWorker(Local<Object> target,
env->SetProtoMethod(w, "loopIdleTime", Worker::LoopIdleTime);
env->SetProtoMethod(w, "loopStartTime", Worker::LoopStartTime);
- Local<String> workerString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "Worker");
- w->SetClassName(workerString);
- target->Set(env->context(),
- workerString,
- w->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Worker", w);
}
{
diff --git a/src/node_zlib.cc b/src/node_zlib.cc
index efb11debf8f..2a2466052c9 100644
--- a/src/node_zlib.cc
+++ b/src/node_zlib.cc
@@ -54,7 +54,6 @@ using v8::Int32;
using v8::Integer;
using v8::Local;
using v8::Object;
-using v8::String;
using v8::Uint32Array;
using v8::Value;
@@ -1262,11 +1261,7 @@ struct MakeClass {
env->SetProtoMethod(z, "params", Stream::Params);
env->SetProtoMethod(z, "reset", Stream::Reset);
- Local<String> zlibString = OneByteString(env->isolate(), name);
- z->SetClassName(zlibString);
- target->Set(env->context(),
- zlibString,
- z->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, name, z);
}
};
diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc
index 1396395463d..7ec3c66a78b 100644
--- a/src/pipe_wrap.cc
+++ b/src/pipe_wrap.cc
@@ -43,7 +43,6 @@ using v8::Int32;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
-using v8::String;
using v8::Value;
MaybeLocal<Object> PipeWrap::Instantiate(Environment* env,
@@ -69,8 +68,6 @@ void PipeWrap::Initialize(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
- Local<String> pipeString = FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe");
- t->SetClassName(pipeString);
t->InstanceTemplate()
->SetInternalFieldCount(StreamBase::kInternalFieldCount);
@@ -87,20 +84,13 @@ void PipeWrap::Initialize(Local<Object> target,
env->SetProtoMethod(t, "fchmod", Fchmod);
- target->Set(env->context(),
- pipeString,
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Pipe", t);
env->set_pipe_constructor_template(t);
// Create FunctionTemplate for PipeConnectWrap.
auto cwt = BaseObject::MakeLazilyInitializedJSTemplate(env);
cwt->Inherit(AsyncWrap::GetConstructorTemplate(env));
- Local<String> wrapString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap");
- cwt->SetClassName(wrapString);
- target->Set(env->context(),
- wrapString,
- cwt->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "PipeConnectWrap", cwt);
// Define constants
Local<Object> constants = Object::New(env->isolate());
diff --git a/src/process_wrap.cc b/src/process_wrap.cc
index 3d1065c9922..7628a1264c5 100644
--- a/src/process_wrap.cc
+++ b/src/process_wrap.cc
@@ -54,18 +54,13 @@ class ProcessWrap : public HandleWrap {
Local<FunctionTemplate> constructor = env->NewFunctionTemplate(New);
constructor->InstanceTemplate()->SetInternalFieldCount(
ProcessWrap::kInternalFieldCount);
- Local<String> processString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "Process");
- constructor->SetClassName(processString);
constructor->Inherit(HandleWrap::GetConstructorTemplate(env));
env->SetProtoMethod(constructor, "spawn", Spawn);
env->SetProtoMethod(constructor, "kill", Kill);
- target->Set(env->context(),
- processString,
- constructor->GetFunction(context).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "Process", constructor);
}
SET_NO_MEMORY_INFO()
diff --git a/src/quic/node_quic_socket.cc b/src/quic/node_quic_socket.cc
index abbdd50e470..810705014ca 100644
--- a/src/quic/node_quic_socket.cc
+++ b/src/quic/node_quic_socket.cc
@@ -39,7 +39,6 @@ using v8::Number;
using v8::Object;
using v8::ObjectTemplate;
using v8::PropertyAttribute;
-using v8::String;
using v8::Value;
namespace quic {
@@ -1154,10 +1153,8 @@ void QuicEndpoint::Initialize(
Local<Object> target,
Local<Context> context) {
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(
QuicEndpoint::kInternalFieldCount);
env->SetProtoMethod(endpoint,
@@ -1165,11 +1162,7 @@ void QuicEndpoint::Initialize(
QuicEndpointWaitForPendingCallbacks);
endpoint->InstanceTemplate()->Set(env->owner_symbol(), Null(isolate));
- target->Set(
- context,
- class_name,
- endpoint->GetFunction(context).ToLocalChecked())
- .FromJust();
+ env->SetConstructorFunction(target, "QuicEndpoint", endpoint);
}
void QuicSocket::Initialize(
@@ -1177,10 +1170,8 @@ void QuicSocket::Initialize(
Local<Object> target,
Local<Context> context) {
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(
QuicSocket::kInternalFieldCount);
socket->InstanceTemplate()->Set(env->owner_symbol(), Null(isolate));
@@ -1197,8 +1188,7 @@ void QuicSocket::Initialize(
"setDiagnosticPacketLoss",
QuicSocketSetDiagnosticPacketLoss);
socket->Inherit(HandleWrap::GetConstructorTemplate(env));
- target->Set(context, class_name,
- socket->GetFunction(env->context()).ToLocalChecked()).FromJust();
+ env->SetConstructorFunction(target, "QuicSocket", socket);
Local<FunctionTemplate> sendwrap_ctor = FunctionTemplate::New(isolate);
sendwrap_ctor->Inherit(AsyncWrap::GetConstructorTemplate(env));
diff --git a/src/quic/node_quic_stream.cc b/src/quic/node_quic_stream.cc
index d63e66988ac..57976ae50d9 100644
--- a/src/quic/node_quic_stream.cc
+++ b/src/quic/node_quic_stream.cc
@@ -26,12 +26,10 @@ using v8::Array;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
-using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::ObjectTemplate;
using v8::PropertyAttribute;
-using v8::String;
using v8::Value;
namespace quic {
@@ -525,10 +523,7 @@ void QuicStream::Initialize(
Environment* env,
Local<Object> target,
Local<Context> context) {
- Isolate* isolate = env->isolate();
- Local<String> class_name = FIXED_ONE_BYTE_STRING(isolate, "QuicStream");
Local<FunctionTemplate> stream = FunctionTemplate::New(env->isolate());
- stream->SetClassName(class_name);
stream->Inherit(AsyncWrap::GetConstructorTemplate(env));
StreamBase::AddMethods(env, stream);
Local<ObjectTemplate> streamt = stream->InstanceTemplate();
@@ -543,9 +538,7 @@ void QuicStream::Initialize(
env->SetProtoMethod(stream, "submitTrailers", QuicStreamSubmitTrailers);
env->SetProtoMethod(stream, "submitPush", QuicStreamSubmitPush);
env->set_quicserverstream_instance_template(streamt);
- target->Set(env->context(),
- class_name,
- stream->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "QuicStream", stream);
env->SetMethod(target, "openBidirectionalStream", OpenBidirectionalStream);
env->SetMethod(target, "openUnidirectionalStream", OpenUnidirectionalStream);
diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc
index 2be7ac98341..49ea849f637 100644
--- a/src/signal_wrap.cc
+++ b/src/signal_wrap.cc
@@ -35,7 +35,6 @@ using v8::HandleScope;
using v8::Integer;
using v8::Local;
using v8::Object;
-using v8::String;
using v8::Value;
void DecreaseSignalHandlerCount(int signum);
@@ -55,17 +54,12 @@ class SignalWrap : public HandleWrap {
Local<FunctionTemplate> constructor = env->NewFunctionTemplate(New);
constructor->InstanceTemplate()->SetInternalFieldCount(
SignalWrap::kInternalFieldCount);
- Local<String> signalString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "Signal");
- constructor->SetClassName(signalString);
constructor->Inherit(HandleWrap::GetConstructorTemplate(env));
env->SetProtoMethod(constructor, "start", Start);
env->SetProtoMethod(constructor, "stop", Stop);
- target->Set(env->context(), signalString,
- constructor->GetFunction(env->context()).ToLocalChecked())
- .Check();
+ env->SetConstructorFunction(target, "Signal", constructor);
}
SET_NO_MEMORY_INFO()
diff --git a/src/stream_pipe.cc b/src/stream_pipe.cc
index 1422f9e0ea5..afd7ec36eef 100644
--- a/src/stream_pipe.cc
+++ b/src/stream_pipe.cc
@@ -13,7 +13,6 @@ using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Local;
using v8::Object;
-using v8::String;
using v8::Value;
StreamPipe::StreamPipe(StreamBase* source,
@@ -293,20 +292,14 @@ void InitializeStreamPipe(Local<Object> target,
// Create FunctionTemplate for FileHandle::CloseReq
Local<FunctionTemplate> pipe = env->NewFunctionTemplate(StreamPipe::New);
- Local<String> stream_pipe_string =
- FIXED_ONE_BYTE_STRING(env->isolate(), "StreamPipe");
env->SetProtoMethod(pipe, "unpipe", StreamPipe::Unpipe);
env->SetProtoMethod(pipe, "start", StreamPipe::Start);
env->SetProtoMethod(pipe, "isClosed", StreamPipe::IsClosed);
env->SetProtoMethod(pipe, "pendingWrites", StreamPipe::PendingWrites);
pipe->Inherit(AsyncWrap::GetConstructorTemplate(env));
- pipe->SetClassName(stream_pipe_string);
pipe->InstanceTemplate()->SetInternalFieldCount(
StreamPipe::kInternalFieldCount);
- target
- ->Set(context, stream_pipe_string,
- pipe->GetFunction(context).ToLocalChecked())
- .Check();
+ env->SetConstructorFunction(target, "StreamPipe", pipe);
}
} // anonymous namespace
diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc
index bd396110fcc..a1fa5e94b73 100644
--- a/src/stream_wrap.cc
+++ b/src/stream_wrap.cc
@@ -49,7 +49,6 @@ using v8::Object;
using v8::PropertyAttribute;
using v8::ReadOnly;
using v8::Signature;
-using v8::String;
using v8::Value;
@@ -67,9 +66,6 @@ void LibuvStreamWrap::Initialize(Local<Object> target,
Local<FunctionTemplate> sw =
FunctionTemplate::New(env->isolate(), is_construct_call_callback);
sw->InstanceTemplate()->SetInternalFieldCount(StreamReq::kInternalFieldCount);
- Local<String> wrapString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "ShutdownWrap");
- sw->SetClassName(wrapString);
// we need to set handle and callback to null,
// so that those fields are created and functions
@@ -88,22 +84,15 @@ void LibuvStreamWrap::Initialize(Local<Object> target,
sw->Inherit(AsyncWrap::GetConstructorTemplate(env));
- target->Set(env->context(),
- wrapString,
- sw->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "ShutdownWrap", sw);
env->set_shutdown_wrap_template(sw->InstanceTemplate());
Local<FunctionTemplate> ww =
FunctionTemplate::New(env->isolate(), is_construct_call_callback);
ww->InstanceTemplate()->SetInternalFieldCount(
StreamReq::kInternalFieldCount);
- Local<String> writeWrapString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "WriteWrap");
- ww->SetClassName(writeWrapString);
ww->Inherit(AsyncWrap::GetConstructorTemplate(env));
- target->Set(env->context(),
- writeWrapString,
- ww->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "WriteWrap", ww);
env->set_write_wrap_template(ww->InstanceTemplate());
NODE_DEFINE_CONSTANT(target, kReadBytesOrError);
diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc
index fa45bd118d4..cd7174984e2 100644
--- a/src/tcp_wrap.cc
+++ b/src/tcp_wrap.cc
@@ -74,8 +74,6 @@ void TCPWrap::Initialize(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
- Local<String> tcpString = FIXED_ONE_BYTE_STRING(env->isolate(), "TCP");
- t->SetClassName(tcpString);
t->InstanceTemplate()->SetInternalFieldCount(StreamBase::kInternalFieldCount);
// Init properties
@@ -103,21 +101,14 @@ void TCPWrap::Initialize(Local<Object> target,
env->SetProtoMethod(t, "setSimultaneousAccepts", SetSimultaneousAccepts);
#endif
- target->Set(env->context(),
- tcpString,
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "TCP", t);
env->set_tcp_constructor_template(t);
// Create FunctionTemplate for TCPConnectWrap.
Local<FunctionTemplate> cwt =
BaseObject::MakeLazilyInitializedJSTemplate(env);
cwt->Inherit(AsyncWrap::GetConstructorTemplate(env));
- Local<String> wrapString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "TCPConnectWrap");
- cwt->SetClassName(wrapString);
- target->Set(env->context(),
- wrapString,
- cwt->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "TCPConnectWrap", cwt);
// Define constants
Local<Object> constants = Object::New(env->isolate());
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc
index 26bafebcb22..e746f62c5ed 100644
--- a/src/udp_wrap.cc
+++ b/src/udp_wrap.cc
@@ -43,7 +43,6 @@ using v8::Object;
using v8::PropertyAttribute;
using v8::ReadOnly;
using v8::Signature;
-using v8::String;
using v8::Uint32;
using v8::Undefined;
using v8::Value;
@@ -134,9 +133,6 @@ void UDPWrap::Initialize(Local<Object> target,
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
t->InstanceTemplate()->SetInternalFieldCount(
UDPWrapBase::kInternalFieldCount);
- Local<String> udpString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "UDP");
- t->SetClassName(udpString);
enum PropertyAttribute attributes =
static_cast<PropertyAttribute>(ReadOnly | DontDelete);
@@ -182,9 +178,7 @@ void UDPWrap::Initialize(Local<Object> target,
t->Inherit(HandleWrap::GetConstructorTemplate(env));
- target->Set(env->context(),
- udpString,
- t->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "UDP", t);
env->set_udp_constructor_function(
t->GetFunction(env->context()).ToLocalChecked());
@@ -192,12 +186,7 @@ void UDPWrap::Initialize(Local<Object> target,
Local<FunctionTemplate> swt =
BaseObject::MakeLazilyInitializedJSTemplate(env);
swt->Inherit(AsyncWrap::GetConstructorTemplate(env));
- Local<String> sendWrapString =
- FIXED_ONE_BYTE_STRING(env->isolate(), "SendWrap");
- swt->SetClassName(sendWrapString);
- target->Set(env->context(),
- sendWrapString,
- swt->GetFunction(env->context()).ToLocalChecked()).Check();
+ env->SetConstructorFunction(target, "SendWrap", swt);
Local<Object> constants = Object::New(env->isolate());
NODE_DEFINE_CONSTANT(constants, UV_UDP_IPV6ONLY);
diff --git a/src/uv.cc b/src/uv.cc
index bf50c88111f..e4b428f339b 100644
--- a/src/uv.cc
+++ b/src/uv.cc
@@ -106,11 +106,10 @@ void Initialize(Local<Object> target,
void* priv) {
Environment* env = Environment::GetCurrent(context);
Isolate* isolate = env->isolate();
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(isolate, "errname"),
- env->NewFunctionTemplate(ErrName)
- ->GetFunction(env->context())
- .ToLocalChecked()).Check();
+ env->SetConstructorFunction(
+ target,
+ "errname",
+ env->NewFunctionTemplate(ErrName));
// TODO(joyeecheung): This should be deprecated in user land in favor of
// `util.getSystemErrorName(err)`.