Skip to content

Commit 5a05dfe

Browse files
jasnellMylesBorins
authored andcommitted
src: fixup strings, reduce duplication
PR-URL: #14937 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 1c3cb49 commit 5a05dfe

18 files changed

+104
-73
lines changed

src/cares_wrap.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,28 +2167,28 @@ void Initialize(Local<Object> target,
21672167
FunctionTemplate::New(env->isolate(), is_construct_call_callback);
21682168
aiw->InstanceTemplate()->SetInternalFieldCount(1);
21692169
env->SetProtoMethod(aiw, "getAsyncId", AsyncWrap::GetAsyncId);
2170-
aiw->SetClassName(
2171-
FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap"));
2172-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap"),
2173-
aiw->GetFunction());
2170+
Local<String> addrInfoWrapString =
2171+
FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap");
2172+
aiw->SetClassName(addrInfoWrapString);
2173+
target->Set(addrInfoWrapString, aiw->GetFunction());
21742174

21752175
Local<FunctionTemplate> niw =
21762176
FunctionTemplate::New(env->isolate(), is_construct_call_callback);
21772177
niw->InstanceTemplate()->SetInternalFieldCount(1);
21782178
env->SetProtoMethod(niw, "getAsyncId", AsyncWrap::GetAsyncId);
2179-
niw->SetClassName(
2180-
FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap"));
2181-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap"),
2182-
niw->GetFunction());
2179+
Local<String> nameInfoWrapString =
2180+
FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap");
2181+
niw->SetClassName(nameInfoWrapString);
2182+
target->Set(nameInfoWrapString, niw->GetFunction());
21832183

21842184
Local<FunctionTemplate> qrw =
21852185
FunctionTemplate::New(env->isolate(), is_construct_call_callback);
21862186
qrw->InstanceTemplate()->SetInternalFieldCount(1);
21872187
env->SetProtoMethod(qrw, "getAsyncId", AsyncWrap::GetAsyncId);
2188-
qrw->SetClassName(
2189-
FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap"));
2190-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap"),
2191-
qrw->GetFunction());
2188+
Local<String> queryWrapString =
2189+
FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap");
2190+
qrw->SetClassName(queryWrapString);
2191+
target->Set(queryWrapString, qrw->GetFunction());
21922192

21932193
Local<FunctionTemplate> channel_wrap =
21942194
env->NewFunctionTemplate(ChannelWrap::New);
@@ -2212,10 +2212,10 @@ void Initialize(Local<Object> target,
22122212
env->SetProtoMethod(channel_wrap, "setServers", SetServers);
22132213
env->SetProtoMethod(channel_wrap, "cancel", Cancel);
22142214

2215-
channel_wrap->SetClassName(
2216-
FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"));
2217-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"),
2218-
channel_wrap->GetFunction());
2215+
Local<String> channelWrapString =
2216+
FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
2217+
channel_wrap->SetClassName(channelWrapString);
2218+
target->Set(channelWrapString, channel_wrap->GetFunction());
22192219
}
22202220

22212221
} // anonymous namespace

src/js_stream.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ using v8::HandleScope;
1818
using v8::Local;
1919
using v8::MaybeLocal;
2020
using v8::Object;
21+
using v8::String;
2122
using v8::Value;
2223

2324

@@ -212,7 +213,9 @@ void JSStream::Initialize(Local<Object> target,
212213
Environment* env = Environment::GetCurrent(context);
213214

214215
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
215-
t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream"));
216+
Local<String> jsStreamString =
217+
FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream");
218+
t->SetClassName(jsStreamString);
216219
t->InstanceTemplate()->SetInternalFieldCount(1);
217220

218221
env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId);
@@ -226,8 +229,7 @@ void JSStream::Initialize(Local<Object> target,
226229
env->SetProtoMethod(t, "emitEOF", EmitEOF);
227230

228231
StreamBase::AddMethods<JSStream>(env, t, StreamBase::kFlagHasWritev);
229-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream"),
230-
t->GetFunction());
232+
target->Set(jsStreamString, t->GetFunction());
231233
env->set_jsstream_constructor_template(t);
232234
}
233235

