summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/dts/lib.deno.shared_globals.d.ts1
-rw-r--r--cli/main.rs2
-rw-r--r--cli/program_state.rs4
-rw-r--r--cli/standalone.rs3
-rw-r--r--cli/tests/unit/broadcast_channel_test.ts27
-rw-r--r--cli/tests/workers/broadcast_channel.ts5
6 files changed, 42 insertions, 0 deletions
diff --git a/cli/dts/lib.deno.shared_globals.d.ts b/cli/dts/lib.deno.shared_globals.d.ts
index d3784705e..e35de2e77 100644
--- a/cli/dts/lib.deno.shared_globals.d.ts
+++ b/cli/dts/lib.deno.shared_globals.d.ts
@@ -12,6 +12,7 @@
/// <reference lib="deno.fetch" />
/// <reference lib="deno.websocket" />
/// <reference lib="deno.crypto" />
+/// <reference lib="deno.broadcast_channel" />
declare namespace WebAssembly {
/**
diff --git a/cli/main.rs b/cli/main.rs
index 868805e92..60c202a7a 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -124,6 +124,7 @@ fn create_web_worker_callback(
no_color: !colors::use_color(),
get_error_class_fn: Some(&crate::errors::get_error_class_name),
blob_url_store: program_state.blob_url_store.clone(),
+ broadcast_channel: program_state.broadcast_channel.clone(),
};
let mut worker = WebWorker::from_options(
@@ -212,6 +213,7 @@ pub fn create_main_worker(
.join(checksum::gen(&[loc.to_string().as_bytes()]))
}),
blob_url_store: program_state.blob_url_store.clone(),
+ broadcast_channel: program_state.broadcast_channel.clone(),
};
let mut worker = MainWorker::from_options(main_module, permissions, &options);
diff --git a/cli/program_state.rs b/cli/program_state.rs
index 50890b9e4..9f7ddc749 100644
--- a/cli/program_state.rs
+++ b/cli/program_state.rs
@@ -15,6 +15,7 @@ use crate::module_graph::TypeLib;
use crate::source_maps::SourceMapGetter;
use crate::specifier_handler::FetchHandler;
use crate::version;
+use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
use deno_runtime::deno_file::BlobUrlStore;
use deno_runtime::inspector::InspectorServer;
use deno_runtime::permissions::Permissions;
@@ -52,6 +53,7 @@ pub struct ProgramState {
pub maybe_inspector_server: Option<Arc<InspectorServer>>,
pub ca_data: Option<Vec<u8>>,
pub blob_url_store: BlobUrlStore,
+ pub broadcast_channel: InMemoryBroadcastChannel,
}
impl ProgramState {
@@ -77,6 +79,7 @@ impl ProgramState {
};
let blob_url_store = BlobUrlStore::default();
+ let broadcast_channel = InMemoryBroadcastChannel::default();
let file_fetcher = FileFetcher::new(
http_cache,
@@ -143,6 +146,7 @@ impl ProgramState {
maybe_inspector_server,
ca_data,
blob_url_store,
+ broadcast_channel,
};
Ok(Arc::new(program_state))
}
diff --git a/cli/standalone.rs b/cli/standalone.rs
index e0b131eb8..f281c5336 100644
--- a/cli/standalone.rs
+++ b/cli/standalone.rs
@@ -15,6 +15,7 @@ use deno_core::v8_set_flags;
use deno_core::ModuleLoader;
use deno_core::ModuleSpecifier;
use deno_core::OpState;
+use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
use deno_runtime::deno_file::BlobUrlStore;
use deno_runtime::permissions::Permissions;
use deno_runtime::permissions::PermissionsOptions;
@@ -160,6 +161,7 @@ pub async fn run(
let main_module = resolve_url(SPECIFIER)?;
let permissions = Permissions::from_options(&metadata.permissions);
let blob_url_store = BlobUrlStore::default();
+ let broadcast_channel = InMemoryBroadcastChannel::default();
let module_loader = Rc::new(EmbeddedModuleLoader(source_code));
let create_web_worker_cb = Arc::new(|_| {
todo!("Worker are currently not supported in standalone binaries");
@@ -193,6 +195,7 @@ pub async fn run(
location: metadata.location,
location_data_dir: None,
blob_url_store,
+ broadcast_channel,
};
let mut worker =
MainWorker::from_options(main_module.clone(), permissions, &options);
diff --git a/cli/tests/unit/broadcast_channel_test.ts b/cli/tests/unit/broadcast_channel_test.ts
new file mode 100644
index 000000000..cfa62c856
--- /dev/null
+++ b/cli/tests/unit/broadcast_channel_test.ts
@@ -0,0 +1,27 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+import { assertEquals } from "../../../test_util/std/testing/asserts.ts";
+import { deferred } from "../../../test_util/std/async/deferred.ts";
+
+Deno.test("broadcastchannel worker", async () => {
+ const intercom = new BroadcastChannel("intercom");
+ let count = 0;
+
+ const url = new URL("../workers/broadcast_channel.ts", import.meta.url);
+ const worker = new Worker(url.href, { type: "module", name: "worker" });
+ worker.onmessage = () => intercom.postMessage(++count);
+
+ const promise = deferred();
+
+ intercom.onmessage = function (e) {
+ assertEquals(count, e.data);
+ if (count < 42) {
+ intercom.postMessage(++count);
+ } else {
+ worker.terminate();
+ intercom.close();
+ promise.resolve();
+ }
+ };
+
+ await promise;
+});
diff --git a/cli/tests/workers/broadcast_channel.ts b/cli/tests/workers/broadcast_channel.ts
new file mode 100644
index 000000000..5076e9eb7
--- /dev/null
+++ b/cli/tests/workers/broadcast_channel.ts
@@ -0,0 +1,5 @@
+new BroadcastChannel("intercom").onmessage = function (e) {
+ this.postMessage(e.data);
+};
+
+self.postMessage("go");