summaryrefslogtreecommitdiff
path: root/ext/broadcast_channel/lib.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-09 10:56:19 -0400
committerGitHub <noreply@github.com>2023-03-09 14:56:19 +0000
commit8f207c0f3f3a43d77e0c88cfdc840b4b742b9708 (patch)
treea8699bca5ffffff03a9d72f1bed9208a349338ba /ext/broadcast_channel/lib.rs
parent99da8a69e7260b72e55d7214ec96f6ac5e759f35 (diff)
refactor: Split extension registration for runtime and snapshotting (#18095)
This commit splits "<ext_name>::init" functions into "init_ops" and "init_ops_and_esm". That way we don't have to construct list of ESM sources on each startup if we're running with a snapshot. In a follow up commit "deno_core" will be changed to not have a split between "extensions" and "extensions_with_js" - it will be embedders' responsibility to pass appropriately configured extensions. Prerequisite for https://github.com/denoland/deno/pull/18080
Diffstat (limited to 'ext/broadcast_channel/lib.rs')
-rw-r--r--ext/broadcast_channel/lib.rs52
1 files changed, 36 insertions, 16 deletions
diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs
index 3698cc885..14884e99c 100644
--- a/ext/broadcast_channel/lib.rs
+++ b/ext/broadcast_channel/lib.rs
@@ -2,6 +2,7 @@
mod in_memory_broadcast_channel;
+use deno_core::ExtensionBuilder;
pub use in_memory_broadcast_channel::InMemoryBroadcastChannel;
pub use in_memory_broadcast_channel::InMemoryBroadcastChannelResource;
@@ -106,26 +107,45 @@ where
bc.recv(&resource).await
}
-pub fn init<BC: BroadcastChannel + 'static>(
- bc: BC,
- unstable: bool,
-) -> Extension {
+fn ext() -> ExtensionBuilder {
Extension::builder_with_deps(
env!("CARGO_PKG_NAME"),
&["deno_webidl", "deno_web"],
)
- .esm(include_js_files!("01_broadcast_channel.js",))
- .ops(vec![
- op_broadcast_subscribe::decl::<BC>(),
- op_broadcast_unsubscribe::decl::<BC>(),
- op_broadcast_send::decl::<BC>(),
- op_broadcast_recv::decl::<BC>(),
- ])
- .state(move |state| {
- state.put(bc.clone());
- state.put(Unstable(unstable));
- })
- .build()
+}
+
+fn ops<BC: BroadcastChannel + 'static>(
+ ext: &mut ExtensionBuilder,
+ bc: BC,
+ unstable: bool,
+) -> &mut ExtensionBuilder {
+ ext
+ .ops(vec![
+ op_broadcast_subscribe::decl::<BC>(),
+ op_broadcast_unsubscribe::decl::<BC>(),
+ op_broadcast_send::decl::<BC>(),
+ op_broadcast_recv::decl::<BC>(),
+ ])
+ .state(move |state| {
+ state.put(bc.clone());
+ state.put(Unstable(unstable));
+ })
+}
+
+pub fn init_ops_and_esm<BC: BroadcastChannel + 'static>(
+ bc: BC,
+ unstable: bool,
+) -> Extension {
+ ops::<BC>(&mut ext(), bc, unstable)
+ .esm(include_js_files!("01_broadcast_channel.js",))
+ .build()
+}
+
+pub fn init_ops<BC: BroadcastChannel + 'static>(
+ bc: BC,
+ unstable: bool,
+) -> Extension {
+ ops::<BC>(&mut ext(), bc, unstable).build()
}
pub fn get_declaration() -> PathBuf {