Skip to content

Commit fd8cf79

Browse files
committed
src: miscellaneous cleanups for node_config
Includes a fix for setting the `icuDataDir` as a UTF8 string rather than one byte. Previously, if the dir contained any non-ascii characters they would be mangled. This won't cover cases that involve paths with other character encodings (thank you Linux).. but it will cover the most likely. Other miscellaneous cleanups are included PR-URL: #14868 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 35f6e59 commit fd8cf79

File tree

1 file changed

+52
-42
lines changed

1 file changed

+52
-42
lines changed

src/node_config.cc

+52-42
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace node {
1111
using v8::Boolean;
1212
using v8::Context;
1313
using v8::Integer;
14+
using v8::Isolate;
1415
using v8::Local;
1516
using v8::Number;
1617
using v8::Object;
@@ -25,24 +26,24 @@ using v8::Value;
2526

2627
#define READONLY_BOOLEAN_PROPERTY(str) \
2728
do { \
28-
target->DefineOwnProperty(env->context(), \
29-
OneByteString(env->isolate(), str), \
30-
True(env->isolate()), ReadOnly).FromJust(); \
29+
target->DefineOwnProperty(context, \
30+
FIXED_ONE_BYTE_STRING(isolate, str), \
31+
True(isolate), ReadOnly).FromJust(); \
3132
} while (0)
3233

3334
#define READONLY_PROPERTY(obj, name, value) \
3435
do { \
3536
obj->DefineOwnProperty(env->context(), \
36-
OneByteString(env->isolate(), name), \
37-
value, \
38-
ReadOnly).FromJust(); \
37+
FIXED_ONE_BYTE_STRING(isolate, name), \
38+
value, ReadOnly).FromJust(); \
3939
} while (0)
4040

41-
4241
static void InitConfig(Local<Object> target,
4342
Local<Value> unused,
4443
Local<Context> context) {
4544
Environment* env = Environment::GetCurrent(context);
45+
Isolate* isolate = env->isolate();
46+
4647
#ifdef NODE_HAVE_I18N_SUPPORT
4748

4849
READONLY_BOOLEAN_PROPERTY("hasIntl");
@@ -51,10 +52,13 @@ static void InitConfig(Local<Object> target,
5152
READONLY_BOOLEAN_PROPERTY("hasSmallICU");
5253
#endif // NODE_HAVE_SMALL_ICU
5354

54-
target->DefineOwnProperty(env->context(),
55-
OneByteString(env->isolate(), "icuDataDir"),
56-
OneByteString(env->isolate(), icu_data_dir.data()))
57-
.FromJust();
55+
target->DefineOwnProperty(
56+
context,
57+
FIXED_ONE_BYTE_STRING(isolate, "icuDataDir"),
58+
String::NewFromUtf8(isolate,
59+
icu_data_dir.data(),
60+
v8::NewStringType::kNormal).ToLocalChecked(),
61+
ReadOnly).FromJust();
5862

5963
#endif // NODE_HAVE_I18N_SUPPORT
6064

@@ -64,37 +68,6 @@ static void InitConfig(Local<Object> target,
6468
if (config_pending_deprecation)
6569
READONLY_BOOLEAN_PROPERTY("pendingDeprecation");
6670

67-
if (!config_warning_file.empty()) {
68-
Local<String> name = OneByteString(env->isolate(), "warningFile");
69-
Local<String> value = String::NewFromUtf8(env->isolate(),
70-
config_warning_file.data(),
71-
v8::NewStringType::kNormal,
72-
config_warning_file.size())
73-
.ToLocalChecked();
74-
target->DefineOwnProperty(env->context(), name, value).FromJust();
75-
}
76-
77-
Local<Object> debugOptions = Object::New(env->isolate());
78-
79-
target->DefineOwnProperty(env->context(),
80-
OneByteString(env->isolate(), "debugOptions"),
81-
debugOptions).FromJust();
82-
83-
debugOptions->DefineOwnProperty(env->context(),
84-
OneByteString(env->isolate(), "host"),
85-
String::NewFromUtf8(env->isolate(),
86-
debug_options.host_name().c_str())).FromJust();
87-
88-
debugOptions->DefineOwnProperty(env->context(),
89-
OneByteString(env->isolate(), "port"),
90-
Integer::New(env->isolate(),
91-
debug_options.port())).FromJust();
92-
93-
debugOptions->DefineOwnProperty(env->context(),
94-
OneByteString(env->isolate(), "inspectorEnabled"),
95-
Boolean::New(env->isolate(),
96-
debug_options.inspector_enabled())).FromJust();
97-
9871
if (config_expose_internals)
9972
READONLY_BOOLEAN_PROPERTY("exposeInternals");
10073

@@ -104,6 +77,43 @@ static void InitConfig(Local<Object> target,
10477
READONLY_PROPERTY(target,
10578
"bits",
10679
Number::New(env->isolate(), 8 * sizeof(intptr_t)));
80+
81+
if (!config_warning_file.empty()) {
82+
target->DefineOwnProperty(
83+
context,
84+
FIXED_ONE_BYTE_STRING(isolate, "warningFile"),
85+
String::NewFromUtf8(isolate,
86+
config_warning_file.data(),
87+
v8::NewStringType::kNormal).ToLocalChecked(),
88+
ReadOnly).FromJust();
89+
}
90+
91+
Local<Object> debugOptions = Object::New(isolate);
92+
93+
target->DefineOwnProperty(
94+
context,
95+
FIXED_ONE_BYTE_STRING(isolate, "debugOptions"),
96+
debugOptions, ReadOnly).FromJust();
97+
98+
debugOptions->DefineOwnProperty(
99+
context,
100+
FIXED_ONE_BYTE_STRING(isolate, "host"),
101+
String::NewFromUtf8(isolate,
102+
debug_options.host_name().c_str(),
103+
v8::NewStringType::kNormal).ToLocalChecked(),
104+
ReadOnly).FromJust();
105+
106+
debugOptions->DefineOwnProperty(
107+
context,
108+
FIXED_ONE_BYTE_STRING(isolate, "port"),
109+
Integer::New(isolate, debug_options.port()),
110+
ReadOnly).FromJust();
111+
112+
debugOptions->DefineOwnProperty(
113+
context,
114+
FIXED_ONE_BYTE_STRING(isolate, "inspectorEnabled"),
115+
Boolean::New(isolate, debug_options.inspector_enabled()), ReadOnly)
116+
.FromJust();
107117
} // InitConfig
108118

109119
} // namespace node

0 commit comments

Comments
 (0)