diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-01-07 17:25:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-07 17:25:34 +0100 |
commit | fac64478157ee563b185edb5734688e4523df3a1 (patch) | |
tree | 888d562982e1fc37dfb9a4459928bcec84d55dfc /cli/module_loader.rs | |
parent | 82e930726ee5dbac8e6eae0962c07c72daf9843c (diff) |
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.
Diffstat (limited to 'cli/module_loader.rs')
-rw-r--r-- | cli/module_loader.rs | 13 |
1 files changed, 8 insertions, 5 deletions
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<Self> { 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<Self> { + pub fn new_for_worker( + ps: ProcState, + permissions: PermissionsContainer, + ) -> Rc<Self> { 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::<Permissions>().clone(); + let dynamic_permissions = state.borrow::<PermissionsContainer>().clone(); let root_permissions = if is_dynamic { dynamic_permissions.clone() } else { |