src: add READONLY_STRING_PROPERTY and simplify config
Bit of tidying up where we set different config values. PR-URL: https://github.com/nodejs/node/pull/22222 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
640dc7a474
commit
30b5b8485b
@ -29,6 +29,18 @@ using v8::Value;
|
|||||||
True(isolate), ReadOnly).FromJust(); \
|
True(isolate), ReadOnly).FromJust(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define READONLY_STRING_PROPERTY(obj, str, val) \
|
||||||
|
do { \
|
||||||
|
(obj)->DefineOwnProperty(context, \
|
||||||
|
FIXED_ONE_BYTE_STRING(isolate, str), \
|
||||||
|
String::NewFromUtf8( \
|
||||||
|
isolate, \
|
||||||
|
val.data(), \
|
||||||
|
v8::NewStringType::kNormal).ToLocalChecked(), \
|
||||||
|
ReadOnly).FromJust(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
#define READONLY_PROPERTY(obj, name, value) \
|
#define READONLY_PROPERTY(obj, name, value) \
|
||||||
do { \
|
do { \
|
||||||
obj->DefineOwnProperty(env->context(), \
|
obj->DefineOwnProperty(env->context(), \
|
||||||
@ -60,13 +72,7 @@ static void Initialize(Local<Object> target,
|
|||||||
READONLY_BOOLEAN_PROPERTY("hasTracing");
|
READONLY_BOOLEAN_PROPERTY("hasTracing");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
target->DefineOwnProperty(
|
READONLY_STRING_PROPERTY(target, "icuDataDir", icu_data_dir);
|
||||||
context,
|
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "icuDataDir"),
|
|
||||||
String::NewFromUtf8(isolate,
|
|
||||||
icu_data_dir.data(),
|
|
||||||
v8::NewStringType::kNormal).ToLocalChecked(),
|
|
||||||
ReadOnly).FromJust();
|
|
||||||
|
|
||||||
#endif // NODE_HAVE_I18N_SUPPORT
|
#endif // NODE_HAVE_I18N_SUPPORT
|
||||||
|
|
||||||
@ -78,13 +84,7 @@ static void Initialize(Local<Object> target,
|
|||||||
if (config_experimental_modules) {
|
if (config_experimental_modules) {
|
||||||
READONLY_BOOLEAN_PROPERTY("experimentalModules");
|
READONLY_BOOLEAN_PROPERTY("experimentalModules");
|
||||||
if (!config_userland_loader.empty()) {
|
if (!config_userland_loader.empty()) {
|
||||||
target->DefineOwnProperty(
|
READONLY_STRING_PROPERTY(target, "userLoader", config_userland_loader);
|
||||||
context,
|
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "userLoader"),
|
|
||||||
String::NewFromUtf8(isolate,
|
|
||||||
config_userland_loader.data(),
|
|
||||||
v8::NewStringType::kNormal).ToLocalChecked(),
|
|
||||||
ReadOnly).FromJust();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,41 +111,21 @@ static void Initialize(Local<Object> target,
|
|||||||
Number::New(env->isolate(), 8 * sizeof(intptr_t)));
|
Number::New(env->isolate(), 8 * sizeof(intptr_t)));
|
||||||
|
|
||||||
if (!config_warning_file.empty()) {
|
if (!config_warning_file.empty()) {
|
||||||
target->DefineOwnProperty(
|
READONLY_STRING_PROPERTY(target, "warningFile", config_warning_file);
|
||||||
context,
|
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "warningFile"),
|
|
||||||
String::NewFromUtf8(isolate,
|
|
||||||
config_warning_file.data(),
|
|
||||||
v8::NewStringType::kNormal).ToLocalChecked(),
|
|
||||||
ReadOnly).FromJust();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Local<Object> debugOptions = Object::New(isolate);
|
Local<Object> debugOptions = Object::New(isolate);
|
||||||
|
READONLY_PROPERTY(target, "debugOptions", debugOptions);
|
||||||
|
|
||||||
target->DefineOwnProperty(
|
READONLY_STRING_PROPERTY(debugOptions, "host", debug_options.host_name());
|
||||||
context,
|
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "debugOptions"),
|
|
||||||
debugOptions, ReadOnly).FromJust();
|
|
||||||
|
|
||||||
debugOptions->DefineOwnProperty(
|
READONLY_PROPERTY(debugOptions,
|
||||||
context,
|
"port",
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "host"),
|
Integer::New(isolate, debug_options.port()));
|
||||||
String::NewFromUtf8(isolate,
|
|
||||||
debug_options.host_name().c_str(),
|
|
||||||
v8::NewStringType::kNormal).ToLocalChecked(),
|
|
||||||
ReadOnly).FromJust();
|
|
||||||
|
|
||||||
debugOptions->DefineOwnProperty(
|
READONLY_PROPERTY(debugOptions,
|
||||||
context,
|
"inspectorEnabled",
|
||||||
env->port_string(),
|
Boolean::New(isolate, debug_options.inspector_enabled()));
|
||||||
Integer::New(isolate, debug_options.port()),
|
|
||||||
ReadOnly).FromJust();
|
|
||||||
|
|
||||||
debugOptions->DefineOwnProperty(
|
|
||||||
context,
|
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "inspectorEnabled"),
|
|
||||||
Boolean::New(isolate, debug_options.inspector_enabled()), ReadOnly)
|
|
||||||
.FromJust();
|
|
||||||
} // InitConfig
|
} // InitConfig
|
||||||
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user