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/ffi/lib.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'ext/ffi') diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index 8a1227ed9..f93e2e121 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -5,6 +5,7 @@ use deno_core::futures::channel::mpsc; use deno_core::include_js_files; use deno_core::v8; use deno_core::Extension; +use deno_core::ExtensionBuilder; use deno_core::OpState; use std::cell::RefCell; @@ -81,9 +82,15 @@ pub(crate) struct FfiState { pub(crate) async_work_receiver: mpsc::UnboundedReceiver, } -pub fn init(unstable: bool) -> Extension { +fn ext() -> ExtensionBuilder { Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"]) - .esm(include_js_files!("00_ffi.js",)) +} + +fn ops( + ext: &mut ExtensionBuilder, + unstable: bool, +) -> &mut ExtensionBuilder { + ext .ops(vec![ op_ffi_load::decl::

(), op_ffi_get_static::decl(), @@ -151,5 +158,18 @@ pub fn init(unstable: bool) -> Extension { async_work_sender, }); }) +} + +pub fn init_ops_and_esm( + unstable: bool, +) -> Extension { + ops::

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

(&mut ext(), unstable) + .esm(include_js_files!("00_ffi.js",)) .build() } -- cgit v1.2.3