summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/main.rs25
-rw-r--r--cli/tests/integration_tests.rs12
-rw-r--r--cli/tests/v8_flags_unrecognized.out5
-rw-r--r--cli/tests/v8_help.out5
4 files changed, 39 insertions, 8 deletions
diff --git a/cli/main.rs b/cli/main.rs
index 728a23db0..0c84e7b3e 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -96,6 +96,7 @@ use state::exit_unstable;
use std::env;
use std::io::Read;
use std::io::Write;
+use std::iter::once;
use std::path::PathBuf;
use std::pin::Pin;
use upgrade::upgrade_command;
@@ -666,9 +667,27 @@ pub fn main() {
let flags = flags::flags_from_vec(args);
if let Some(ref v8_flags) = flags.v8_flags {
- let mut v8_flags_ = v8_flags.clone();
- v8_flags_.insert(0, "UNUSED_BUT_NECESSARY_ARG0".to_string());
- v8_set_flags(v8_flags_);
+ let v8_flags_includes_help = v8_flags
+ .iter()
+ .any(|flag| flag == "-help" || flag == "--help");
+ let v8_flags = once("UNUSED_BUT_NECESSARY_ARG0".to_owned())
+ .chain(v8_flags.iter().cloned())
+ .collect::<Vec<_>>();
+ let unrecognized_v8_flags = v8_set_flags(v8_flags)
+ .into_iter()
+ .skip(1)
+ .collect::<Vec<_>>();
+ if !unrecognized_v8_flags.is_empty() {
+ for f in unrecognized_v8_flags {
+ eprintln!("error: V8 did not recognize flag '{}'", f);
+ }
+ eprintln!();
+ eprintln!("For a list of V8 flags, use '--v8-flags=--help'");
+ std::process::exit(1);
+ }
+ if v8_flags_includes_help {
+ std::process::exit(0);
+ }
}
let log_level = match flags.log_level {
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index e0d93eef5..233d53d1c 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -2030,17 +2030,23 @@ itest!(unbuffered_stdout {
// Cannot write the expression to evaluate as "console.log(typeof gc)"
// because itest! splits args on whitespace.
-itest!(eval_v8_flags {
+itest!(v8_flags_eval {
args: "eval --v8-flags=--expose-gc console.log(typeof(gc))",
output: "v8_flags.js.out",
});
-itest!(run_v8_flags {
+itest!(v8_flags_run {
args: "run --v8-flags=--expose-gc v8_flags.js",
output: "v8_flags.js.out",
});
-itest!(run_v8_help {
+itest!(v8_flags_unrecognized {
+ args: "repl --v8-flags=--foo,bar,--trace-gc,-baz",
+ output: "v8_flags_unrecognized.out",
+ exit_code: 1,
+});
+
+itest!(v8_help {
args: "repl --v8-flags=--help",
output: "v8_help.out",
});
diff --git a/cli/tests/v8_flags_unrecognized.out b/cli/tests/v8_flags_unrecognized.out
new file mode 100644
index 000000000..56e70f830
--- /dev/null
+++ b/cli/tests/v8_flags_unrecognized.out
@@ -0,0 +1,5 @@
+error: V8 did not recognize flag '--foo'
+error: V8 did not recognize flag 'bar'
+error: V8 did not recognize flag '-baz'
+
+For a list of V8 flags, use '--v8-flags=--help'
diff --git a/cli/tests/v8_help.out b/cli/tests/v8_help.out
index 3d7aac28d..006d73557 100644
--- a/cli/tests/v8_help.out
+++ b/cli/tests/v8_help.out
@@ -1,3 +1,4 @@
[WILDCARD]
-Synopsis:
-[WILDCARD]d8[WILDCARD] \ No newline at end of file
+Options:
+[WILDCARD]
+ --trace-gc [WILDCARD]