2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-24 23:03:03 -05:00
|
|
|
|
2024-05-09 16:49:10 -04:00
|
|
|
pub mod convert;
|
|
|
|
|
2023-01-24 23:03:03 -05:00
|
|
|
#[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(
|
2023-05-13 15:42:34 -04:00
|
|
|
default_v8_flags: &[String],
|
2023-01-24 23:03:03 -05:00
|
|
|
v8_flags: &[String],
|
|
|
|
env_v8_flags: Vec<String>,
|
|
|
|
) -> Vec<String> {
|
|
|
|
std::iter::once("UNUSED_BUT_NECESSARY_ARG0".to_owned())
|
2023-05-13 15:42:34 -04:00
|
|
|
.chain(default_v8_flags.iter().cloned())
|
2023-08-27 00:04:12 -04:00
|
|
|
.chain(env_v8_flags)
|
2023-01-24 23:03:03 -05:00
|
|
|
.chain(v8_flags.iter().cloned())
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
}
|
|
|
|
|
2023-05-13 15:42:34 -04:00
|
|
|
pub fn init_v8_flags(
|
|
|
|
default_v8_flags: &[String],
|
|
|
|
v8_flags: &[String],
|
|
|
|
env_v8_flags: Vec<String>,
|
|
|
|
) {
|
|
|
|
if default_v8_flags.is_empty()
|
|
|
|
&& v8_flags.is_empty()
|
|
|
|
&& env_v8_flags.is_empty()
|
|
|
|
{
|
2023-01-24 23:03:03 -05:00
|
|
|
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`.
|
2023-05-13 15:42:34 -04:00
|
|
|
let v8_flags = construct_v8_flags(default_v8_flags, v8_flags, env_v8_flags);
|
2023-01-24 23:03:03 -05:00
|
|
|
let unrecognized_v8_flags = deno_core::v8_set_flags(v8_flags)
|
|
|
|
.into_iter()
|
|
|
|
.skip(1)
|
|
|
|
.collect::<Vec<_>>();
|
2024-05-08 22:45:06 -04:00
|
|
|
|
|
|
|
#[allow(clippy::print_stderr)]
|
2023-01-24 23:03:03 -05:00
|
|
|
if !unrecognized_v8_flags.is_empty() {
|
|
|
|
for f in unrecognized_v8_flags {
|
2023-01-27 10:43:16 -05:00
|
|
|
eprintln!("error: V8 did not recognize flag '{f}'");
|
2023-01-24 23:03:03 -05:00
|
|
|
}
|
|
|
|
eprintln!("\nFor a list of V8 flags, use '--v8-flags=--help'");
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
if v8_flags_includes_help {
|
|
|
|
std::process::exit(0);
|
|
|
|
}
|
|
|
|
}
|