From 8f207c0f3f3a43d77e0c88cfdc840b4b742b9708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 9 Mar 2023 10:56:19 -0400 Subject: refactor: Split extension registration for runtime and snapshotting (#18095) This commit splits "::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 --- ext/broadcast_channel/lib.rs | 52 ++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'ext/broadcast_channel/lib.rs') 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: 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::(), - op_broadcast_unsubscribe::decl::(), - op_broadcast_send::decl::(), - op_broadcast_recv::decl::(), - ]) - .state(move |state| { - state.put(bc.clone()); - state.put(Unstable(unstable)); - }) - .build() +} + +fn ops( + ext: &mut ExtensionBuilder, + bc: BC, + unstable: bool, +) -> &mut ExtensionBuilder { + ext + .ops(vec![ + op_broadcast_subscribe::decl::(), + op_broadcast_unsubscribe::decl::(), + op_broadcast_send::decl::(), + op_broadcast_recv::decl::(), + ]) + .state(move |state| { + state.put(bc.clone()); + state.put(Unstable(unstable)); + }) +} + +pub fn init_ops_and_esm( + bc: BC, + unstable: bool, +) -> Extension { + ops::(&mut ext(), bc, unstable) + .esm(include_js_files!("01_broadcast_channel.js",)) + .build() +} + +pub fn init_ops( + bc: BC, + unstable: bool, +) -> Extension { + ops::(&mut ext(), bc, unstable).build() } pub fn get_declaration() -> PathBuf { -- cgit v1.2.3