Skip to content

Commit b3eb10d

Browse files
maclover7targos
authored andcommitted
src: add READONLY_STRING_PROPERTY and simplify config
Bit of tidying up where we set different config values. PR-URL: #22222 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9327a58 commit b3eb10d

File tree

1 file changed

+25
-45
lines changed

1 file changed

+25
-45
lines changed

src/node_config.cc

+25-45
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ using v8::Value;
2929
True(isolate), ReadOnly).FromJust(); \
3030
} while (0)
3131

32+
#define READONLY_STRING_PROPERTY(obj, str, val) \
33+
do { \
34+
(obj)->DefineOwnProperty(context, \
35+
FIXED_ONE_BYTE_STRING(isolate, str), \
36+
String::NewFromUtf8( \
37+
isolate, \
38+
val.data(), \
39+
v8::NewStringType::kNormal).ToLocalChecked(), \
40+
ReadOnly).FromJust(); \
41+
} while (0)
42+
43+
3244
#define READONLY_PROPERTY(obj, name, value) \
3345
do { \
3446
obj->DefineOwnProperty(env->context(), \
@@ -60,13 +72,7 @@ static void Initialize(Local<Object> target,
6072
READONLY_BOOLEAN_PROPERTY("hasTracing");
6173
#endif
6274

63-
target->DefineOwnProperty(
64-
context,
65-
FIXED_ONE_BYTE_STRING(isolate, "icuDataDir"),
66-
String::NewFromUtf8(isolate,
67-
icu_data_dir.data(),
68-
v8::NewStringType::kNormal).ToLocalChecked(),
69-
ReadOnly).FromJust();
75+
READONLY_STRING_PROPERTY(target, "icuDataDir", icu_data_dir);
7076

7177
#endif // NODE_HAVE_I18N_SUPPORT
7278

@@ -78,13 +84,7 @@ static void Initialize(Local<Object> target,
7884
if (config_experimental_modules) {
7985
READONLY_BOOLEAN_PROPERTY("experimentalModules");
8086
if (!config_userland_loader.empty()) {
81-
target->DefineOwnProperty(
82-
context,
83-
FIXED_ONE_BYTE_STRING(isolate, "userLoader"),
84-
String::NewFromUtf8(isolate,
85-
config_userland_loader.data(),
86-
v8::NewStringType::kNormal).ToLocalChecked(),
87-
ReadOnly).FromJust();
87+
READONLY_STRING_PROPERTY(target, "userLoader", config_userland_loader);
8888
}
8989
}
9090

@@ -111,41 +111,21 @@ static void Initialize(Local<Object> target,
111111
Number::New(env->isolate(), 8 * sizeof(intptr_t)));
112112

113113
if (!config_warning_file.empty()) {
114-
target->DefineOwnProperty(
115-
context,
116-
FIXED_ONE_BYTE_STRING(isolate, "warningFile"),
117-
String::NewFromUtf8(isolate,
118-
config_warning_file.data(),
119-
v8::NewStringType::kNormal).ToLocalChecked(),
120-
ReadOnly).FromJust();
114+
READONLY_STRING_PROPERTY(target, "warningFile", config_warning_file);
121115
}
122116

123117
Local<Object> debugOptions = Object::New(isolate);
118+
READONLY_PROPERTY(target, "debugOptions", debugOptions);
119+
120+
READONLY_STRING_PROPERTY(debugOptions, "host", debug_options.host_name());
121+
122+
READONLY_PROPERTY(debugOptions,
123+
"port",
124+
Integer::New(isolate, debug_options.port()));
124125

125-
target->DefineOwnProperty(
126-
context,
127-
FIXED_ONE_BYTE_STRING(isolate, "debugOptions"),
128-
debugOptions, ReadOnly).FromJust();
129-
130-
debugOptions->DefineOwnProperty(
131-
context,
132-
FIXED_ONE_BYTE_STRING(isolate, "host"),
133-
String::NewFromUtf8(isolate,
134-
debug_options.host_name().c_str(),
135-
v8::NewStringType::kNormal).ToLocalChecked(),
136-
ReadOnly).FromJust();
137-
138-
debugOptions->DefineOwnProperty(
139-
context,
140-
env->port_string(),
141-
Integer::New(isolate, debug_options.port()),
142-
ReadOnly).FromJust();
143-
144-
debugOptions->DefineOwnProperty(
145-
context,
146-
FIXED_ONE_BYTE_STRING(isolate, "inspectorEnabled"),
147-
Boolean::New(isolate, debug_options.inspector_enabled()), ReadOnly)
148-
.FromJust();
126+
READONLY_PROPERTY(debugOptions,
127+
"inspectorEnabled",
128+
Boolean::New(isolate, debug_options.inspector_enabled()));
149129
} // InitConfig
150130

151131
} // namespace node

0 commit comments

Comments
 (0)