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/worker.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/worker.rs')
-rw-r--r-- | cli/worker.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/cli/worker.rs b/cli/worker.rs index ea50966f4..2d29a7a53 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -16,7 +16,7 @@ use deno_runtime::colors; use deno_runtime::fmt_errors::format_js_error; use deno_runtime::ops::worker_host::CreateWebWorkerCb; use deno_runtime::ops::worker_host::WorkerEventCb; -use deno_runtime::permissions::Permissions; +use deno_runtime::permissions::PermissionsContainer; use deno_runtime::web_worker::WebWorker; use deno_runtime::web_worker::WebWorkerOptions; use deno_runtime::worker::MainWorker; @@ -410,7 +410,7 @@ impl CliMainWorker { pub async fn create_main_worker( ps: &ProcState, main_module: ModuleSpecifier, - permissions: Permissions, + permissions: PermissionsContainer, ) -> Result<CliMainWorker, AnyError> { create_main_worker_internal( ps, @@ -426,7 +426,7 @@ pub async fn create_main_worker( pub async fn create_main_worker_for_test_or_bench( ps: &ProcState, main_module: ModuleSpecifier, - permissions: Permissions, + permissions: PermissionsContainer, custom_extensions: Vec<Extension>, stdio: deno_runtime::ops::io::Stdio, ) -> Result<CliMainWorker, AnyError> { @@ -444,7 +444,7 @@ pub async fn create_main_worker_for_test_or_bench( async fn create_main_worker_internal( ps: &ProcState, main_module: ModuleSpecifier, - permissions: Permissions, + permissions: PermissionsContainer, mut custom_extensions: Vec<Extension>, stdio: deno_runtime::ops::io::Stdio, bench_or_test: bool, @@ -731,10 +731,11 @@ mod tests { use deno_core::{resolve_url_or_path, FsModuleLoader}; use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel; use deno_runtime::deno_web::BlobStore; + use deno_runtime::permissions::Permissions; fn create_test_worker() -> MainWorker { let main_module = resolve_url_or_path("./hello.js").unwrap(); - let permissions = Permissions::default(); + let permissions = PermissionsContainer::new(Permissions::default()); let options = WorkerOptions { bootstrap: BootstrapOptions { |