Node.js  v8.x
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine
node_config.cc
Go to the documentation of this file.
1 #include "node.h"
2 #include "node_i18n.h"
3 #include "env.h"
4 #include "env-inl.h"
5 #include "util.h"
6 #include "util-inl.h"
7 #include "node_debug_options.h"
8 
9 namespace node {
10 
11 using v8::Boolean;
12 using v8::Context;
13 using v8::Integer;
14 using v8::Isolate;
15 using v8::Local;
16 using v8::Number;
17 using v8::Object;
18 using v8::ReadOnly;
19 using v8::String;
20 using v8::Value;
21 
22 // The config binding is used to provide an internal view of compile or runtime
23 // config options that are required internally by lib/*.js code. This is an
24 // alternative to dropping additional properties onto the process object as
25 // has been the practice previously in node.cc.
26 
27 #define READONLY_BOOLEAN_PROPERTY(str) \
28  do { \
29  target->DefineOwnProperty(context, \
30  FIXED_ONE_BYTE_STRING(isolate, str), \
31  True(isolate), ReadOnly).FromJust(); \
32  } while (0)
33 
34 #define READONLY_PROPERTY(obj, name, value) \
35  do { \
36  obj->DefineOwnProperty(env->context(), \
37  FIXED_ONE_BYTE_STRING(isolate, name), \
38  value, ReadOnly).FromJust(); \
39  } while (0)
40 
41 static void InitConfig(Local<Object> target,
42  Local<Value> unused,
43  Local<Context> context) {
44  Environment* env = Environment::GetCurrent(context);
45  Isolate* isolate = env->isolate();
46 
47 #ifdef NODE_HAVE_I18N_SUPPORT
48 
49  READONLY_BOOLEAN_PROPERTY("hasIntl");
50 
51 #ifdef NODE_HAVE_SMALL_ICU
52  READONLY_BOOLEAN_PROPERTY("hasSmallICU");
53 #endif // NODE_HAVE_SMALL_ICU
54 
55  target->DefineOwnProperty(
56  context,
57  FIXED_ONE_BYTE_STRING(isolate, "icuDataDir"),
58  String::NewFromUtf8(isolate,
59  icu_data_dir.data(),
60  v8::NewStringType::kNormal).ToLocalChecked(),
61  ReadOnly).FromJust();
62 
63 #endif // NODE_HAVE_I18N_SUPPORT
64 
66  READONLY_BOOLEAN_PROPERTY("preserveSymlinks");
67 
69  READONLY_BOOLEAN_PROPERTY("experimentalModules");
70 
72  READONLY_BOOLEAN_PROPERTY("pendingDeprecation");
73 
75  READONLY_BOOLEAN_PROPERTY("exposeInternals");
76 
78  READONLY_BOOLEAN_PROPERTY("exposeHTTP2");
79 
80  READONLY_PROPERTY(target,
81  "bits",
82  Number::New(env->isolate(), 8 * sizeof(intptr_t)));
83 
84  if (!config_warning_file.empty()) {
85  target->DefineOwnProperty(
86  context,
87  FIXED_ONE_BYTE_STRING(isolate, "warningFile"),
88  String::NewFromUtf8(isolate,
89  config_warning_file.data(),
90  v8::NewStringType::kNormal).ToLocalChecked(),
91  ReadOnly).FromJust();
92  }
93 
94  Local<Object> debugOptions = Object::New(isolate);
95 
96  target->DefineOwnProperty(
97  context,
98  FIXED_ONE_BYTE_STRING(isolate, "debugOptions"),
99  debugOptions, ReadOnly).FromJust();
100 
101  debugOptions->DefineOwnProperty(
102  context,
103  FIXED_ONE_BYTE_STRING(isolate, "host"),
104  String::NewFromUtf8(isolate,
105  debug_options.host_name().c_str(),
106  v8::NewStringType::kNormal).ToLocalChecked(),
107  ReadOnly).FromJust();
108 
109  debugOptions->DefineOwnProperty(
110  context,
111  env->port_string(),
112  Integer::New(isolate, debug_options.port()),
113  ReadOnly).FromJust();
114 
115  debugOptions->DefineOwnProperty(
116  context,
117  FIXED_ONE_BYTE_STRING(isolate, "inspectorEnabled"),
118  Boolean::New(isolate, debug_options.inspector_enabled()), ReadOnly)
119  .FromJust();
120 } // InitConfig
121 
122 } // namespace node
123 
124 NODE_MODULE_CONTEXT_AWARE_BUILTIN(config, node::InitConfig)
bool config_expose_http2
Definition: node.cc:247
NODE_MODULE_CONTEXT_AWARE_BUILTIN(inspector, node::inspector::Agent::InitInspector)
bool inspector_enabled() const
#define READONLY_PROPERTY(obj, name, value)
Definition: node_config.cc:34
#define READONLY_BOOLEAN_PROPERTY(str)
Definition: node_config.cc:27
bool config_experimental_modules
Definition: node.cc:231
node::DebugOptions debug_options
Definition: node.cc:259
bool config_pending_deprecation
Definition: node.cc:235
std::string config_warning_file
Definition: node.cc:238
bool config_preserve_symlinks
Definition: node.cc:226
MaybeLocal< Object > New(Isolate *isolate, Local< String > string, enum encoding enc)
Definition: node_buffer.cc:241
bool config_expose_internals
Definition: node.cc:244
std::string host_name() const