diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-03-13 10:07:24 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-13 16:07:24 +0000 |
commit | eccdb0e99acd66cce38fc8535aeab221a8a6fffa (patch) | |
tree | f975571936d29c9c87482e6c54de9678a52e5794 /cli/args/flags.rs | |
parent | aef9bca876f26c424177d284af75933cbfd53f3b (diff) |
chore(permissions): add allow_all flag (#22890)
Unlocking a potential perf optimization at a later date -- carry the
`allow_all` flag into the permission container.
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r-- | cli/args/flags.rs | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index f9f736490..3065e130b 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -214,7 +214,7 @@ impl LintFlags { } } -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Default)] pub struct ReplFlags { pub eval_files: Option<Vec<String>>, pub eval: Option<String>, @@ -814,6 +814,19 @@ impl Flags { || arg.starts_with("--deny-write") }) } + + #[inline(always)] + fn allow_all(&mut self) { + self.allow_all = true; + self.allow_read = Some(vec![]); + self.allow_env = Some(vec![]); + self.allow_net = Some(vec![]); + self.allow_run = Some(vec![]); + self.allow_write = Some(vec![]); + self.allow_sys = Some(vec![]); + self.allow_ffi = Some(vec![]); + self.allow_hrtime = true; + } } static ENV_VARIABLES_HELP: &str = color_print::cstr!( @@ -3488,14 +3501,7 @@ fn doc_parse(flags: &mut Flags, matches: &mut ArgMatches) { fn eval_parse(flags: &mut Flags, matches: &mut ArgMatches) { runtime_args_parse(flags, matches, false, true); - flags.allow_net = Some(vec![]); - flags.allow_env = Some(vec![]); - flags.allow_run = Some(vec![]); - flags.allow_read = Some(vec![]); - flags.allow_sys = Some(vec![]); - flags.allow_write = Some(vec![]); - flags.allow_ffi = Some(vec![]); - flags.allow_hrtime = true; + flags.allow_all(); ext_arg_parse(flags, matches); @@ -4005,15 +4011,7 @@ fn permission_args_parse(flags: &mut Flags, matches: &mut ArgMatches) { } if matches.get_flag("allow-all") { - flags.allow_all = true; - flags.allow_read = Some(vec![]); - flags.allow_env = Some(vec![]); - flags.allow_net = Some(vec![]); - flags.allow_run = Some(vec![]); - flags.allow_write = Some(vec![]); - flags.allow_sys = Some(vec![]); - flags.allow_ffi = Some(vec![]); - flags.allow_hrtime = true; + flags.allow_all(); } if matches.get_flag("no-prompt") { @@ -5439,6 +5437,7 @@ mod tests { print: false, code: "'console.log(\"hello\")'".to_string(), }), + allow_all: true, allow_net: Some(vec![]), allow_env: Some(vec![]), allow_run: Some(vec![]), @@ -5462,6 +5461,7 @@ mod tests { print: true, code: "1+2".to_string(), }), + allow_all: true, allow_net: Some(vec![]), allow_env: Some(vec![]), allow_run: Some(vec![]), @@ -5486,6 +5486,7 @@ mod tests { print: false, code: "'console.log(\"hello\")'".to_string(), }), + allow_all: true, allow_net: Some(vec![]), allow_env: Some(vec![]), allow_run: Some(vec![]), @@ -5524,6 +5525,7 @@ mod tests { v8_flags: svec!["--help", "--random-seed=1"], seed: Some(1), inspect: Some("127.0.0.1:9229".parse().unwrap()), + allow_all: true, allow_net: Some(vec![]), allow_env: Some(vec![]), allow_run: Some(vec![]), @@ -5555,6 +5557,7 @@ mod tests { code: "console.log(Deno.args)".to_string(), }), argv: svec!["arg1", "arg2"], + allow_all: true, allow_net: Some(vec![]), allow_env: Some(vec![]), allow_run: Some(vec![]), |