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/http/lib.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'ext/http') diff --git a/ext/http/lib.rs b/ext/http/lib.rs index 14a93ede9..8fd7015aa 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -30,6 +30,7 @@ use deno_core::CancelFuture; use deno_core::CancelHandle; use deno_core::CancelTryFuture; use deno_core::Extension; +use deno_core::ExtensionBuilder; use deno_core::OpState; use deno_core::RcRef; use deno_core::Resource; @@ -77,13 +78,15 @@ use crate::reader_stream::ShutdownHandle; pub mod compressible; mod reader_stream; -pub fn init() -> Extension { +fn ext() -> ExtensionBuilder { Extension::builder_with_deps( env!("CARGO_PKG_NAME"), &["deno_web", "deno_net", "deno_fetch", "deno_websocket"], ) - .esm(include_js_files!("01_http.js",)) - .ops(vec![ +} + +fn ops(ext: &mut ExtensionBuilder) -> &mut ExtensionBuilder { + ext.ops(vec![ op_http_accept::decl(), op_http_write_headers::decl(), op_http_headers::decl(), @@ -93,7 +96,16 @@ pub fn init() -> Extension { op_http_websocket_accept_header::decl(), op_http_upgrade_websocket::decl(), ]) - .build() +} + +pub fn init_ops_and_esm() -> Extension { + ops(&mut ext()) + .esm(include_js_files!("01_http.js",)) + .build() +} + +pub fn init_ops() -> Extension { + ops(&mut ext()).build() } pub enum HttpSocketAddr { -- cgit v1.2.3