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/flash/lib.rs | 88 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 35 deletions(-) (limited to 'ext/flash/lib.rs') diff --git a/ext/flash/lib.rs b/ext/flash/lib.rs index 605dc3e43..41287d003 100644 --- a/ext/flash/lib.rs +++ b/ext/flash/lib.rs @@ -17,6 +17,7 @@ use deno_core::ByteString; use deno_core::CancelFuture; use deno_core::CancelHandle; use deno_core::Extension; +use deno_core::ExtensionBuilder; use deno_core::OpState; use deno_core::StringOrBuffer; use deno_core::ZeroCopyBuf; @@ -1526,7 +1527,7 @@ pub trait FlashPermissions { ) -> Result<(), AnyError>; } -pub fn init(unstable: bool) -> Extension { +fn ext() -> ExtensionBuilder { Extension::builder_with_deps( env!("CARGO_PKG_NAME"), &[ @@ -1537,38 +1538,55 @@ pub fn init(unstable: bool) -> Extension { "deno_http", ], ) - .esm(deno_core::include_js_files!("01_http.js",)) - .ops(vec![ - op_flash_serve::decl::

(), - op_node_unstable_flash_serve::decl::

(), - op_flash_respond::decl(), - op_flash_respond_async::decl(), - op_flash_respond_chunked::decl(), - op_flash_method::decl(), - op_flash_path::decl(), - op_flash_headers::decl(), - op_flash_addr::decl(), - op_flash_next::decl(), - op_flash_next_server::decl(), - op_flash_next_async::decl(), - op_flash_read_body::decl(), - op_flash_upgrade_websocket::decl(), - op_flash_drive_server::decl(), - op_flash_wait_for_listening::decl(), - op_flash_first_packet::decl(), - op_flash_has_body_stream::decl(), - op_flash_close_server::decl(), - op_flash_make_request::decl(), - op_flash_write_resource::decl(), - op_try_flash_respond_chunked::decl(), - ]) - .state(move |op_state| { - op_state.put(Unstable(unstable)); - op_state.put(FlashContext { - next_server_id: 0, - join_handles: HashMap::default(), - servers: HashMap::default(), - }); - }) - .build() +} + +fn ops( + ext: &mut ExtensionBuilder, + unstable: bool, +) -> &mut ExtensionBuilder { + ext + .ops(vec![ + op_flash_serve::decl::

(), + op_node_unstable_flash_serve::decl::

(), + op_flash_respond::decl(), + op_flash_respond_async::decl(), + op_flash_respond_chunked::decl(), + op_flash_method::decl(), + op_flash_path::decl(), + op_flash_headers::decl(), + op_flash_addr::decl(), + op_flash_next::decl(), + op_flash_next_server::decl(), + op_flash_next_async::decl(), + op_flash_read_body::decl(), + op_flash_upgrade_websocket::decl(), + op_flash_drive_server::decl(), + op_flash_wait_for_listening::decl(), + op_flash_first_packet::decl(), + op_flash_has_body_stream::decl(), + op_flash_close_server::decl(), + op_flash_make_request::decl(), + op_flash_write_resource::decl(), + op_try_flash_respond_chunked::decl(), + ]) + .state(move |op_state| { + op_state.put(Unstable(unstable)); + op_state.put(FlashContext { + next_server_id: 0, + join_handles: HashMap::default(), + servers: HashMap::default(), + }); + }) +} + +pub fn init_ops_and_esm( + unstable: bool, +) -> Extension { + ops::

(&mut ext(), unstable) + .esm(deno_core::include_js_files!("01_http.js",)) + .build() +} + +pub fn init_ops(unstable: bool) -> Extension { + ops::

(&mut ext(), unstable).build() } -- cgit v1.2.3