Added -e, --eval
This commit is contained in:
parent
5986a582d9
commit
9481bc1009
14
src/node.cc
14
src/node.cc
@ -68,6 +68,8 @@ static Persistent<String> listeners_symbol;
|
|||||||
static Persistent<String> uncaught_exception_symbol;
|
static Persistent<String> uncaught_exception_symbol;
|
||||||
static Persistent<String> emit_symbol;
|
static Persistent<String> emit_symbol;
|
||||||
|
|
||||||
|
|
||||||
|
static char *eval_string = NULL;
|
||||||
static int option_end_index = 0;
|
static int option_end_index = 0;
|
||||||
static bool use_debug_agent = false;
|
static bool use_debug_agent = false;
|
||||||
static bool debug_wait_connect = 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()));
|
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;
|
size_t size = 2*PATH_MAX;
|
||||||
char execPath[size];
|
char execPath[size];
|
||||||
if (OS::GetExecutablePath(execPath, &size) != 0) {
|
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) {
|
} else if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) {
|
||||||
PrintHelp();
|
PrintHelp();
|
||||||
exit(0);
|
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<char*>("");
|
||||||
|
eval_string = argv[++i];
|
||||||
} else if (strcmp(arg, "--v8-options") == 0) {
|
} else if (strcmp(arg, "--v8-options") == 0) {
|
||||||
argv[i] = const_cast<char*>("--help");
|
argv[i] = const_cast<char*>("--help");
|
||||||
} else if (argv[i][0] != '-') {
|
} else if (argv[i][0] != '-') {
|
||||||
|
@ -577,17 +577,21 @@ if (process.argv[0].indexOf('/') > 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv[1]) {
|
if (process.argv[1]) {
|
||||||
|
// Load module
|
||||||
if (process.argv[1].charAt(0) != "/" && !(/^http:\/\//).exec(process.argv[1])) {
|
if (process.argv[1].charAt(0) != "/" && !(/^http:\/\//).exec(process.argv[1])) {
|
||||||
process.argv[1] = path.join(cwd, process.argv[1]);
|
process.argv[1] = path.join(cwd, process.argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REMOVEME: nextTick should not be necessary. This hack to get
|
// REMOVEME: nextTick should not be necessary. This hack to get
|
||||||
// test/simple/test-exception-handler2.js working.
|
// test/simple/test-exception-handler2.js working.
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
module.runMain();
|
module.runMain();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} else if (process._eval) {
|
||||||
|
// -e, --eval
|
||||||
|
if (process._eval) console.log(eval(process._eval));
|
||||||
} else {
|
} else {
|
||||||
// No arguments, run the repl
|
// REPL
|
||||||
module.requireNative('repl').start();
|
module.requireNative('repl').start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user