Browse Source

process: set key properties as ReadOnly

v0.11.5-release
Trevor Norris 12 years ago
parent
commit
c80f8fa8f1
  1. 60
      src/node.cc

60
src/node.cc

@ -2199,6 +2199,12 @@ static void NeedImmediateCallbackSetter(Local<String> property,
} }
#define READONLY_PROPERTY(obj, str, var) \
do { \
obj->Set(String::New(str), var, v8::ReadOnly); \
} while (0)
Handle<Object> SetupProcessObject(int argc, char *argv[]) { Handle<Object> SetupProcessObject(int argc, char *argv[]) {
HandleScope scope(node_isolate); HandleScope scope(node_isolate);
@ -2218,27 +2224,27 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
ProcessTitleSetter); ProcessTitleSetter);
// process.version // process.version
process->Set(String::NewSymbol("version"), String::New(NODE_VERSION)); READONLY_PROPERTY(process, "version", String::New(NODE_VERSION));
// process.moduleLoadList // process.moduleLoadList
Local<Array> modules = Array::New(); Local<Array> modules = Array::New();
module_load_list.Reset(node_isolate, modules); module_load_list.Reset(node_isolate, modules);
process->Set(String::NewSymbol("moduleLoadList"), modules); READONLY_PROPERTY(process, "moduleLoadList", modules);
// process.versions // process.versions
Local<Object> versions = Object::New(); Local<Object> versions = Object::New();
process->Set(String::NewSymbol("versions"), versions); READONLY_PROPERTY(process, "versions", versions);
versions->Set(String::NewSymbol("http_parser"), String::New( READONLY_PROPERTY(versions, "http_parser", String::New(
NODE_STRINGIFY(HTTP_PARSER_VERSION_MAJOR) "." NODE_STRINGIFY(HTTP_PARSER_VERSION_MAJOR) "."
NODE_STRINGIFY(HTTP_PARSER_VERSION_MINOR))); NODE_STRINGIFY(HTTP_PARSER_VERSION_MINOR)));
// +1 to get rid of the leading 'v' // +1 to get rid of the leading 'v'
versions->Set(String::NewSymbol("node"), String::New(NODE_VERSION+1)); READONLY_PROPERTY(versions, "node", String::New(NODE_VERSION+1));
versions->Set(String::NewSymbol("v8"), String::New(V8::GetVersion())); READONLY_PROPERTY(versions, "v8", String::New(V8::GetVersion()));
versions->Set(String::NewSymbol("ares"), String::New(ARES_VERSION_STR)); READONLY_PROPERTY(versions, "uv", String::New(uv_version_string()));
versions->Set(String::NewSymbol("uv"), String::New(uv_version_string())); READONLY_PROPERTY(versions, "zlib", String::New(ZLIB_VERSION));
versions->Set(String::NewSymbol("zlib"), String::New(ZLIB_VERSION)); READONLY_PROPERTY(versions,
versions->Set(String::NewSymbol("modules"), "modules",
String::New(NODE_STRINGIFY(NODE_MODULE_VERSION))); String::New(NODE_STRINGIFY(NODE_MODULE_VERSION)));
#if HAVE_OPENSSL #if HAVE_OPENSSL
// Stupid code to slice out the version string. // Stupid code to slice out the version string.
int c, l = strlen(OPENSSL_VERSION_TEXT); int c, l = strlen(OPENSSL_VERSION_TEXT);
@ -2252,17 +2258,18 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
break; break;
} }
} }
versions->Set(String::NewSymbol("openssl"), READONLY_PROPERTY(versions,
String::New(&OPENSSL_VERSION_TEXT[i], j - i)); "openssl",
String::New(&OPENSSL_VERSION_TEXT[i], j - i));
#endif #endif
// process.arch // process.arch
process->Set(String::NewSymbol("arch"), String::New(ARCH)); READONLY_PROPERTY(process, "arch", String::New(ARCH));
// process.platform // process.platform
process->Set(String::NewSymbol("platform"), String::New(PLATFORM)); READONLY_PROPERTY(process, "platform", String::New(PLATFORM));
// process.argv // process.argv
Local<Array> arguments = Array::New(argc - option_end_index + 1); Local<Array> arguments = Array::New(argc - option_end_index + 1);
@ -2294,40 +2301,40 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
Local<Object> env = envTemplate->NewInstance(); Local<Object> env = envTemplate->NewInstance();
process->Set(String::NewSymbol("env"), env); process->Set(String::NewSymbol("env"), env);
process->Set(String::NewSymbol("pid"), Integer::New(getpid(), node_isolate)); READONLY_PROPERTY(process, "pid", Integer::New(getpid(), node_isolate));
process->Set(String::NewSymbol("features"), GetFeatures()); READONLY_PROPERTY(process, "features", GetFeatures());
process->SetAccessor(String::New("_needImmediateCallback"), process->SetAccessor(String::New("_needImmediateCallback"),
NeedImmediateCallbackGetter, NeedImmediateCallbackGetter,
NeedImmediateCallbackSetter); NeedImmediateCallbackSetter);
// -e, --eval // -e, --eval
if (eval_string) { if (eval_string) {
process->Set(String::NewSymbol("_eval"), String::New(eval_string)); READONLY_PROPERTY(process, "_eval", String::New(eval_string));
} }
// -p, --print // -p, --print
if (print_eval) { if (print_eval) {
process->Set(String::NewSymbol("_print_eval"), True(node_isolate)); READONLY_PROPERTY(process, "_print_eval", True(node_isolate));
} }
// -i, --interactive // -i, --interactive
if (force_repl) { if (force_repl) {
process->Set(String::NewSymbol("_forceRepl"), True(node_isolate)); READONLY_PROPERTY(process, "_forceRepl", True(node_isolate));
} }
// --no-deprecation // --no-deprecation
if (no_deprecation) { if (no_deprecation) {
process->Set(String::NewSymbol("noDeprecation"), True(node_isolate)); READONLY_PROPERTY(process, "noDeprecation", True(node_isolate));
} }
// --throw-deprecation // --throw-deprecation
if (throw_deprecation) { if (throw_deprecation) {
process->Set(String::NewSymbol("throwDeprecation"), True(node_isolate)); READONLY_PROPERTY(process, "throwDeprecation", True(node_isolate));
} }
// --trace-deprecation // --trace-deprecation
if (trace_deprecation) { if (trace_deprecation) {
process->Set(String::NewSymbol("traceDeprecation"), True(node_isolate)); READONLY_PROPERTY(process, "traceDeprecation", True(node_isolate));
} }
size_t size = 2*PATH_MAX; size_t size = 2*PATH_MAX;
@ -2398,6 +2405,9 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
} }
#undef READONLY_PROPERTY
static void AtExit() { static void AtExit() {
uv_tty_reset_mode(); uv_tty_reset_mode();
} }

Loading…
Cancel
Save