diff options
author | James M Snell <jasnell@gmail.com> | 2017-08-16 20:46:26 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-08-19 01:04:26 +0300 |
commit | fd8cf7905698db82e2c333ba21058144363becdf (patch) | |
tree | 57c5acddba081b463cf71dfb9f9418f68f9a5ee2 /src/node_config.cc | |
parent | 35f6e59dfce2f4f525d02d84aabe26bf111de567 (diff) |
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: https://github.com/nodejs/node/pull/14868
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_config.cc')
-rw-r--r-- | src/node_config.cc | 94 |
1 files changed, 52 insertions, 42 deletions
diff --git a/src/node_config.cc b/src/node_config.cc index 64263fb2d69..a2d980d793f 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -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; @@ -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"); @@ -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 @@ -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"); @@ -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 |