Browse Source

print warning on process.ENV

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
ea9006a5bc
  1. 33
      src/node.cc

33
src/node.cc

@ -1531,6 +1531,17 @@ static Handle<Value> EnvGetter(Local<String> property,
} }
static bool ENV_warning = false;
static Handle<Value> EnvGetterWarn(Local<String> property,
const AccessorInfo& info) {
if (!ENV_warning) {
ENV_warning = true;
fprintf(stderr, "(node) Use process.env instead of process.ENV\r\n");
}
return EnvGetter(property, info);
}
static Handle<Value> EnvSetter(Local<String> property, static Handle<Value> EnvSetter(Local<String> property,
Local<Value> value, Local<Value> value,
const AccessorInfo& info) { const AccessorInfo& info) {
@ -1630,13 +1641,27 @@ static void Load(int argc, char *argv[]) {
// create process.env // create process.env
Local<ObjectTemplate> envTemplate = ObjectTemplate::New(); Local<ObjectTemplate> envTemplate = ObjectTemplate::New();
envTemplate->SetNamedPropertyHandler(EnvGetter, EnvSetter, EnvQuery, EnvDeleter, EnvEnumerator, Undefined()); envTemplate->SetNamedPropertyHandler(EnvGetter,
EnvSetter,
// assign process.ENV EnvQuery,
EnvDeleter,
EnvEnumerator,
Undefined());
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("env"), env);
// create process.ENV
// TODO: remove me at some point.
Local<ObjectTemplate> ENVTemplate = ObjectTemplate::New();
ENVTemplate->SetNamedPropertyHandler(EnvGetterWarn,
EnvSetter,
EnvQuery,
EnvDeleter,
EnvEnumerator,
Undefined());
Local<Object> ENV = ENVTemplate->NewInstance();
process->Set(String::NewSymbol("ENV"), ENV);
process->Set(String::NewSymbol("pid"), Integer::New(getpid())); process->Set(String::NewSymbol("pid"), Integer::New(getpid()));
// -e, --eval // -e, --eval

Loading…
Cancel
Save