src/node_config.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static void InitConfig(Local<Object> target,
105105

106106
debugOptions->DefineOwnProperty(
107107
context,
108-
FIXED_ONE_BYTE_STRING(isolate, "port"),
108+
env->port_string(),
109109
Integer::New(isolate, debug_options.port()),
110110
ReadOnly).FromJust();
111111

src/node_crypto.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ bool EntropySource(unsigned char* buffer, size_t length) {
312312
void SecureContext::Initialize(Environment* env, Local<Object> target) {
313313
Local<FunctionTemplate> t = env->NewFunctionTemplate(SecureContext::New);
314314
t->InstanceTemplate()->SetInternalFieldCount(1);
315-
t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext"));
315+
Local<String> secureContextString =
316+
FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext");
317+
t->SetClassName(secureContextString);
316318

317319
env->SetProtoMethod(t, "init", SecureContext::Init);
318320
env->SetProtoMethod(t, "setKey", SecureContext::SetKey);
@@ -359,8 +361,7 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
359361
static_cast<PropertyAttribute>(ReadOnly | DontDelete),
360362
AccessorSignature::New(env->isolate(), t));
361363

362-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext"),
363-
t->GetFunction());
364+
target->Set(secureContextString, t->GetFunction());
364365
env->set_secure_context_constructor_template(t);
365366
}
366367

src/node_file.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,9 +1484,10 @@ void InitFs(Local<Object> target,
14841484
FunctionTemplate::New(env->isolate(), NewFSReqWrap);
14851485
fst->InstanceTemplate()->SetInternalFieldCount(1);
14861486
env->SetProtoMethod(fst, "getAsyncId", AsyncWrap::GetAsyncId);
1487-
fst->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "FSReqWrap"));
1488-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "FSReqWrap"),
1489-
fst->GetFunction());
1487+
Local<String> wrapString =
1488+
FIXED_ONE_BYTE_STRING(env->isolate(), "FSReqWrap");
1489+
fst->SetClassName(wrapString);
1490+
target->Set(wrapString, fst->GetFunction());
14901491
}
14911492

14921493
} // end namespace node

src/node_http2.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,7 @@ void Initialize(Local<Object> target,
12061206
env->SetMethod(target, "nghttp2ErrorString", HttpErrorString);
12071207

12081208
Local<String> http2SessionClassName =
1209-
String::NewFromUtf8(isolate, "Http2Session",
1210-
v8::NewStringType::kInternalized).ToLocalChecked();
1209+
FIXED_ONE_BYTE_STRING(isolate, "Http2Session");
12111210

12121211
Local<FunctionTemplate> session =
12131212
env->NewFunctionTemplate(Http2Session::New);

src/node_serdes.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,11 @@ void InitializeSerdesBindings(Local<Object> target,
451451
"_setTreatArrayBufferViewsAsHostObjects",
452452
SerializerContext::SetTreatArrayBufferViewsAsHostObjects);
453453

454-
ser->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Serializer"));
454+
Local<String> serializerString =
455+
FIXED_ONE_BYTE_STRING(env->isolate(), "Serializer");
456+
ser->SetClassName(serializerString);
455457
target->Set(env->context(),
456-
FIXED_ONE_BYTE_STRING(env->isolate(), "Serializer"),
458+
serializerString,
457459
ser->GetFunction(env->context()).ToLocalChecked()).FromJust();
458460

459461
Local<FunctionTemplate> des =
@@ -474,9 +476,11 @@ void InitializeSerdesBindings(Local<Object> target,
474476
env->SetProtoMethod(des, "readDouble", DeserializerContext::ReadDouble);
475477
env->SetProtoMethod(des, "_readRawBytes", DeserializerContext::ReadRawBytes);
476478

477-
des->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Deserializer"));
479+
Local<String> deserializerString =
480+
FIXED_ONE_BYTE_STRING(env->isolate(), "Deserializer");
481+
des->SetClassName(deserializerString);
478482
target->Set(env->context(),
479-
FIXED_ONE_BYTE_STRING(env->isolate(), "Deserializer"),
483+
deserializerString,
480484
des->GetFunction(env->context()).ToLocalChecked()).FromJust();
481485
}
482486

src/node_stat_watcher.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ using v8::HandleScope;
3939
using v8::Integer;
4040
using v8::Local;
4141
using v8::Object;
42+
using v8::String;
4243
using v8::Value;
4344

4445

@@ -47,14 +48,15 @@ void StatWatcher::Initialize(Environment* env, Local<Object> target) {
4748

4849
Local<FunctionTemplate> t = env->NewFunctionTemplate(StatWatcher::New);
4950
t->InstanceTemplate()->SetInternalFieldCount(1);
50-
t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "StatWatcher"));
51+
Local<String> statWatcherString =
52+
FIXED_ONE_BYTE_STRING(env->isolate(), "StatWatcher");
53+
t->SetClassName(statWatcherString);
5154

