diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-06-13 16:45:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 09:45:06 -0600 |
commit | ceb03cfb037cf7024a5048b17b508ddda59cfa05 (patch) | |
tree | 0c2df444e00f17131f9e2af708f80cdc4b032ce8 /core/modules.rs | |
parent | 5348778666d2d8d7ce138bbdf75ac5aa9f7ed428 (diff) |
refactor(core): cleanup feature flags for js source inclusion (#19463)
Remove `ExtensionFileSourceCode::LoadedFromFsDuringSnapshot` and feature
`include_js_for_snapshotting` since they leak paths that are only
applicable in this repo to embedders. Replace with feature
`exclude_js_sources`. Additionally the feature
`force_include_js_sources` allows negating it, if both features are set.
We need both of these because features are additive and there must be a
way of force including sources for snapshot creation while still having
the `exclude_js_sources` feature. `force_include_js_sources` is only set
for build deps, so sources are still excluded from the final binary.
You can also specify `force_include_js_sources` on any extension to
override the above features for that extension. Towards #19398.
But there was still the snapshot-from-snapshot situation where code
could be executed twice, I addressed that by making `mod_evaluate()` and
scripts like `core/01_core.js` behave idempotently. This allowed
unifying `ext::init_ops()` and `ext::init_ops_and_esm()` into
`ext::init()`.
Diffstat (limited to 'core/modules.rs')
-rw-r--r-- | core/modules.rs | 27 |
1 files changed, 2 insertions, 25 deletions
diff --git a/core/modules.rs b/core/modules.rs index 4f1875ae5..5d9fe2fc4 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 { - source.load() + Ok(source.load()) }; match result { Ok(code) => { @@ -459,29 +459,6 @@ 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 @@ -2044,7 +2021,7 @@ import "/a.js"; deno_core::extension!(test_ext, ops = [op_test]); let mut runtime = JsRuntime::new(RuntimeOptions { - extensions: vec![test_ext::init_ops()], + extensions: vec![test_ext::init()], module_loader: Some(loader), ..Default::default() }); |