Skip to content

Commit

Permalink
src: miscellaneous cleanups for node_config
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jasnell authored and MylesBorins committed Sep 12, 2017
1 parent bda5585 commit 1c3cb49
Showing 1 changed file with 52 additions and 42 deletions.
94 changes: 52 additions & 42 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace node {
using v8::Boolean;
using v8::Context;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Number;
using v8::Object;
Expand All @@ -25,24 +26,24 @@ using v8::Value;

#define READONLY_BOOLEAN_PROPERTY(str) \
do { \
target->DefineOwnProperty(env->context(), \
OneByteString(env->isolate(), str), \
True(env->isolate()), ReadOnly).FromJust(); \
target->DefineOwnProperty(context, \
FIXED_ONE_BYTE_STRING(isolate, str), \
True(isolate), ReadOnly).FromJust(); \
} while (0)

#define READONLY_PROPERTY(obj, name, value) \
do { \
obj->DefineOwnProperty(env->context(), \
OneByteString(env->isolate(), name), \
value, \
ReadOnly).FromJust(); \
FIXED_ONE_BYTE_STRING(isolate, name), \
value, ReadOnly).FromJust(); \
} while (0)


static void InitConfig(Local<Object> target,
Local<Value> unused,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);
Isolate* isolate = env->isolate();

#ifdef NODE_HAVE_I18N_SUPPORT

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

target->DefineOwnProperty(env->context(),
OneByteString(env->isolate(), "icuDataDir"),
OneByteString(env->isolate(), icu_data_dir.data()))
.FromJust();
target->DefineOwnProperty(
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

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

if (!config_warning_file.empty()) {
Local<String> name = OneByteString(env->isolate(), "warningFile");
Local<String> value = String::NewFromUtf8(env->isolate(),
config_warning_file.data(),
v8::NewStringType::kNormal,
config_warning_file.size())
.ToLocalChecked();
target->DefineOwnProperty(env->context(), name, value).FromJust();
}

Local<Object> debugOptions = Object::New(env->isolate());

target->DefineOwnProperty(env->context(),
OneByteString(env->isolate(), "debugOptions"),
debugOptions).FromJust();

debugOptions->DefineOwnProperty(env->context(),
OneByteString(env->isolate(), "host"),
String::NewFromUtf8(env->isolate(),
debug_options.host_name().c_str())).FromJust();

debugOptions->DefineOwnProperty(env->context(),
OneByteString(env->isolate(), "port"),
Integer::New(env->isolate(),
debug_options.port())).FromJust();

debugOptions->DefineOwnProperty(env->context(),
OneByteString(env->isolate(), "inspectorEnabled"),
Boolean::New(env->isolate(),
debug_options.inspector_enabled())).FromJust();

if (config_expose_internals)
READONLY_BOOLEAN_PROPERTY("exposeInternals");

Expand All @@ -104,6 +77,43 @@ static void InitConfig(Local<Object> target,
READONLY_PROPERTY(target,
"bits",
Number::New(env->isolate(), 8 * sizeof(intptr_t)));

if (!config_warning_file.empty()) {
target->DefineOwnProperty(
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);

target->DefineOwnProperty(
context,
FIXED_ONE_BYTE_STRING(isolate, "debugOptions"),
debugOptions, ReadOnly).FromJust();

debugOptions->DefineOwnProperty(
context,
FIXED_ONE_BYTE_STRING(isolate, "host"),
String::NewFromUtf8(isolate,
debug_options.host_name().c_str(),
v8::NewStringType::kNormal).ToLocalChecked(),
ReadOnly).FromJust();

debugOptions->DefineOwnProperty(
context,
FIXED_ONE_BYTE_STRING(isolate, "port"),
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

} // namespace node
Expand Down

0 comments on commit 1c3cb49

Please sign in to comment.