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 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..9ffea0bedadf4f --- /dev/null +++ b/src/node_config.cc @@ -0,0 +1,48 @@ +#include "node.h" +#include "node_i18n.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); + +#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 + +NODE_MODULE_CONTEXT_AWARE_BUILTIN(config, node::InitConfig) 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);