diff options
author | andy finch <andyfinch7@gmail.com> | 2019-03-01 19:25:50 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-01 19:25:50 -0500 |
commit | 8c310d3d56c6b1bc67ee81d8c5ea9b20abee8088 (patch) | |
tree | 442823e64836f956fe22014b563269e1ababefae /src/workers.rs | |
parent | 1cc02a5d9d867f1a239ee4b69f587d8afac07b02 (diff) |
Permissions refactor (#1864)
Refactored permissions to be assignable on a per-isolate
basis, and added a fix for #1858 to op_fetch_module_meta_data.
Diffstat (limited to 'src/workers.rs')
-rw-r--r-- | src/workers.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/workers.rs b/src/workers.rs index 3b20ae371..6b85a97da 100644 --- a/src/workers.rs +++ b/src/workers.rs @@ -5,6 +5,7 @@ use crate::isolate::IsolateState; use crate::isolate::WorkerChannels; use crate::js_errors::JSErrorColor; use crate::ops; +use crate::permissions::DenoPermissions; use crate::resources; use crate::snapshot; use crate::tokio_util; @@ -22,7 +23,10 @@ pub struct Worker { } impl Worker { - pub fn new(parent_state: &Arc<IsolateState>) -> (Self, WorkerChannels) { + pub fn new( + parent_state: &Arc<IsolateState>, + permissions: DenoPermissions, + ) -> (Self, WorkerChannels) { let (worker_in_tx, worker_in_rx) = mpsc::channel::<Buf>(1); let (worker_out_tx, worker_out_rx) = mpsc::channel::<Buf>(1); @@ -36,7 +40,7 @@ impl Worker { )); let snapshot = snapshot::compiler_snapshot(); - let isolate = Isolate::new(snapshot, state, ops::dispatch); + let isolate = Isolate::new(snapshot, state, ops::dispatch, permissions); let worker = Worker { isolate }; (worker, external_channels) @@ -54,6 +58,7 @@ impl Worker { pub fn spawn( state: Arc<IsolateState>, js_source: String, + permissions: DenoPermissions, ) -> resources::Resource { // TODO This function should return a Future, so that the caller can retrieve // the JSError if one is thrown. Currently it just prints to stderr and calls @@ -63,7 +68,7 @@ pub fn spawn( let builder = thread::Builder::new().name("worker".to_string()); let _tid = builder .spawn(move || { - let (worker, external_channels) = Worker::new(&state); + let (worker, external_channels) = Worker::new(&state, permissions); let resource = resources::add_worker(external_channels); p.send(resource.clone()).unwrap(); @@ -109,6 +114,7 @@ mod tests { console.log("after postMessage"); } "#.into(), + DenoPermissions::default(), ); let msg = String::from("hi").into_boxed_str().into_boxed_bytes(); @@ -127,8 +133,11 @@ mod tests { #[test] fn removed_from_resource_table_on_close() { - let resource = - spawn(IsolateState::mock(), "onmessage = () => close();".into()); + let resource = spawn( + IsolateState::mock(), + "onmessage = () => close();".into(), + DenoPermissions::default(), + ); assert_eq!( resources::get_type(resource.rid), |