diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-01-25 05:03:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 05:03:03 +0100 |
commit | f3711f28f4b5ddfd9a11d9952b0a33b75fc5bc9c (patch) | |
tree | e20562103e9d3a5aa3b47126bea1a773072792fe /cli/util/v8.rs | |
parent | 900929f65c94585de713cb8864aacb5fdc065759 (diff) |
feat(cli): add `DENO_V8_FLAGS` env var (#17313)
Closes #5669
Diffstat (limited to 'cli/util/v8.rs')
-rw-r--r-- | cli/util/v8.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/cli/util/v8.rs b/cli/util/v8.rs new file mode 100644 index 000000000..b6d6aa44e --- /dev/null +++ b/cli/util/v8.rs @@ -0,0 +1,47 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +#[inline(always)] +pub fn get_v8_flags_from_env() -> Vec<String> { + std::env::var("DENO_V8_FLAGS") + .ok() + .map(|flags| flags.split(',').map(String::from).collect::<Vec<String>>()) + .unwrap_or_default() +} + +#[inline(always)] +pub fn construct_v8_flags( + v8_flags: &[String], + env_v8_flags: Vec<String>, +) -> Vec<String> { + std::iter::once("UNUSED_BUT_NECESSARY_ARG0".to_owned()) + .chain(env_v8_flags.into_iter()) + .chain(v8_flags.iter().cloned()) + .collect::<Vec<_>>() +} + +pub fn init_v8_flags(v8_flags: &[String], env_v8_flags: Vec<String>) { + if v8_flags.is_empty() && env_v8_flags.is_empty() { + return; + } + + let v8_flags_includes_help = env_v8_flags + .iter() + .chain(v8_flags) + .any(|flag| flag == "-help" || flag == "--help"); + // Keep in sync with `standalone.rs`. + let v8_flags = construct_v8_flags(v8_flags, env_v8_flags); + let unrecognized_v8_flags = deno_core::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!("\nFor a list of V8 flags, use '--v8-flags=--help'"); + std::process::exit(1); + } + if v8_flags_includes_help { + std::process::exit(0); + } +} |