mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
2080669943
<!-- Before submitting a PR, please read https://deno.com/manual/contributing 1. Give the PR a descriptive title. Examples of good title: - fix(std/http): Fix race condition in server - docs(console): Update docstrings - feat(doc): Handle nested reexports Examples of bad title: - fix #7123 - update docs - fix bugs 2. Ensure there is a related issue and it is referenced in the PR text. 3. Ensure there are tests that cover the changes. 4. Ensure `cargo test` passes. 5. Ensure `./tools/format.js` passes without changing files. 6. Ensure `./tools/lint.js` passes. 7. Open as a draft PR if your work is still in progress. The CI won't run all steps, but you can add '[ci]' to a commit message to force it to. 8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label. --> As the title. --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
56 lines
1.5 KiB
Rust
56 lines
1.5 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(
|
|
default_v8_flags: &[String],
|
|
v8_flags: &[String],
|
|
env_v8_flags: Vec<String>,
|
|
) -> Vec<String> {
|
|
std::iter::once("UNUSED_BUT_NECESSARY_ARG0".to_owned())
|
|
.chain(default_v8_flags.iter().cloned())
|
|
.chain(env_v8_flags)
|
|
.chain(v8_flags.iter().cloned())
|
|
.collect::<Vec<_>>()
|
|
}
|
|
|
|
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()
|
|
{
|
|
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(default_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);
|
|
}
|
|
}
|