5255
env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId);
5356
env->SetProtoMethod(t, "start", StatWatcher::Start);
5457
env->SetProtoMethod(t, "stop", StatWatcher::Stop);
5558

56-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "StatWatcher"),
57-
t->GetFunction());
59+
target->Set(statWatcherString, t->GetFunction());
5860
}
5961

6062

src/node_zlib.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ using v8::Integer;
4848
using v8::Local;
4949
using v8::Number;
5050
using v8::Object;
51+
using v8::String;
5152
using v8::Value;
5253

5354
namespace {
@@ -691,8 +692,9 @@ void InitZlib(Local<Object> target,
691692
env->SetProtoMethod(z, "params", ZCtx::Params);
692693
env->SetProtoMethod(z, "reset", ZCtx::Reset);
693694

694-
z->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib"));
695-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib"), z->GetFunction());
695+
Local<String> zlibString = FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib");
696+
z->SetClassName(zlibString);
697+
target->Set(zlibString, z->GetFunction());
696698

697699
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ZLIB_VERSION"),
698700
FIXED_ONE_BYTE_STRING(env->isolate(), ZLIB_VERSION));

src/pipe_wrap.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ using v8::FunctionTemplate;
4444
using v8::HandleScope;
4545
using v8::Local;
4646
using v8::Object;
47+
using v8::String;
4748
using v8::Value;
4849

4950
using AsyncHooks = Environment::AsyncHooks;
@@ -67,7 +68,8 @@ void PipeWrap::Initialize(Local<Object> target,
6768
Environment* env = Environment::GetCurrent(context);
6869

6970
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
70-
t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe"));
71+
Local<String> pipeString = FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe");
72+
t->SetClassName(pipeString);
7173
t->InstanceTemplate()->SetInternalFieldCount(1);
7274

7375
env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId);
@@ -92,7 +94,7 @@ void PipeWrap::Initialize(Local<Object> target,
9294
env->SetProtoMethod(t, "setPendingInstances", SetPendingInstances);
9395
#endif
9496

95-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe"), t->GetFunction());
97+
target->Set(pipeString, t->GetFunction());
9698
env->set_pipe_constructor_template(t);
9799

98100
// Create FunctionTemplate for PipeConnectWrap.
@@ -103,9 +105,10 @@ void PipeWrap::Initialize(Local<Object> target,
103105
auto cwt = FunctionTemplate::New(env->isolate(), constructor);
104106
cwt->InstanceTemplate()->SetInternalFieldCount(1);
105107
env->SetProtoMethod(cwt, "getAsyncId", AsyncWrap::GetAsyncId);
106-
cwt->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap"));
107-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap"),
108-
cwt->GetFunction());
108+
Local<String> wrapString =
109+
FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap");
110+
cwt->SetClassName(wrapString);
111+
target->Set(wrapString, cwt->GetFunction());
109112
}
110113

111114

0 commit comments

Comments
 (0)