Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added -e, --eval

  • Loading branch information...
commit 08f1bf42bbb8a005a73c098ffb6ad423a504f134 1 parent 18ff6db
@tjholowaychuk tjholowaychuk authored ry committed
Showing with 20 additions and 2 deletions.
  1. +14 −0 src/node.cc
  2. +6 −2 src/node.js
View
14 src/node.cc
@@ -68,6 +68,8 @@ static Persistent<String> listeners_symbol;
static Persistent<String> uncaught_exception_symbol;
static Persistent<String> 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;
@@ -1612,6 +1614,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) {
@@ -1764,6 +1771,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<char*>("");
+ eval_string = argv[++i];
} else if (strcmp(arg, "--v8-options") == 0) {
argv[i] = const_cast<char*>("--help");
} else if (argv[i][0] != '-') {
View
8 src/node.js
@@ -746,17 +746,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();
}
Please sign in to comment.
Something went wrong with that request. Please try again.