diff --git a/src/node.cc b/src/node.cc index 004fa99b03..36913eeadf 100644 --- a/src/node.cc +++ b/src/node.cc @@ -68,6 +68,8 @@ static Persistent listeners_symbol; static Persistent uncaught_exception_symbol; static Persistent emit_symbol; + +static char *eval_string = NULL; static int option_end_index = 0; static bool use_debug_agent = false; static bool debug_wait_connect = false; @@ -1608,6 +1610,11 @@ static void Load(int argc, char *argv[]) { process->Set(String::NewSymbol("pid"), Integer::New(getpid())); + // -e, --eval + if (eval_string) { + process->Set(String::NewSymbol("_eval"), String::New(eval_string)); + } + size_t size = 2*PATH_MAX; char execPath[size]; if (OS::GetExecutablePath(execPath, &size) != 0) { @@ -1751,6 +1758,13 @@ static void ParseArgs(int *argc, char **argv) { } else if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) { PrintHelp(); exit(0); + } else if (strcmp(arg, "--eval") == 0 || strcmp(arg, "-e") == 0) { + if (*argc <= i + 1) { + fprintf(stderr, "Error: --eval requires an argument\n"); + exit(1); + } + argv[i] = const_cast(""); + eval_string = argv[++i]; } else if (strcmp(arg, "--v8-options") == 0) { argv[i] = const_cast("--help"); } else if (argv[i][0] != '-') { diff --git a/src/node.js b/src/node.js index 7d177eb6ce..1ad5576bc9 100644 --- a/src/node.js +++ b/src/node.js @@ -577,17 +577,21 @@ if (process.argv[0].indexOf('/') > 0) { } if (process.argv[1]) { + // Load module if (process.argv[1].charAt(0) != "/" && !(/^http:\/\//).exec(process.argv[1])) { process.argv[1] = path.join(cwd, process.argv[1]); } - // REMOVEME: nextTick should not be necessary. This hack to get // test/simple/test-exception-handler2.js working. process.nextTick(function() { module.runMain(); }); + +} else if (process._eval) { + // -e, --eval + if (process._eval) console.log(eval(process._eval)); } else { - // No arguments, run the repl + // REPL module.requireNative('repl').start(); }