From 771a03dfe3dba6ac3136bd4aa25525220e29b0ff Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 18 Aug 2017 21:58:25 -0700 Subject: src: fixup strings, reduce duplication PR-URL: https://github.com/nodejs/node/pull/14937 Reviewed-By: Anna Henningsen --- src/cares_wrap.cc | 32 ++++++++++++++++---------------- src/js_stream.cc | 8 +++++--- src/node_config.cc | 2 +- src/node_crypto.cc | 7 ++++--- src/node_file.cc | 7 ++++--- src/node_http2.cc | 3 +-- src/node_serdes.cc | 12 ++++++++---- src/node_stat_watcher.cc | 8 +++++--- src/node_zlib.cc | 6 ++++-- src/pipe_wrap.cc | 13 ++++++++----- src/process_wrap.cc | 7 ++++--- src/signal_wrap.cc | 8 +++++--- src/stream_wrap.cc | 14 ++++++++------ src/tcp_wrap.cc | 14 ++++++++------ src/timer_wrap.cc | 7 ++++--- src/tls_wrap.cc | 9 ++++++--- src/tty_wrap.cc | 7 +++++-- src/udp_wrap.cc | 13 ++++++++----- 18 files changed, 104 insertions(+), 73 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index f43eb7ed8b..b66a3e5262 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -2190,28 +2190,28 @@ void Initialize(Local target, FunctionTemplate::New(env->isolate(), is_construct_call_callback); aiw->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(aiw, "getAsyncId", AsyncWrap::GetAsyncId); - aiw->SetClassName( - FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap")); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap"), - aiw->GetFunction()); + Local addrInfoWrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap"); + aiw->SetClassName(addrInfoWrapString); + target->Set(addrInfoWrapString, aiw->GetFunction()); Local niw = FunctionTemplate::New(env->isolate(), is_construct_call_callback); niw->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(niw, "getAsyncId", AsyncWrap::GetAsyncId); - niw->SetClassName( - FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap")); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap"), - niw->GetFunction()); + Local nameInfoWrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap"); + niw->SetClassName(nameInfoWrapString); + target->Set(nameInfoWrapString, niw->GetFunction()); Local qrw = FunctionTemplate::New(env->isolate(), is_construct_call_callback); qrw->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(qrw, "getAsyncId", AsyncWrap::GetAsyncId); - qrw->SetClassName( - FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap")); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap"), - qrw->GetFunction()); + Local queryWrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap"); + qrw->SetClassName(queryWrapString); + target->Set(queryWrapString, qrw->GetFunction()); Local channel_wrap = env->NewFunctionTemplate(ChannelWrap::New); @@ -2235,10 +2235,10 @@ void Initialize(Local target, env->SetProtoMethod(channel_wrap, "setServers", SetServers); env->SetProtoMethod(channel_wrap, "cancel", Cancel); - channel_wrap->SetClassName( - FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap")); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"), - channel_wrap->GetFunction()); + Local channelWrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"); + channel_wrap->SetClassName(channelWrapString); + target->Set(channelWrapString, channel_wrap->GetFunction()); } } // anonymous namespace diff --git a/src/js_stream.cc b/src/js_stream.cc index d88cc853c8..caef92f1ca 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -18,6 +18,7 @@ using v8::HandleScope; using v8::Local; using v8::MaybeLocal; using v8::Object; +using v8::String; using v8::Value; @@ -212,7 +213,9 @@ void JSStream::Initialize(Local target, Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(New); - t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream")); + Local jsStreamString = + FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream"); + t->SetClassName(jsStreamString); t->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId); @@ -226,8 +229,7 @@ void JSStream::Initialize(Local target, env->SetProtoMethod(t, "emitEOF", EmitEOF); StreamBase::AddMethods(env, t, StreamBase::kFlagHasWritev); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream"), - t->GetFunction()); + target->Set(jsStreamString, t->GetFunction()); env->set_jsstream_constructor_template(t); } diff --git a/src/node_config.cc b/src/node_config.cc index a2d980d793..87110dd8c6 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -105,7 +105,7 @@ static void InitConfig(Local target, debugOptions->DefineOwnProperty( context, - FIXED_ONE_BYTE_STRING(isolate, "port"), + env->port_string(), Integer::New(isolate, debug_options.port()), ReadOnly).FromJust(); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index fa7b3c8ec3..f756251190 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -312,7 +312,9 @@ bool EntropySource(unsigned char* buffer, size_t length) { void SecureContext::Initialize(Environment* env, Local target) { Local t = env->NewFunctionTemplate(SecureContext::New); t->InstanceTemplate()->SetInternalFieldCount(1); - t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext")); + Local secureContextString = + FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext"); + t->SetClassName(secureContextString); env->SetProtoMethod(t, "init", SecureContext::Init); env->SetProtoMethod(t, "setKey", SecureContext::SetKey); @@ -359,8 +361,7 @@ void SecureContext::Initialize(Environment* env, Local target) { static_cast(ReadOnly | DontDelete), AccessorSignature::New(env->isolate(), t)); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext"), - t->GetFunction()); + target->Set(secureContextString, t->GetFunction()); env->set_secure_context_constructor_template(t); } diff --git a/src/node_file.cc b/src/node_file.cc index 9e0553a7a5..407e692f99 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1484,9 +1484,10 @@ void InitFs(Local target, FunctionTemplate::New(env->isolate(), NewFSReqWrap); fst->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(fst, "getAsyncId", AsyncWrap::GetAsyncId); - fst->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "FSReqWrap")); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "FSReqWrap"), - fst->GetFunction()); + Local wrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "FSReqWrap"); + fst->SetClassName(wrapString); + target->Set(wrapString, fst->GetFunction()); } } // end namespace node diff --git a/src/node_http2.cc b/src/node_http2.cc index 9308e9e68e..70dcc5e00d 100755 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1206,8 +1206,7 @@ void Initialize(Local target, env->SetMethod(target, "nghttp2ErrorString", HttpErrorString); Local http2SessionClassName = - String::NewFromUtf8(isolate, "Http2Session", - v8::NewStringType::kInternalized).ToLocalChecked(); + FIXED_ONE_BYTE_STRING(isolate, "Http2Session"); Local session = env->NewFunctionTemplate(Http2Session::New); diff --git a/src/node_serdes.cc b/src/node_serdes.cc index a077598dfe..ced9e4dd98 100644 --- a/src/node_serdes.cc +++ b/src/node_serdes.cc @@ -451,9 +451,11 @@ void InitializeSerdesBindings(Local target, "_setTreatArrayBufferViewsAsHostObjects", SerializerContext::SetTreatArrayBufferViewsAsHostObjects); - ser->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Serializer")); + Local serializerString = + FIXED_ONE_BYTE_STRING(env->isolate(), "Serializer"); + ser->SetClassName(serializerString); target->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "Serializer"), + serializerString, ser->GetFunction(env->context()).ToLocalChecked()).FromJust(); Local des = @@ -474,9 +476,11 @@ void InitializeSerdesBindings(Local target, env->SetProtoMethod(des, "readDouble", DeserializerContext::ReadDouble); env->SetProtoMethod(des, "_readRawBytes", DeserializerContext::ReadRawBytes); - des->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Deserializer")); + Local deserializerString = + FIXED_ONE_BYTE_STRING(env->isolate(), "Deserializer"); + des->SetClassName(deserializerString); target->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "Deserializer"), + deserializerString, des->GetFunction(env->context()).ToLocalChecked()).FromJust(); } diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index 18bf2c5419..3f9354efce 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -39,6 +39,7 @@ using v8::HandleScope; using v8::Integer; using v8::Local; using v8::Object; +using v8::String; using v8::Value; @@ -47,14 +48,15 @@ void StatWatcher::Initialize(Environment* env, Local target) { Local t = env->NewFunctionTemplate(StatWatcher::New); t->InstanceTemplate()->SetInternalFieldCount(1); - t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "StatWatcher")); + Local statWatcherString = + FIXED_ONE_BYTE_STRING(env->isolate(), "StatWatcher"); + t->SetClassName(statWatcherString); env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId); env->SetProtoMethod(t, "start", StatWatcher::Start); env->SetProtoMethod(t, "stop", StatWatcher::Stop); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "StatWatcher"), - t->GetFunction()); + target->Set(statWatcherString, t->GetFunction()); } diff --git a/src/node_zlib.cc b/src/node_zlib.cc index b66313f179..c29785e37e 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -50,6 +50,7 @@ using v8::Local; using v8::Number; using v8::Object; using v8::Persistent; +using v8::String; using v8::Uint32Array; using v8::Value; @@ -693,8 +694,9 @@ void InitZlib(Local target, env->SetProtoMethod(z, "params", ZCtx::Params); env->SetProtoMethod(z, "reset", ZCtx::Reset); - z->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib")); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib"), z->GetFunction()); + Local zlibString = FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib"); + z->SetClassName(zlibString); + target->Set(zlibString, z->GetFunction()); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ZLIB_VERSION"), FIXED_ONE_BYTE_STRING(env->isolate(), ZLIB_VERSION)); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 2185580b06..0daec0b144 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -44,6 +44,7 @@ using v8::FunctionTemplate; using v8::HandleScope; using v8::Local; using v8::Object; +using v8::String; using v8::Value; using AsyncHooks = Environment::AsyncHooks; @@ -67,7 +68,8 @@ void PipeWrap::Initialize(Local target, Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(New); - t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe")); + Local pipeString = FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe"); + t->SetClassName(pipeString); t->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId); @@ -92,7 +94,7 @@ void PipeWrap::Initialize(Local target, env->SetProtoMethod(t, "setPendingInstances", SetPendingInstances); #endif - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe"), t->GetFunction()); + target->Set(pipeString, t->GetFunction()); env->set_pipe_constructor_template(t); // Create FunctionTemplate for PipeConnectWrap. @@ -103,9 +105,10 @@ void PipeWrap::Initialize(Local target, auto cwt = FunctionTemplate::New(env->isolate(), constructor); cwt->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(cwt, "getAsyncId", AsyncWrap::GetAsyncId); - cwt->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap")); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap"), - cwt->GetFunction()); + Local wrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap"); + cwt->SetClassName(wrapString); + target->Set(wrapString, cwt->GetFunction()); } diff --git a/src/process_wrap.cc b/src/process_wrap.cc index cae0788927..26e233b2bd 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -53,7 +53,9 @@ class ProcessWrap : public HandleWrap { Environment* env = Environment::GetCurrent(context); Local constructor = env->NewFunctionTemplate(New); constructor->InstanceTemplate()->SetInternalFieldCount(1); - constructor->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Process")); + Local processString = + FIXED_ONE_BYTE_STRING(env->isolate(), "Process"); + constructor->SetClassName(processString); env->SetProtoMethod(constructor, "getAsyncId", AsyncWrap::GetAsyncId); @@ -66,8 +68,7 @@ class ProcessWrap : public HandleWrap { env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); env->SetProtoMethod(constructor, "hasRef", HandleWrap::HasRef); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Process"), - constructor->GetFunction()); + target->Set(processString, constructor->GetFunction()); } size_t self_size() const override { return sizeof(*this); } diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index 1af98a9311..eed010b388 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -37,6 +37,7 @@ using v8::HandleScope; using v8::Integer; using v8::Local; using v8::Object; +using v8::String; using v8::Value; namespace { @@ -49,7 +50,9 @@ class SignalWrap : public HandleWrap { Environment* env = Environment::GetCurrent(context); Local constructor = env->NewFunctionTemplate(New); constructor->InstanceTemplate()->SetInternalFieldCount(1); - constructor->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Signal")); + Local signalString = + FIXED_ONE_BYTE_STRING(env->isolate(), "Signal"); + constructor->SetClassName(signalString); env->SetProtoMethod(constructor, "getAsyncId", AsyncWrap::GetAsyncId); env->SetProtoMethod(constructor, "close", HandleWrap::Close); @@ -59,8 +62,7 @@ class SignalWrap : public HandleWrap { env->SetProtoMethod(constructor, "start", Start); env->SetProtoMethod(constructor, "stop", Stop); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Signal"), - constructor->GetFunction()); + target->Set(signalString, constructor->GetFunction()); } size_t self_size() const override { return sizeof(*this); } diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index eb156a91a2..57c93ac489 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -67,18 +67,20 @@ void StreamWrap::Initialize(Local target, Local sw = FunctionTemplate::New(env->isolate(), is_construct_call_callback); sw->InstanceTemplate()->SetInternalFieldCount(1); - sw->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "ShutdownWrap")); + Local wrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "ShutdownWrap"); + sw->SetClassName(wrapString); env->SetProtoMethod(sw, "getAsyncId", AsyncWrap::GetAsyncId); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ShutdownWrap"), - sw->GetFunction()); + target->Set(wrapString, sw->GetFunction()); Local ww = FunctionTemplate::New(env->isolate(), is_construct_call_callback); ww->InstanceTemplate()->SetInternalFieldCount(1); - ww->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "WriteWrap")); + Local writeWrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "WriteWrap"); + ww->SetClassName(writeWrapString); env->SetProtoMethod(ww, "getAsyncId", AsyncWrap::GetAsyncId); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "WriteWrap"), - ww->GetFunction()); + target->Set(writeWrapString, ww->GetFunction()); env->set_write_wrap_constructor_function(ww->GetFunction()); } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 4bee4b9709..e721108cae 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -71,11 +71,12 @@ void TCPWrap::Initialize(Local target, Environment* env = Environment::GetCurrent(context); Local t = env->NewFunctionTemplate(New); - t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TCP")); + Local tcpString = FIXED_ONE_BYTE_STRING(env->isolate(), "TCP"); + t->SetClassName(tcpString); t->InstanceTemplate()->SetInternalFieldCount(1); // Init properties - t->InstanceTemplate()->Set(String::NewFromUtf8(env->isolate(), "reading"), + t->InstanceTemplate()->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "reading"), Boolean::New(env->isolate(), false)); t->InstanceTemplate()->Set(env->owner_string(), Null(env->isolate())); t->InstanceTemplate()->Set(env->onread_string(), Null(env->isolate())); @@ -109,7 +110,7 @@ void TCPWrap::Initialize(Local target, env->SetProtoMethod(t, "setSimultaneousAccepts", SetSimultaneousAccepts); #endif - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "TCP"), t->GetFunction()); + target->Set(tcpString, t->GetFunction()); env->set_tcp_constructor_template(t); // Create FunctionTemplate for TCPConnectWrap. @@ -120,9 +121,10 @@ void TCPWrap::Initialize(Local target, auto cwt = FunctionTemplate::New(env->isolate(), constructor); cwt->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(cwt, "getAsyncId", AsyncWrap::GetAsyncId); - cwt->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TCPConnectWrap")); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "TCPConnectWrap"), - cwt->GetFunction()); + Local wrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "TCPConnectWrap"); + cwt->SetClassName(wrapString); + target->Set(wrapString, cwt->GetFunction()); } diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 609d087e33..03e7ad3262 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -39,6 +39,7 @@ using v8::HandleScope; using v8::Integer; using v8::Local; using v8::Object; +using v8::String; using v8::Value; const uint32_t kOnTimeout = 0; @@ -50,8 +51,9 @@ class TimerWrap : public HandleWrap { Local context) { Environment* env = Environment::GetCurrent(context); Local constructor = env->NewFunctionTemplate(New); + Local timerString = FIXED_ONE_BYTE_STRING(env->isolate(), "Timer"); constructor->InstanceTemplate()->SetInternalFieldCount(1); - constructor->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Timer")); + constructor->SetClassName(timerString); constructor->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnTimeout"), Integer::New(env->isolate(), kOnTimeout)); @@ -67,8 +69,7 @@ class TimerWrap : public HandleWrap { env->SetProtoMethod(constructor, "start", Start); env->SetProtoMethod(constructor, "stop", Stop); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Timer"), - constructor->GetFunction()); + target->Set(timerString, constructor->GetFunction()); } size_t self_size() const override { return sizeof(*this); } diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index f03dbd7fd6..4e9eb19930 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -938,9 +938,13 @@ void TLSWrap::Initialize(Local target, CHECK(args.IsConstructCall()); args.This()->SetAlignedPointerInInternalField(0, nullptr); }; + + Local tlsWrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap"); + auto t = env->NewFunctionTemplate(constructor); t->InstanceTemplate()->SetInternalFieldCount(1); - t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap")); + t->SetClassName(tlsWrapString); env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId); env->SetProtoMethod(t, "asyncReset", AsyncWrap::AsyncReset); @@ -962,8 +966,7 @@ void TLSWrap::Initialize(Local target, env->set_tls_wrap_constructor_template(t); env->set_tls_wrap_constructor_function(t->GetFunction()); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap"), - t->GetFunction()); + target->Set(tlsWrapString, t->GetFunction()); } } // namespace node diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index f3f1edfe5d..88e9a98264 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -41,6 +41,7 @@ using v8::FunctionTemplate; using v8::Integer; using v8::Local; using v8::Object; +using v8::String; using v8::Value; @@ -49,8 +50,10 @@ void TTYWrap::Initialize(Local target, Local context) { Environment* env = Environment::GetCurrent(context); + Local ttyString = FIXED_ONE_BYTE_STRING(env->isolate(), "TTY"); + Local t = env->NewFunctionTemplate(New); - t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TTY")); + t->SetClassName(ttyString); t->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId); @@ -68,7 +71,7 @@ void TTYWrap::Initialize(Local target, env->SetMethod(target, "isTTY", IsTTY); env->SetMethod(target, "guessHandleType", GuessHandleType); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "TTY"), t->GetFunction()); + target->Set(ttyString, t->GetFunction()); env->set_tty_constructor_template(t); } diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index c192de6d62..702a5263c8 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -106,7 +106,9 @@ void UDPWrap::Initialize(Local target, Local t = env->NewFunctionTemplate(New); t->InstanceTemplate()->SetInternalFieldCount(1); - t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP")); + Local udpString = + FIXED_ONE_BYTE_STRING(env->isolate(), "UDP"); + t->SetClassName(udpString); enum PropertyAttribute attributes = static_cast(v8::ReadOnly | v8::DontDelete); @@ -139,7 +141,7 @@ void UDPWrap::Initialize(Local target, env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP"), t->GetFunction()); + target->Set(udpString, t->GetFunction()); env->set_udp_constructor_function(t->GetFunction()); // Create FunctionTemplate for SendWrap @@ -147,9 +149,10 @@ void UDPWrap::Initialize(Local target, FunctionTemplate::New(env->isolate(), NewSendWrap); swt->InstanceTemplate()->SetInternalFieldCount(1); env->SetProtoMethod(swt, "getAsyncId", AsyncWrap::GetAsyncId); - swt->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "SendWrap")); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "SendWrap"), - swt->GetFunction()); + Local sendWrapString = + FIXED_ONE_BYTE_STRING(env->isolate(), "SendWrap"); + swt->SetClassName(sendWrapString); + target->Set(sendWrapString, swt->GetFunction()); } -- cgit v1.2.3