From 60bf79c18410fd332b6b9b7c222e6d3d62bfe3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 14 Jun 2023 00:36:16 +0200 Subject: =?UTF-8?q?Revert=20"refactor(core):=20cleanup=20feature=20flags?= =?UTF-8?q?=20for=20js=20source=20inclusion=E2=80=A6=20(#19490)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … (#19463)" This reverts commit ceb03cfb037cf7024a5048b17b508ddda59cfa05. This is being reverted because it causes 3.5Mb increase in the binary size, due to runtime JS code being included in the binary, even though it's already snapshotted. CC @nayeemrmn --- core/modules.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'core/modules.rs') diff --git a/core/modules.rs b/core/modules.rs index 5d9fe2fc4..4f1875ae5 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -438,7 +438,7 @@ impl ModuleLoader for ExtModuleLoader { let result = if let Some(load_callback) = &self.maybe_load_callback { load_callback(source) } else { - Ok(source.load()) + source.load() }; match result { Ok(code) => { @@ -459,6 +459,29 @@ impl ModuleLoader for ExtModuleLoader { } } +impl Drop for ExtModuleLoader { + fn drop(&mut self) { + let sources = self.sources.get_mut(); + let used_specifiers = self.used_specifiers.get_mut(); + let unused_modules: Vec<_> = sources + .iter() + .filter(|(k, _)| !used_specifiers.contains(k.as_str())) + .collect(); + + if !unused_modules.is_empty() { + let mut msg = + "Following modules were passed to ExtModuleLoader but never used:\n" + .to_string(); + for m in unused_modules { + msg.push_str(" - "); + msg.push_str(m.0); + msg.push('\n'); + } + panic!("{}", msg); + } + } +} + /// Basic file system module loader. /// /// Note that this loader will **block** event loop @@ -2021,7 +2044,7 @@ import "/a.js"; deno_core::extension!(test_ext, ops = [op_test]); let mut runtime = JsRuntime::new(RuntimeOptions { - extensions: vec![test_ext::init()], + extensions: vec![test_ext::init_ops()], module_loader: Some(loader), ..Default::default() }); -- cgit v1.2.3