@@ -29,6 +29,18 @@ using v8::Value; |
29 | 29 | True(isolate), ReadOnly).FromJust(); \ |
30 | 30 | } while (0) |
31 | 31 |
|
| 32 | +#define READONLY_STRING_PROPERTY(obj, str, val) \ |
| 33 | + do { \ |
| 34 | + (obj)->DefineOwnProperty(context, \ |
| 35 | + FIXED_ONE_BYTE_STRING(isolate, str), \ |
| 36 | + String::NewFromUtf8( \ |
| 37 | + isolate, \ |
| 38 | + val.data(), \ |
| 39 | + v8::NewStringType::kNormal).ToLocalChecked(), \ |
| 40 | + ReadOnly).FromJust(); \ |
| 41 | + } while (0) |
| 42 | + |
| 43 | + |
32 | 44 | #define READONLY_PROPERTY(obj, name, value) \ |
33 | 45 | do { \ |
34 | 46 | obj->DefineOwnProperty(env->context(), \ |
@@ -60,13 +72,7 @@ static void Initialize(Local<Object> target, |
60 | 72 | READONLY_BOOLEAN_PROPERTY("hasTracing"); |
61 | 73 | #endif |
62 | 74 |
|
63 | | - target->DefineOwnProperty( |
64 | | - context, |
65 | | - FIXED_ONE_BYTE_STRING(isolate, "icuDataDir"), |
66 | | - String::NewFromUtf8(isolate, |
67 | | - icu_data_dir.data(), |
68 | | - v8::NewStringType::kNormal).ToLocalChecked(), |
69 | | - ReadOnly).FromJust(); |
| 75 | + READONLY_STRING_PROPERTY(target, "icuDataDir", icu_data_dir); |
70 | 76 |
|
71 | 77 | #endif // NODE_HAVE_I18N_SUPPORT |
72 | 78 |
|
@@ -78,13 +84,7 @@ static void Initialize(Local<Object> target, |
78 | 84 | if (config_experimental_modules) { |
79 | 85 | READONLY_BOOLEAN_PROPERTY("experimentalModules"); |
80 | 86 | if (!config_userland_loader.empty()) { |
81 | | - target->DefineOwnProperty( |
82 | | - context, |
83 | | - FIXED_ONE_BYTE_STRING(isolate, "userLoader"), |
84 | | - String::NewFromUtf8(isolate, |
85 | | - config_userland_loader.data(), |
86 | | - v8::NewStringType::kNormal).ToLocalChecked(), |
87 | | - ReadOnly).FromJust(); |
| 87 | + READONLY_STRING_PROPERTY(target, "userLoader", config_userland_loader); |
88 | 88 | } |
89 | 89 | } |
90 | 90 |
|
@@ -111,41 +111,21 @@ static void Initialize(Local<Object> target, |
111 | 111 | Number::New(env->isolate(), 8 * sizeof(intptr_t))); |
112 | 112 |
|
113 | 113 | if (!config_warning_file.empty()) { |
114 | | - target->DefineOwnProperty( |
115 | | - context, |
116 | | - FIXED_ONE_BYTE_STRING(isolate, "warningFile"), |
117 | | - String::NewFromUtf8(isolate, |
118 | | - config_warning_file.data(), |
119 | | - v8::NewStringType::kNormal).ToLocalChecked(), |
120 | | - ReadOnly).FromJust(); |
| 114 | + READONLY_STRING_PROPERTY(target, "warningFile", config_warning_file); |
121 | 115 | } |
122 | 116 |
|
123 | 117 | Local<Object> debugOptions = Object::New(isolate); |
| 118 | + READONLY_PROPERTY(target, "debugOptions", debugOptions); |
| 119 | + |
| 120 | + READONLY_STRING_PROPERTY(debugOptions, "host", debug_options.host_name()); |
| 121 | + |
| 122 | + READONLY_PROPERTY(debugOptions, |
| 123 | + "port", |
| 124 | + Integer::New(isolate, debug_options.port())); |
124 | 125 |
|
125 | | - target->DefineOwnProperty( |
126 | | - context, |
127 | | - FIXED_ONE_BYTE_STRING(isolate, "debugOptions"), |
128 | | - debugOptions, ReadOnly).FromJust(); |
129 | | - |
130 | | - debugOptions->DefineOwnProperty( |
131 | | - context, |
132 | | - FIXED_ONE_BYTE_STRING(isolate, "host"), |
133 | | - String::NewFromUtf8(isolate, |
134 | | - debug_options.host_name().c_str(), |
135 | | - v8::NewStringType::kNormal).ToLocalChecked(), |
136 | | - ReadOnly).FromJust(); |
137 | | - |
138 | | - debugOptions->DefineOwnProperty( |
139 | | - context, |
140 | | - env->port_string(), |
141 | | - Integer::New(isolate, debug_options.port()), |
142 | | - ReadOnly).FromJust(); |
143 | | - |
144 | | - debugOptions->DefineOwnProperty( |
145 | | - context, |
146 | | - FIXED_ONE_BYTE_STRING(isolate, "inspectorEnabled"), |
147 | | - Boolean::New(isolate, debug_options.inspector_enabled()), ReadOnly) |
148 | | - .FromJust(); |
| 126 | + READONLY_PROPERTY(debugOptions, |
| 127 | + "inspectorEnabled", |
| 128 | + Boolean::New(isolate, debug_options.inspector_enabled())); |
149 | 129 | } // InitConfig |
150 | 130 |
|
151 | 131 | } // namespace node |
|