summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvan Lucas <evanlucas@me.com>2015-06-01 09:15:10 -0500
committerEvan Lucas <evanlucas@me.com>2015-06-01 11:25:32 -0500
commit5b6f575c1f5d4b82e03e2a78066b7707747e110e (patch)
tree229a072c17b64b9811d6b43cb5ea0a8d6f71b5e8 /src
parentc0e7bf2d8ceb65ad3840bc4ebf3cbd9fef8e8c14 (diff)
downloadandroid-node-v8-5b6f575c1f5d4b82e03e2a78066b7707747e110e.tar.gz
android-node-v8-5b6f575c1f5d4b82e03e2a78066b7707747e110e.tar.bz2
android-node-v8-5b6f575c1f5d4b82e03e2a78066b7707747e110e.zip
Revert "src: add getopt option parser"
This reverts commit c0e7bf2d8ceb65ad3840bc4ebf3cbd9fef8e8c14. There are a few edge cases that can cause a crash and need to be properly handled. PR-URL: https://github.com/nodejs/io.js/pull/1862 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src')
-rw-r--r--src/node.cc314
-rw-r--r--src/node_options.cc305
-rw-r--r--src/node_options.h62
3 files changed, 275 insertions, 406 deletions
diff --git a/src/node.cc b/src/node.cc
index 01136890ab..f47dd72205 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -4,7 +4,6 @@
#include "node_file.h"
#include "node_http_parser.h"
#include "node_javascript.h"
-#include "node_options.h"
#include "node_version.h"
#if defined HAVE_PERFCTR
@@ -112,6 +111,18 @@ using v8::V8;
using v8::Value;
using v8::kExternalUint32Array;
+static bool print_eval = false;
+static bool force_repl = false;
+static bool trace_deprecation = false;
+static bool throw_deprecation = false;
+static bool abort_on_uncaught_exception = false;
+static bool trace_sync_io = false;
+static const char* eval_string = nullptr;
+static unsigned int preload_module_count = 0;
+static const char** preload_modules = nullptr;
+static bool use_debug_agent = false;
+static bool debug_wait_connect = false;
+static int debug_port = 5858;
static bool v8_is_profiling = false;
static bool node_is_initialized = false;
static node_module* modpending;
@@ -119,8 +130,10 @@ static node_module* modlist_builtin;
static node_module* modlist_linked;
static node_module* modlist_addon;
-// cli options
-NodeOptions node_options;
+#if defined(NODE_HAVE_I18N_SUPPORT)
+// Path to ICU data (for i18n / Intl)
+static const char* icu_data_dir = nullptr;
+#endif
// used by C++ modules as well
bool no_deprecation = false;
@@ -1253,13 +1266,13 @@ enum encoding ParseEncoding(const char* encoding,
} else if (strcasecmp(encoding, "hex") == 0) {
return HEX;
} else if (strcasecmp(encoding, "raw") == 0) {
- if (!node_options.no_deprecation) {
+ if (!no_deprecation) {
fprintf(stderr, "'raw' (array of integers) has been removed. "
"Use 'binary'.\n");
}
return BINARY;
} else if (strcasecmp(encoding, "raws") == 0) {
- if (!node_options.no_deprecation) {
+ if (!no_deprecation) {
fprintf(stderr, "'raws' encoding has been renamed to 'binary'. "
"Please update your code.\n");
}
@@ -2535,14 +2548,14 @@ static Handle<Object> GetFeatures(Environment* env) {
static void DebugPortGetter(Local<String> property,
const PropertyCallbackInfo<Value>& info) {
- info.GetReturnValue().Set(node_options.debug_port);
+ info.GetReturnValue().Set(debug_port);
}
static void DebugPortSetter(Local<String> property,
Local<Value> value,
const PropertyCallbackInfo<void>& info) {
- node_options.debug_port = value->Int32Value();
+ debug_port = value->Int32Value();
}
@@ -2776,58 +2789,56 @@ void SetupProcessObject(Environment* env,
env->as_external());
// -e, --eval
- if (node_options.eval_string) {
+ if (eval_string) {
READONLY_PROPERTY(process,
"_eval",
- String::NewFromUtf8(env->isolate(),
- node_options.eval_string));
+ String::NewFromUtf8(env->isolate(), eval_string));
}
// -p, --print
- if (node_options.print_eval) {
+ if (print_eval) {
READONLY_PROPERTY(process, "_print_eval", True(env->isolate()));
}
// -i, --interactive
- if (node_options.force_repl) {
+ if (force_repl) {
READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
}
- if (node_options.preload_module_count) {
- CHECK(node_options.preload_modules);
+ if (preload_module_count) {
+ CHECK(preload_modules);
Local<Array> array = Array::New(env->isolate());
- for (unsigned int i = 0; i < node_options.preload_module_count; ++i) {
- Local<String> module = String::NewFromUtf8(
- env->isolate(),
- node_options.preload_modules[i]);
+ for (unsigned int i = 0; i < preload_module_count; ++i) {
+ Local<String> module = String::NewFromUtf8(env->isolate(),
+ preload_modules[i]);
array->Set(i, module);
}
READONLY_PROPERTY(process,
"_preload_modules",
array);
- delete[] node_options.preload_modules;
- node_options.preload_modules = nullptr;
- node_options.preload_module_count = 0;
+ delete[] preload_modules;
+ preload_modules = nullptr;
+ preload_module_count = 0;
}
// --no-deprecation
- if (node_options.no_deprecation) {
+ if (no_deprecation) {
READONLY_PROPERTY(process, "noDeprecation", True(env->isolate()));
}
// --throw-deprecation
- if (node_options.throw_deprecation) {
+ if (throw_deprecation) {
READONLY_PROPERTY(process, "throwDeprecation", True(env->isolate()));
}
// --trace-deprecation
- if (node_options.trace_deprecation) {
+ if (trace_deprecation) {
READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
}
// --trace-sync-io
- if (node_options.trace_sync_io) {
+ if (trace_sync_io) {
READONLY_PROPERTY(process, "traceSyncIO", True(env->isolate()));
// Don't env->set_trace_sync_io(true) because it will be enabled
// after LoadEnvironment() has run.
@@ -3009,6 +3020,235 @@ void LoadEnvironment(Environment* env) {
f->Call(global, 1, &arg);
}
+static void PrintHelp();
+
+static bool ParseDebugOpt(const char* arg) {
+ const char* port = nullptr;
+
+ if (!strcmp(arg, "--debug")) {
+ use_debug_agent = true;
+ } else if (!strncmp(arg, "--debug=", sizeof("--debug=") - 1)) {
+ use_debug_agent = true;
+ port = arg + sizeof("--debug=") - 1;
+ } else if (!strcmp(arg, "--debug-brk")) {
+ use_debug_agent = true;
+ debug_wait_connect = true;
+ } else if (!strncmp(arg, "--debug-brk=", sizeof("--debug-brk=") - 1)) {
+ use_debug_agent = true;
+ debug_wait_connect = true;
+ port = arg + sizeof("--debug-brk=") - 1;
+ } else if (!strncmp(arg, "--debug-port=", sizeof("--debug-port=") - 1)) {
+ port = arg + sizeof("--debug-port=") - 1;
+ } else {
+ return false;
+ }
+
+ if (port != nullptr) {
+ debug_port = atoi(port);
+ if (debug_port < 1024 || debug_port > 65535) {
+ fprintf(stderr, "Debug port must be in range 1024 to 65535.\n");
+ PrintHelp();
+ exit(12);
+ }
+ }
+
+ return true;
+}
+
+static void PrintHelp() {
+ printf("Usage: iojs [options] [ -e script | script.js ] [arguments] \n"
+ " iojs debug script.js [arguments] \n"
+ "\n"
+ "Options:\n"
+ " -v, --version print io.js version\n"
+ " -e, --eval script evaluate script\n"
+ " -p, --print evaluate script and print result\n"
+ " -i, --interactive always enter the REPL even if stdin\n"
+ " does not appear to be a terminal\n"
+ " -r, --require module to preload (option can be repeated)\n"
+ " --no-deprecation silence deprecation warnings\n"
+ " --throw-deprecation throw an exception anytime a deprecated "
+ "function is used\n"
+ " --trace-deprecation show stack traces on deprecations\n"
+ " --trace-sync-io show stack trace when use of sync IO\n"
+ " is detected after the first tick\n"
+ " --v8-options print v8 command line options\n"
+#if defined(NODE_HAVE_I18N_SUPPORT)
+ " --icu-data-dir=dir set ICU data load path to dir\n"
+ " (overrides NODE_ICU_DATA)\n"
+#if !defined(NODE_HAVE_SMALL_ICU)
+ " Note: linked-in ICU data is\n"
+ " present.\n"
+#endif
+#endif
+ "\n"
+ "Environment variables:\n"
+#ifdef _WIN32
+ "NODE_PATH ';'-separated list of directories\n"
+#else
+ "NODE_PATH ':'-separated list of directories\n"
+#endif
+ " prefixed to the module search path.\n"
+ "NODE_DISABLE_COLORS Set to 1 to disable colors in the REPL\n"
+#if defined(NODE_HAVE_I18N_SUPPORT)
+ "NODE_ICU_DATA Data path for ICU (Intl object) data\n"
+#if !defined(NODE_HAVE_SMALL_ICU)
+ " (will extend linked-in data)\n"
+#endif
+#endif
+ "\n"
+ "Documentation can be found at https://iojs.org/\n");
+}
+
+
+// Parse command line arguments.
+//
+// argv is modified in place. exec_argv and v8_argv are out arguments that
+// ParseArgs() allocates memory for and stores a pointer to the output
+// vector in. The caller should free them with delete[].
+//
+// On exit:
+//
+// * argv contains the arguments with node and V8 options filtered out.
+// * exec_argv contains both node and V8 options and nothing else.
+// * v8_argv contains argv[0] plus any V8 options
+static void ParseArgs(int* argc,
+ const char** argv,
+ int* exec_argc,
+ const char*** exec_argv,
+ int* v8_argc,
+ const char*** v8_argv) {
+ const unsigned int nargs = static_cast<unsigned int>(*argc);
+ const char** new_exec_argv = new const char*[nargs];
+ const char** new_v8_argv = new const char*[nargs];
+ const char** new_argv = new const char*[nargs];
+ const char** local_preload_modules = new const char*[nargs];
+
+ for (unsigned int i = 0; i < nargs; ++i) {
+ new_exec_argv[i] = nullptr;
+ new_v8_argv[i] = nullptr;
+ new_argv[i] = nullptr;
+ local_preload_modules[i] = nullptr;
+ }
+
+ // exec_argv starts with the first option, the other two start with argv[0].
+ unsigned int new_exec_argc = 0;
+ unsigned int new_v8_argc = 1;
+ unsigned int new_argc = 1;
+ new_v8_argv[0] = argv[0];
+ new_argv[0] = argv[0];
+
+ unsigned int index = 1;
+ while (index < nargs && argv[index][0] == '-') {
+ const char* const arg = argv[index];
+ unsigned int args_consumed = 1;
+
+ if (ParseDebugOpt(arg)) {
+ // Done, consumed by ParseDebugOpt().
+ } else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) {
+ printf("%s\n", NODE_VERSION);
+ exit(0);
+ } else if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) {
+ PrintHelp();
+ exit(0);
+ } else if (strcmp(arg, "--eval") == 0 ||
+ strcmp(arg, "-e") == 0 ||
+ strcmp(arg, "--print") == 0 ||
+ strcmp(arg, "-pe") == 0 ||
+ strcmp(arg, "-p") == 0) {
+ bool is_eval = strchr(arg, 'e') != nullptr;
+ bool is_print = strchr(arg, 'p') != nullptr;
+ print_eval = print_eval || is_print;
+ // --eval, -e and -pe always require an argument.
+ if (is_eval == true) {
+ args_consumed += 1;
+ eval_string = argv[index + 1];
+ if (eval_string == nullptr) {
+ fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg);
+ exit(9);
+ }
+ } else if ((index + 1 < nargs) &&
+ argv[index + 1] != nullptr &&
+ argv[index + 1][0] != '-') {
+ args_consumed += 1;
+ eval_string = argv[index + 1];
+ if (strncmp(eval_string, "\\-", 2) == 0) {
+ // Starts with "\\-": escaped expression, drop the backslash.
+ eval_string += 1;
+ }
+ }
+ } else if (strcmp(arg, "--require") == 0 ||
+ strcmp(arg, "-r") == 0) {
+ const char* module = argv[index + 1];
+ if (module == nullptr) {
+ fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg);
+ exit(9);
+ }
+ args_consumed += 1;
+ local_preload_modules[preload_module_count++] = module;
+ } else if (strcmp(arg, "--interactive") == 0 || strcmp(arg, "-i") == 0) {
+ force_repl = true;
+ } else if (strcmp(arg, "--no-deprecation") == 0) {
+ no_deprecation = true;
+ } else if (strcmp(arg, "--trace-deprecation") == 0) {
+ trace_deprecation = true;
+ } else if (strcmp(arg, "--trace-sync-io") == 0) {
+ trace_sync_io = true;
+ } else if (strcmp(arg, "--throw-deprecation") == 0) {
+ throw_deprecation = true;
+ } else if (strcmp(arg, "--abort-on-uncaught-exception") == 0 ||
+ strcmp(arg, "--abort_on_uncaught_exception") == 0) {
+ abort_on_uncaught_exception = true;
+ } else if (strcmp(arg, "--v8-options") == 0) {
+ new_v8_argv[new_v8_argc] = "--help";
+ new_v8_argc += 1;
+#if defined(NODE_HAVE_I18N_SUPPORT)
+ } else if (strncmp(arg, "--icu-data-dir=", 15) == 0) {
+ icu_data_dir = arg + 15;
+#endif
+ } else if (strcmp(arg, "--expose-internals") == 0 ||
+ strcmp(arg, "--expose_internals") == 0) {
+ // consumed in js
+ } else {
+ // V8 option. Pass through as-is.
+ new_v8_argv[new_v8_argc] = arg;
+ new_v8_argc += 1;
+ }
+
+ memcpy(new_exec_argv + new_exec_argc,
+ argv + index,
+ args_consumed * sizeof(*argv));
+
+ new_exec_argc += args_consumed;
+ index += args_consumed;
+ }
+
+ // Copy remaining arguments.
+ const unsigned int args_left = nargs - index;
+ memcpy(new_argv + new_argc, argv + index, args_left * sizeof(*argv));
+ new_argc += args_left;
+
+ *exec_argc = new_exec_argc;
+ *exec_argv = new_exec_argv;
+ *v8_argc = new_v8_argc;
+ *v8_argv = new_v8_argv;
+
+ // Copy new_argv over argv and update argc.
+ memcpy(argv, new_argv, new_argc * sizeof(*argv));
+ delete[] new_argv;
+ *argc = static_cast<int>(new_argc);
+
+ // Copy the preload_modules from the local array to an appropriately sized
+ // global array.
+ if (preload_module_count > 0) {
+ CHECK(!preload_modules);
+ preload_modules = new const char*[preload_module_count];
+ memcpy(preload_modules, local_preload_modules,
+ preload_module_count * sizeof(*preload_modules));
+ }
+ delete[] local_preload_modules;
+}
+
// Called from V8 Debug Agent TCP thread.
static void DispatchMessagesDebugAgentCallback(Environment* env) {
@@ -3022,12 +3262,9 @@ static void StartDebug(Environment* env, bool wait) {
env->debugger_agent()->set_dispatch_handler(
DispatchMessagesDebugAgentCallback);
- debugger_running = env->debugger_agent()->Start(node_options.debug_port,
- wait);
+ debugger_running = env->debugger_agent()->Start(debug_port, wait);
if (debugger_running == false) {
- fprintf(stderr,
- "Starting debugger on port %d failed\n",
- node_options.debug_port);
+ fprintf(stderr, "Starting debugger on port %d failed\n", debug_port);
fflush(stderr);
return;
}
@@ -3397,8 +3634,8 @@ void Init(int* argc,
// Parse a few arguments which are specific to Node.
int v8_argc;
const char** v8_argv;
- node_options.ParseArgs(argc, argv, exec_argc, exec_argv, &v8_argc, &v8_argv);
- no_deprecation = node_options.no_deprecation;
+ ParseArgs(argc, argv, exec_argc, exec_argv, &v8_argc, &v8_argv);
+
// TODO(bnoordhuis) Intercept --prof arguments and start the CPU profiler
// manually? That would give us a little more control over its runtime
// behavior but it could also interfere with the user's intentions in ways
@@ -3437,14 +3674,14 @@ void Init(int* argc,
exit(9);
}
- if (node_options.debug_wait_connect) {
+ if (debug_wait_connect) {
const char expose_debug_as[] = "--expose_debug_as=v8debug";
V8::SetFlagsFromString(expose_debug_as, sizeof(expose_debug_as) - 1);
}
V8::SetArrayBufferAllocator(&ArrayBufferAllocator::the_singleton);
- if (!node_options.use_debug_agent) {
+ if (!use_debug_agent) {
RegisterDebugSignalHandler();
}
@@ -3657,15 +3894,14 @@ static void StartNodeInstance(void* arg) {
Environment* env = CreateEnvironment(isolate, context, instance_data);
Context::Scope context_scope(context);
if (instance_data->is_main())
- env->set_using_abort_on_uncaught_exc(
- node_options.abort_on_uncaught_exception);
+ env->set_using_abort_on_uncaught_exc(abort_on_uncaught_exception);
// Start debug agent when argv has --debug
if (instance_data->use_debug_agent())
- StartDebug(env, node_options.debug_wait_connect);
+ StartDebug(env, debug_wait_connect);
LoadEnvironment(env);
- env->set_trace_sync_io(node_options.trace_sync_io);
+ env->set_trace_sync_io(trace_sync_io);
// Enable debugger
if (instance_data->use_debug_agent())
@@ -3742,7 +3978,7 @@ int Start(int argc, char** argv) {
const_cast<const char**>(argv),
exec_argc,
exec_argv,
- node_options.use_debug_agent);
+ use_debug_agent);
StartNodeInstance(&instance_data);
exit_code = instance_data.exit_code();
}
diff --git a/src/node_options.cc b/src/node_options.cc
deleted file mode 100644
index 276c5cd327..0000000000
--- a/src/node_options.cc
+++ /dev/null
@@ -1,305 +0,0 @@
-#include "node_options.h"
-#include "node_version.h"
-#include "node_internals.h"
-#include "getopt.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-namespace node {
-
-enum {
- OPT_NO_DEPRECATION = 1000,
- OPT_THROW_DEPRECATION,
- OPT_TRACE_DEPRECATION,
- OPT_TRACE_SYNC_IO,
- OPT_V8_OPTIONS,
- OPT_ABORT_UNCAUGHT,
- OPT_EXPOSE_INTERNALS,
- OPT_DEBUG,
- OPT_DEBUG_BRK,
- OPT_DEBUG_PORT,
-#if defined(NODE_HAVE_I18N_SUPPORT)
- OPT_ICU_DATA_DIR
-#endif
-};
-
-static struct option longopts[] = {
- { "help", no_argument, nullptr, 'h', "show help and usage" },
- { "version", no_argument, nullptr, 'v', "print io.js version" },
- { "eval", optional_argument, nullptr, 'e', "evaluate script" },
- { "print", optional_argument, nullptr, 'p',
- "evaluate script and print result" },
- { "interactive", no_argument, nullptr, 'i',
- "always enter the REPL even if stdin "
- "does not appear to be a terminal" },
- { "require", required_argument, nullptr, 'r', "module to preload" },
- { "no-deprecation", no_argument, nullptr, OPT_NO_DEPRECATION,
- "silence deprecation warnings" },
- { "throw-deprecation", no_argument, nullptr, OPT_THROW_DEPRECATION,
- "throw an exception anytime a deprecated function is used" },
- { "trace-deprecation", no_argument, nullptr, OPT_TRACE_DEPRECATION,
- "show stack traces on deprecations" },
- { "trace-sync-io", no_argument, nullptr, OPT_TRACE_SYNC_IO,
- "show stake trace when use of sync IO "
- "is detected after the first tick" },
- { "v8-options", no_argument, nullptr, OPT_V8_OPTIONS,
- "print v8 command line options" },
- { "v8_options", no_argument, nullptr, OPT_V8_OPTIONS,
- "print v8 command line options" },
- { "abort-on-uncaught-exception", no_argument, nullptr, OPT_ABORT_UNCAUGHT,
- "abort on uncaught exception" },
- { "abort_on_uncaught_exception", no_argument, nullptr, OPT_ABORT_UNCAUGHT,
- "abort on uncaught exception" },
- { "expose-internals", no_argument, nullptr, OPT_EXPOSE_INTERNALS,
- "expose internal modules" },
- { "expose_internals", no_argument, nullptr, OPT_EXPOSE_INTERNALS,
- "expose internal modules" },
- { "debug", optional_argument, nullptr, OPT_DEBUG, "enable debug mode" },
- { "debug-brk", optional_argument, nullptr, OPT_DEBUG_BRK,
- "break before starting" },
- { "debug-port", required_argument, nullptr, OPT_DEBUG_PORT,
- "specify debug port (defaults to 5858)" },
-#if defined(NODE_HAVE_I18N_SUPPORT)
- { "icu-data-dir", required_argument, nullptr, OPT_ICU_DATA_DIR },
-#endif
- { nullptr, 0, nullptr, 0, "" }
-};
-
-void NodeOptions::PrintHelp() {
- printf("Usage: iojs [options] [ -e script | script.js ] [arguments] \n"
- " iojs debug script.js [arguments] \n"
- "\n"
- "Options:\n");
- for (size_t i = 0; i < ARRAY_SIZE(longopts); i++) {
- if (longopts[i].name == nullptr)
- continue;
- if (longopts[i].val < 1000) {
- printf("\t-%c, --%-30s %-50s\n",
- longopts[i].val,
- longopts[i].name,
- longopts[i].desc);
- } else {
- printf("\t --%-30s %-50s\n", longopts[i].name, longopts[i].desc);
- }
- }
-
- printf("\n");
-
- printf("Environment variables:\n"
-#ifdef _WIN32
- "\t NODE_PATH ';'-separated list of directories\n"
-#else
- "\t NODE_PATH ':'-separated list of directories\n"
-#endif
- "\t prefixed to the module search path.\n"
- "\t NODE_DISABLE_COLORS Set to 1 to disable colors in the REPL\n"
-#if defined(NODE_HAVE_I18N_SUPPORT)
- "\t NODE_ICU_DATA Data path for ICU (Intl object) data\n"
-#if !defined(NODE_HAVE_SMALL_ICU)
- "\t (will extend linked-in data)\n"
-#endif
-#endif
- "\n"
- "Documentation can be found at https://iojs.org/\n");
-}
-
-void NodeOptions::ParseArgs(int* argc,
- const char** argv,
- int* exec_argc,
- const char*** exec_argv,
- int* v8_argc,
- const char*** v8_argv) {
- const unsigned int nargs = static_cast<unsigned int>(*argc);
- const char** new_exec_argv = new const char*[nargs];
- const char** new_v8_argv = new const char*[nargs];
- const char** new_argv = new const char*[nargs];
- const char** local_preload_modules = new const char*[nargs];
-
- // we are mutating the strings vector but not the strings themselves
- char** largv = const_cast<char**>(argv);
- for (unsigned int i = 0; i < nargs; ++i) {
- new_exec_argv[i] = nullptr;
- new_v8_argv[i] = nullptr;
- new_argv[i] = nullptr;
- local_preload_modules[i] = nullptr;
- }
-
- const char* port = nullptr;
-
- // exec_argv starts with the first option, the other two start with argv[0].
- unsigned int new_exec_argc = 0;
- unsigned int new_v8_argc = 1;
- unsigned int new_argc = 1;
- new_v8_argv[0] = argv[0];
- new_argv[0] = argv[0];
- int rc = 0;
- unsigned int index = 1;
- bool is_eval = false;
- bool is_print = false;
- const char optstring[] = ":hve:p::ir:d::b::x:";
- while ((rc = getopt_long(*argc, largv, optstring, longopts, NULL)) != -1 &&
- argv[index][0] == '-') {
- unsigned int args_consumed = 1;
- const char* const arg = argv[index];
- switch (rc) {
- case 'h':
- PrintHelp();
- exit(0);
- break;
- case 'v':
- printf("%s\n", NODE_VERSION);
- exit(0);
- break;
- case 'e':
- case 'p':
- {
- if (!is_eval)
- is_eval = (rc == 'e');
-
- if (!is_print)
- is_print = (rc == 'p');
- const char* name = is_eval ? "eval" : "print";
- print_eval = print_eval || is_print;
- if (is_eval == true) {
- eval_string = argv[index + 1];
- args_consumed += 1;
- if (eval_string == nullptr) {
- fprintf(stderr, "%s: %s requires an argument\n", argv[0], name);
- exit(9);
- }
- } else if ((index + 1 < nargs) &&
- argv[index + 1] != nullptr &&
- argv[index + 1][0] != '-') {
- eval_string = argv[index + 1];
- args_consumed += 1;
- if (strncmp(eval_string, "\\-", 2) == 0) {
- // Starts with "\\-": escaped expression, drop the backslash.
- eval_string += 1;
- }
- }
- break;
- }
- case 'i':
- force_repl = true;
- break;
- case 'r':
- {
- const char* module = argv[index + 1];
- args_consumed += 1;
- if (module == nullptr) {
- fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg);
- exit(9);
- }
- local_preload_modules[preload_module_count++] = module;
- break;
- }
- case OPT_NO_DEPRECATION:
- no_deprecation = true;
- break;
- case OPT_THROW_DEPRECATION:
- throw_deprecation = true;
- break;
- case OPT_TRACE_DEPRECATION:
- trace_deprecation = true;
- break;
- case OPT_TRACE_SYNC_IO:
- trace_sync_io = true;
- break;
- case OPT_V8_OPTIONS:
- new_v8_argv[new_v8_argc] = "--help";
- new_v8_argc += 1;
- break;
- case OPT_ABORT_UNCAUGHT:
- abort_on_uncaught_exception = true;
- break;
- case OPT_EXPOSE_INTERNALS:
- // pass through
- break;
- case OPT_DEBUG:
- {
- use_debug_agent = true;
- if (optarg != nullptr) {
- port = const_cast<const char*>(optarg);
- }
- break;
- }
- case OPT_DEBUG_BRK:
- {
- use_debug_agent = true;
- debug_wait_connect = true;
- if (optarg != nullptr) {
- port = const_cast<const char*>(optarg);
- }
- break;
- }
- case OPT_DEBUG_PORT:
- {
- port = optarg;
- break;
- }
-#if defined(NODE_HAVE_I18N_SUPPORT)
- case OPT_ICU_DATA_DIR:
- {
- if (optarg != nullptr) {
- icu_data_dir = const_cast<const char*>(optarg);
- }
- break;
- }
-#endif
- case '?':
- {
- if (arg[0] == '-') {
- // V8 option. Pass through as-is.
- new_v8_argv[new_v8_argc] = arg;
- new_v8_argc += 1;
- }
- break;
- }
- }
-
- memcpy(new_exec_argv + new_exec_argc,
- largv + index,
- args_consumed * sizeof(*largv));
-
- new_exec_argc += args_consumed;
- index += args_consumed;
- }
-
- if (port != nullptr) {
- debug_port = atoi(port);
- if (debug_port < 1024 || debug_port > 65535) {
- fprintf(stderr, "Debug port must be in range 1024 to 65535.\n");
- PrintHelp();
- exit(12);
- }
- }
-
- // Copy remaining arguments.
- const unsigned int args_left = nargs - index;
- memcpy(new_argv + new_argc, argv + index, args_left * sizeof(*argv));
- new_argc += args_left;
-
- *exec_argc = new_exec_argc;
- *exec_argv = new_exec_argv;
- *v8_argc = new_v8_argc;
- *v8_argv = new_v8_argv;
-
- // Copy new_argv over argv and update argc.
- memcpy(argv, new_argv, new_argc * sizeof(*argv));
- delete[] new_argv;
- *argc = static_cast<int>(new_argc);
-
- // Copy the preload_modules from the local array to an appropriately sized
- // global array.
- if (preload_module_count > 0) {
- CHECK(!preload_modules);
- preload_modules = new const char*[preload_module_count];
- memcpy(preload_modules,
- local_preload_modules,
- preload_module_count * sizeof(*preload_modules));
- }
- delete[] local_preload_modules;
-}
-
-} // namespace node
diff --git a/src/node_options.h b/src/node_options.h
deleted file mode 100644
index 1d356a1a15..0000000000
--- a/src/node_options.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef SRC_NODE_OPTIONS_H_
-#define SRC_NODE_OPTIONS_H_
-
-#include "node_version.h"
-#include "util.h"
-#include "getopt.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-namespace node {
-
-class NodeOptions {
- public:
- bool print_eval = false;
- bool force_repl = false;
- bool trace_deprecation = false;
- bool throw_deprecation = false;
- bool abort_on_uncaught_exception = false;
- bool trace_sync_io = false;
- const char* eval_string = nullptr;
- unsigned int preload_module_count = 0;
- const char** preload_modules = nullptr;
- bool use_debug_agent = false;
- bool debug_wait_connect = false;
- int debug_port = 5858;
- bool no_deprecation = false;
-#if defined(NODE_HAVE_I18N_SUPPORT)
- // Path to ICU data (for i18n / Intl)
- const char* icu_data_dir = nullptr;
-#endif
-
- NodeOptions() = default;
-
- // Print help to stdout
- void PrintHelp();
-
- // Parse command line arguments.
- //
- // argv is modified in place. exec_argv and v8_argv are out arguments that
- // ParseArgs() allocates memory for and stores a pointer to the output
- // vector in. The caller should free them with delete[].
- //
- // On exit:
- //
- // * argv contains the arguments with node and V8 options filtered out.
- // * exec_argv contains both node and V8 options and nothing else.
- // * v8_argv contains argv[0] plus any V8 options
- void ParseArgs(int* argc,
- const char** argv,
- int* exec_argc,
- const char*** exec_argv,
- int* v8_argc,
- const char*** v8_argv);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(NodeOptions);
-};
-
-} // namespace node
-
-#endif // SRC_NODE_OPTIONS_H_