From 78d33f4fd5a4d659caace216659fd3a311ac6fa3 Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Fri, 4 Jun 2010 08:29:10 -0700 Subject: [PATCH] Fix options parsing The current node has a bug where it will fail to pass the option argument immediately preceding the first non-option argument to V8. That is the --perf flag will be ignored by V8 when running 'node --perf script.js'. --- src/node.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/node.cc b/src/node.cc index 94229828336..824439d549c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1900,7 +1900,7 @@ static void Load(int argc, char *argv[]) { int i, j; Local arguments = Array::New(argc - option_end_index + 1); arguments->Set(Integer::New(0), String::New(argv[0])); - for (j = 1, i = option_end_index + 1; i < argc; j++, i++) { + for (j = 1, i = option_end_index; i < argc; j++, i++) { Local arg = String::New(argv[i]); arguments->Set(Integer::New(j), arg); } @@ -2050,13 +2050,14 @@ static void PrintHelp() { // Parse node command line arguments. static void ParseArgs(int *argc, char **argv) { + int i; + // TODO use parse opts - for (int i = 1; i < *argc; i++) { + for (i = 1; i < *argc; i++) { const char *arg = argv[i]; if (strstr(arg, "--debug") == arg) { ParseDebugOpt(arg); argv[i] = const_cast(""); - option_end_index = i; } else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) { printf("%s\n", NODE_VERSION); exit(0); @@ -2069,12 +2070,12 @@ static void ParseArgs(int *argc, char **argv) { exit(0); } else if (strcmp(arg, "--v8-options") == 0) { argv[i] = const_cast("--help"); - option_end_index = i+1; } else if (argv[i][0] != '-') { - option_end_index = i-1; break; } } + + option_end_index = i; } } // namespace node