From ea9006a5bcd4e56313d7b5d18c5f585011d2d123 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 2 Dec 2010 15:59:35 -0800 Subject: [PATCH] print warning on process.ENV --- src/node.cc | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/node.cc b/src/node.cc index 9736df5df4..fa80180836 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1531,6 +1531,17 @@ static Handle EnvGetter(Local property, } +static bool ENV_warning = false; +static Handle EnvGetterWarn(Local 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 EnvSetter(Local property, Local value, const AccessorInfo& info) { @@ -1630,13 +1641,27 @@ static void Load(int argc, char *argv[]) { // create process.env Local envTemplate = ObjectTemplate::New(); - envTemplate->SetNamedPropertyHandler(EnvGetter, EnvSetter, EnvQuery, EnvDeleter, EnvEnumerator, Undefined()); - - // assign process.ENV + envTemplate->SetNamedPropertyHandler(EnvGetter, + EnvSetter, + EnvQuery, + EnvDeleter, + EnvEnumerator, + Undefined()); Local env = envTemplate->NewInstance(); - process->Set(String::NewSymbol("ENV"), env); process->Set(String::NewSymbol("env"), env); + // create process.ENV + // TODO: remove me at some point. + Local ENVTemplate = ObjectTemplate::New(); + ENVTemplate->SetNamedPropertyHandler(EnvGetterWarn, + EnvSetter, + EnvQuery, + EnvDeleter, + EnvEnumerator, + Undefined()); + Local ENV = ENVTemplate->NewInstance(); + process->Set(String::NewSymbol("ENV"), ENV); + process->Set(String::NewSymbol("pid"), Integer::New(getpid())); // -e, --eval