Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: add process.binding('config') #6266

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
48 changes: 48 additions & 0 deletions src/node_config.cc
Original file line number Diff line number Diff line change
@@ -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<Object> target,
Local<Value> unused,
Local<Context> 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)
4 changes: 4 additions & 0 deletions src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/node_i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down