From b5c06d0b6707b8528cc49bd6de395aafb165ebf1 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 18 Apr 2016 21:26:30 -0700 Subject: [PATCH 1/3] doc: note that process.config can and will be changed --- doc/api/process.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/api/process.md b/doc/api/process.md index a67752878b285d..5020ae25d8a146 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -489,6 +489,10 @@ An example of the possible output looks like: } ``` +*Note: the `process.config` property is **not** read-only and there are existing +modules in the ecosystem that are known to extend, modify, or entirely replace +the value of `process.config`.* + ## process.connected * {Boolean} Set to false after `process.disconnect()` is called From 55e3422f8b0d8647dbfa85ef53c24b14ae96bbb4 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 18 Apr 2016 21:02:18 -0700 Subject: [PATCH 2/3] src: add process.binding('config') It turns out that userland likes to override process.config with their own stuff. If we want to be able to depend on it in any way, we need our own internal mechanism. This adds a new private process.binding('config') that is intended to serve as a container for internal flags and compile time configs that need to be passed on to the JS layer. --- node.gyp | 1 + src/node_config.cc | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/node_config.cc diff --git a/node.gyp b/node.gyp index 0e9fe40c419af6..86dffef5c6716c 100644 --- a/node.gyp +++ b/node.gyp @@ -130,6 +130,7 @@ 'src/js_stream.cc', 'src/node.cc', 'src/node_buffer.cc', + 'src/node_config.cc', 'src/node_constants.cc', 'src/node_contextify.cc', 'src/node_file.cc', diff --git a/src/node_config.cc b/src/node_config.cc new file mode 100644 index 00000000000000..e50002bc64c202 --- /dev/null +++ b/src/node_config.cc @@ -0,0 +1,36 @@ +#include "node.h" +#include "env.h" +#include "env-inl.h" +#include "util.h" +#include "util-inl.h" + + +namespace node { + +using v8::Context; +using v8::Local; +using v8::Object; +using v8::Value; +using v8::ReadOnly; + +// The config binding is used to provide an internal view of compile or runtime +// config options that are required internally by lib/*.js code. This is an +// alternative to dropping additional properties onto the process object as +// has been the practice previously in node.cc. + +#define READONLY_BOOLEAN_PROPERTY(str) \ + do { \ + target->DefineOwnProperty(env->context(), \ + OneByteString(env->isolate(), str), \ + True(env->isolate()), ReadOnly).FromJust(); \ + } while (0) + +void InitConfig(Local target, + Local unused, + Local context) { + // Environment* env = Environment::GetCurrent(context); +} + +} // namespace node + +NODE_MODULE_CONTEXT_AWARE_BUILTIN(config, node::InitConfig) From 1238fdf3056151054688fd8fcda6af70927e0a47 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 19 Apr 2016 16:11:21 -0700 Subject: [PATCH 3/3] src: add intl and icu configs to process.binding('config') --- src/node_config.cc | 14 +++++++++++++- src/node_i18n.cc | 4 ++++ src/node_i18n.h | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/node_config.cc b/src/node_config.cc index e50002bc64c202..9ffea0bedadf4f 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -1,4 +1,5 @@ #include "node.h" +#include "node_i18n.h" #include "env.h" #include "env-inl.h" #include "util.h" @@ -28,7 +29,18 @@ using v8::ReadOnly; void InitConfig(Local target, Local unused, Local context) { - // Environment* env = Environment::GetCurrent(context); + Environment* env = Environment::GetCurrent(context); + +#ifdef NODE_HAVE_I18N_SUPPORT + READONLY_BOOLEAN_PROPERTY("hasIntl"); + +#ifdef NODE_HAVE_SMALL_ICU + READONLY_BOOLEAN_PROPERTY("hasSmallICU"); +#endif // NODE_HAVE_SMALL_ICU + + if (flag_icu_data_dir) + READONLY_BOOLEAN_PROPERTY("usingICUDataDir"); +#endif // NODE_HAVE_I18N_SUPPORT } } // namespace node diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 0f59b45c23915f..3e5b3a91298988 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -42,10 +42,14 @@ extern "C" const char U_DATA_API SMALL_ICUDATA_ENTRY_POINT[]; #endif namespace node { + +bool flag_icu_data_dir = false; + namespace i18n { bool InitializeICUDirectory(const char* icu_data_path) { if (icu_data_path != nullptr) { + flag_icu_data_dir = true; u_setDataDirectory(icu_data_path); return true; // no error } else { diff --git a/src/node_i18n.h b/src/node_i18n.h index 0d47927a6c024c..4e812ad0f3e8a7 100644 --- a/src/node_i18n.h +++ b/src/node_i18n.h @@ -6,6 +6,9 @@ #if defined(NODE_HAVE_I18N_SUPPORT) namespace node { + +extern bool flag_icu_data_dir; + namespace i18n { bool InitializeICUDirectory(const char* icu_data_path);