@@ -2199,6 +2199,12 @@ static void NeedImmediateCallbackSetter(Local<String> property,
2199
2199
}
2200
2200
2201
2201
2202
+ #define READONLY_PROPERTY (obj, str, var ) \
2203
+ do { \
2204
+ obj->Set (String::New (str), var, v8::ReadOnly); \
2205
+ } while (0 )
2206
+
2207
+
2202
2208
Handle <Object> SetupProcessObject (int argc, char *argv[]) {
2203
2209
HandleScope scope (node_isolate);
2204
2210
@@ -2218,27 +2224,27 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
2218
2224
ProcessTitleSetter);
2219
2225
2220
2226
// process.version
2221
- process-> Set ( String::NewSymbol ( " version" ) , String::New (NODE_VERSION));
2227
+ READONLY_PROPERTY (process, " version" , String::New (NODE_VERSION));
2222
2228
2223
2229
// process.moduleLoadList
2224
2230
Local<Array> modules = Array::New ();
2225
2231
module_load_list.Reset (node_isolate, modules);
2226
- process-> Set ( String::NewSymbol ( " moduleLoadList" ) , modules);
2232
+ READONLY_PROPERTY (process, " moduleLoadList" , modules);
2227
2233
2228
2234
// process.versions
2229
2235
Local<Object> versions = Object::New ();
2230
- process-> Set ( String::NewSymbol ( " versions" ) , versions);
2231
- versions-> Set ( String::NewSymbol ( " http_parser" ) , String::New (
2232
- NODE_STRINGIFY (HTTP_PARSER_VERSION_MAJOR) " ."
2233
- NODE_STRINGIFY (HTTP_PARSER_VERSION_MINOR)));
2236
+ READONLY_PROPERTY (process, " versions" , versions);
2237
+ READONLY_PROPERTY (versions, " http_parser" , String::New (
2238
+ NODE_STRINGIFY (HTTP_PARSER_VERSION_MAJOR) " ."
2239
+ NODE_STRINGIFY (HTTP_PARSER_VERSION_MINOR)));
2234
2240
// +1 to get rid of the leading 'v'
2235
- versions-> Set ( String::NewSymbol ( " node" ) , String::New (NODE_VERSION+1 ));
2236
- versions-> Set ( String::NewSymbol ( " v8" ) , String::New (V8::GetVersion ()));
2237
- versions-> Set ( String::NewSymbol ( " ares " ) , String::New (ARES_VERSION_STR ));
2238
- versions-> Set ( String::NewSymbol ( " uv " ) , String::New (uv_version_string () ));
2239
- versions-> Set ( String::NewSymbol ( " zlib " ), String::New (ZLIB_VERSION));
2240
- versions-> Set ( String::NewSymbol ( " modules" ) ,
2241
- String::New (NODE_STRINGIFY (NODE_MODULE_VERSION)));
2241
+ READONLY_PROPERTY (versions, " node" , String::New (NODE_VERSION+1 ));
2242
+ READONLY_PROPERTY (versions, " v8" , String::New (V8::GetVersion ()));
2243
+ READONLY_PROPERTY (versions, " uv " , String::New (uv_version_string () ));
2244
+ READONLY_PROPERTY (versions, " zlib " , String::New (ZLIB_VERSION ));
2245
+ READONLY_PROPERTY (versions,
2246
+ " modules" ,
2247
+ String::New (NODE_STRINGIFY (NODE_MODULE_VERSION)));
2242
2248
#if HAVE_OPENSSL
2243
2249
// Stupid code to slice out the version string.
2244
2250
int c, l = strlen (OPENSSL_VERSION_TEXT);
@@ -2252,17 +2258,18 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
2252
2258
break ;
2253
2259
}
2254
2260
}
2255
- versions->Set (String::NewSymbol (" openssl" ),
2256
- String::New (&OPENSSL_VERSION_TEXT[i], j - i));
2261
+ READONLY_PROPERTY (versions,
2262
+ " openssl" ,
2263
+ String::New (&OPENSSL_VERSION_TEXT[i], j - i));
2257
2264
#endif
2258
2265
2259
2266
2260
2267
2261
2268
// process.arch
2262
- process-> Set ( String::NewSymbol ( " arch" ) , String::New (ARCH));
2269
+ READONLY_PROPERTY (process, " arch" , String::New (ARCH));
2263
2270
2264
2271
// process.platform
2265
- process-> Set ( String::NewSymbol ( " platform" ) , String::New (PLATFORM));
2272
+ READONLY_PROPERTY (process, " platform" , String::New (PLATFORM));
2266
2273
2267
2274
// process.argv
2268
2275
Local<Array> arguments = Array::New (argc - option_end_index + 1 );
@@ -2294,40 +2301,40 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
2294
2301
Local<Object> env = envTemplate->NewInstance ();
2295
2302
process->Set (String::NewSymbol (" env" ), env);
2296
2303
2297
- process-> Set ( String::NewSymbol ( " pid" ) , Integer::New (getpid (), node_isolate));
2298
- process-> Set ( String::NewSymbol ( " features" ) , GetFeatures ());
2304
+ READONLY_PROPERTY (process, " pid" , Integer::New (getpid (), node_isolate));
2305
+ READONLY_PROPERTY (process, " features" , GetFeatures ());
2299
2306
process->SetAccessor (String::New (" _needImmediateCallback" ),
2300
2307
NeedImmediateCallbackGetter,
2301
2308
NeedImmediateCallbackSetter);
2302
2309
2303
2310
// -e, --eval
2304
2311
if (eval_string) {
2305
- process-> Set ( String::NewSymbol ( " _eval" ) , String::New (eval_string));
2312
+ READONLY_PROPERTY (process, " _eval" , String::New (eval_string));
2306
2313
}
2307
2314
2308
2315
// -p, --print
2309
2316
if (print_eval) {
2310
- process-> Set ( String::NewSymbol ( " _print_eval" ) , True (node_isolate));
2317
+ READONLY_PROPERTY (process, " _print_eval" , True (node_isolate));
2311
2318
}
2312
2319
2313
2320
// -i, --interactive
2314
2321
if (force_repl) {
2315
- process-> Set ( String::NewSymbol ( " _forceRepl" ) , True (node_isolate));
2322
+ READONLY_PROPERTY (process, " _forceRepl" , True (node_isolate));
2316
2323
}
2317
2324
2318
2325
// --no-deprecation
2319
2326
if (no_deprecation) {
2320
- process-> Set ( String::NewSymbol ( " noDeprecation" ) , True (node_isolate));
2327
+ READONLY_PROPERTY (process, " noDeprecation" , True (node_isolate));
2321
2328
}
2322
2329
2323
2330
// --throw-deprecation
2324
2331
if (throw_deprecation) {
2325
- process-> Set ( String::NewSymbol ( " throwDeprecation" ) , True (node_isolate));
2332
+ READONLY_PROPERTY (process, " throwDeprecation" , True (node_isolate));
2326
2333
}
2327
2334
2328
2335
// --trace-deprecation
2329
2336
if (trace_deprecation) {
2330
- process-> Set ( String::NewSymbol ( " traceDeprecation" ) , True (node_isolate));
2337
+ READONLY_PROPERTY (process, " traceDeprecation" , True (node_isolate));
2331
2338
}
2332
2339
2333
2340
size_t size = 2 *PATH_MAX;
@@ -2398,6 +2405,9 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
2398
2405
}
2399
2406
2400
2407
2408
+ #undef READONLY_PROPERTY
2409
+
2410
+
2401
2411
static void AtExit () {
2402
2412
uv_tty_reset_mode ();
2403
2413
}
0 commit comments