summaryrefslogtreecommitdiff
path: root/src/workers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/workers.rs')
-rw-r--r--src/workers.rs19
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),