From fac64478157ee563b185edb5734688e4523df3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 7 Jan 2023 17:25:34 +0100 Subject: 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>" (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. --- cli/module_loader.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'cli/module_loader.rs') diff --git a/cli/module_loader.rs b/cli/module_loader.rs index edc89be77..d452c30cf 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -21,7 +21,7 @@ use deno_core::ModuleSpecifier; use deno_core::ModuleType; use deno_core::OpState; use deno_core::SourceMapGetter; -use deno_runtime::permissions::Permissions; +use deno_runtime::permissions::PermissionsContainer; use std::cell::RefCell; use std::pin::Pin; use std::rc::Rc; @@ -38,7 +38,7 @@ pub struct CliModuleLoader { /// The initial set of permissions used to resolve the static imports in the /// worker. They are decoupled from the worker (dynamic) permissions since /// read access errors must be raised based on the parent thread permissions. - pub root_permissions: Permissions, + pub root_permissions: PermissionsContainer, pub ps: ProcState, } @@ -46,12 +46,15 @@ impl CliModuleLoader { pub fn new(ps: ProcState) -> Rc { Rc::new(CliModuleLoader { lib: ps.options.ts_type_lib_window(), - root_permissions: Permissions::allow_all(), + root_permissions: PermissionsContainer::allow_all(), ps, }) } - pub fn new_for_worker(ps: ProcState, permissions: Permissions) -> Rc { + pub fn new_for_worker( + ps: ProcState, + permissions: PermissionsContainer, + ) -> Rc { Rc::new(CliModuleLoader { lib: ps.options.ts_type_lib_worker(), root_permissions: permissions, @@ -235,7 +238,7 @@ impl ModuleLoader for CliModuleLoader { let ps = self.ps.clone(); let state = op_state.borrow(); - let dynamic_permissions = state.borrow::().clone(); + let dynamic_permissions = state.borrow::().clone(); let root_permissions = if is_dynamic { dynamic_permissions.clone() } else { -- cgit v1.2.3