1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00
denoland-deno/cli/util/v8.rs
David Sherret f5840bdcd3
chore: upgrade to Rust 1.67 (#17548)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-01-27 10:43:16 -05:00

47 lines
1.3 KiB
Rust

// 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);
}
}