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/net/lib.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 15 deletions(-) (limited to 'ext/net/lib.rs') diff --git a/ext/net/lib.rs b/ext/net/lib.rs index 780cbceb5..4703b05cc 100644 --- a/ext/net/lib.rs +++ b/ext/net/lib.rs @@ -10,6 +10,7 @@ pub mod resolve_addr; use deno_core::error::AnyError; use deno_core::include_js_files; use deno_core::Extension; +use deno_core::ExtensionBuilder; use deno_core::OpState; use deno_tls::rustls::RootCertStore; use std::cell::RefCell; @@ -77,24 +78,55 @@ pub struct DefaultTlsOptions { /// would override previously used alias. pub struct UnsafelyIgnoreCertificateErrors(pub Option>); -pub fn init( +fn ext() -> ExtensionBuilder { + Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"]) +} + +fn ops( + ext: &mut ExtensionBuilder, root_cert_store: Option, unstable: bool, unsafely_ignore_certificate_errors: Option>, -) -> Extension { +) -> &mut ExtensionBuilder { let mut ops = ops::init::

(); ops.extend(ops_tls::init::

()); - Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"]) - .esm(include_js_files!("01_net.js", "02_tls.js",)) - .ops(ops) - .state(move |state| { - state.put(DefaultTlsOptions { - root_cert_store: root_cert_store.clone(), - }); - state.put(UnstableChecker { unstable }); - state.put(UnsafelyIgnoreCertificateErrors( - unsafely_ignore_certificate_errors.clone(), - )); - }) - .build() + + ext.ops(ops).state(move |state| { + state.put(DefaultTlsOptions { + root_cert_store: root_cert_store.clone(), + }); + state.put(UnstableChecker { unstable }); + state.put(UnsafelyIgnoreCertificateErrors( + unsafely_ignore_certificate_errors.clone(), + )); + }) +} + +pub fn init_ops_and_esm( + root_cert_store: Option, + unstable: bool, + unsafely_ignore_certificate_errors: Option>, +) -> Extension { + ops::

( + &mut ext(), + root_cert_store, + unstable, + unsafely_ignore_certificate_errors, + ) + .esm(include_js_files!("01_net.js", "02_tls.js",)) + .build() +} + +pub fn init_ops( + root_cert_store: Option, + unstable: bool, + unsafely_ignore_certificate_errors: Option>, +) -> Extension { + ops::

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