refactor(permissions): add PermissionsContainer struct for internal mutability (#17134)

Turns out we were cloning permissions which after prompting were discarded,
so the state of permissions was never preserved. To handle that we need to store
all permissions behind "Arc<Mutex<>>" (because there are situations where we
need to send them to other thread).

Testing and benching code still uses "Permissions" in most places - it's undesirable
to share the same permission set between various test/bench files - otherwise
granting or revoking permissions in one file would influence behavior of other test
files.
This commit is contained in:
Bartek Iwańczuk 2023-01-07 17:25:34 +01:00 committed by GitHub
parent 82e930726e
commit fac6447815
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 489 additions and 377 deletions

View file

@ -8,6 +8,7 @@ use crate::worker::create_main_worker;
use deno_core::error::AnyError;
use deno_core::resolve_url_or_path;
use deno_runtime::permissions::Permissions;
use deno_runtime::permissions::PermissionsContainer;
use rustyline::error::ReadlineError;
mod cdp;
@ -72,7 +73,7 @@ async fn read_eval_file(
let file = ps
.file_fetcher
.fetch(&specifier, &mut Permissions::allow_all())
.fetch(&specifier, PermissionsContainer::allow_all())
.await?;
Ok((*file.source).to_string())
@ -84,7 +85,9 @@ pub async fn run(flags: Flags, repl_flags: ReplFlags) -> Result<i32, AnyError> {
let mut worker = create_main_worker(
&ps,
main_module.clone(),
Permissions::from_options(&ps.options.permissions_options())?,
PermissionsContainer::new(Permissions::from_options(
&ps.options.permissions_options(),
)?),
)
.await?;
worker.setup_repl().await?;