diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-03-17 12:22:15 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-17 18:22:15 +0000 |
commit | e55b448730160a6e4df9815a268d4049ac89deab (patch) | |
tree | 35d80fd60f2f1d1d06903caff256484a7d703d76 /core/modules.rs | |
parent | 0bc6bf5d33b8198253954d7f04558270de45c925 (diff) |
feat(core) deno_core::extension! macro to simplify extension registration (#18210)
This implements two macros to simplify extension registration and centralize a lot of the boilerplate as a base for future improvements:
* `deno_core::ops!` registers a block of `#[op]`s, optionally with type
parameters, useful for places where we share lists of ops
* `deno_core::extension!` is used to register an extension, and creates
two methods that can be used at runtime/snapshot generation time:
`init_ops` and `init_ops_and_esm`.
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'core/modules.rs')
-rw-r--r-- | core/modules.rs | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/core/modules.rs b/core/modules.rs index e03f86c01..ddd55199b 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -1649,7 +1649,6 @@ impl ModuleMap { #[cfg(test)] mod tests { use super::*; - use crate::Extension; use crate::JsRuntime; use crate::RuntimeOptions; use crate::Snapshot; @@ -1990,12 +1989,10 @@ import "/a.js"; 43 } - let ext = Extension::builder("test_ext") - .ops(vec![op_test::decl()]) - .build(); + deno_core::extension!(test_ext, ops = [op_test]); let mut runtime = JsRuntime::new(RuntimeOptions { - extensions: vec![ext], + extensions: vec![test_ext::init_ops()], module_loader: Some(loader), ..Default::default() }); |