summaryrefslogtreecommitdiff
path: root/core/extensions.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-09 08:10:54 -0400
committerGitHub <noreply@github.com>2023-03-09 12:10:54 +0000
commitc3cba7f22c49ca3a3f58df44d8ea4c85d8510bff (patch)
treec710275a5c51b8a4c8175a3ebe92c928272bf3dc /core/extensions.rs
parent521cb4ca9b9b02f7ba3150338d5f3c4b035aab8d (diff)
refactor(core): Extension::builder_with_deps (#18093)
Prerequisite for https://github.com/denoland/deno/pull/18080
Diffstat (limited to 'core/extensions.rs')
-rw-r--r--core/extensions.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/core/extensions.rs b/core/extensions.rs
index 0ee6790ec..3d17db592 100644
--- a/core/extensions.rs
+++ b/core/extensions.rs
@@ -77,7 +77,7 @@ pub struct Extension {
initialized: bool,
enabled: bool,
name: &'static str,
- deps: Option<Vec<&'static str>>,
+ deps: Option<&'static [&'static str]>,
}
// Note: this used to be a trait, but we "downgraded" it to a single concrete type
@@ -90,11 +90,22 @@ impl Extension {
}
}
+ pub fn builder_with_deps(
+ name: &'static str,
+ deps: &'static [&'static str],
+ ) -> ExtensionBuilder {
+ ExtensionBuilder {
+ name,
+ deps,
+ ..Default::default()
+ }
+ }
+
/// Check if dependencies have been loaded, and errors if either:
/// - The extension is depending on itself or an extension with the same name.
/// - A dependency hasn't been loaded yet.
pub fn check_dependencies(&self, previous_exts: &[&mut Extension]) {
- if let Some(deps) = &self.deps {
+ if let Some(deps) = self.deps {
'dep_loop: for dep in deps {
if dep == &self.name {
panic!("Extension '{}' is either depending on itself or there is another extension with the same name", self.name);
@@ -194,15 +205,10 @@ pub struct ExtensionBuilder {
middleware: Option<Box<OpMiddlewareFn>>,
event_loop_middleware: Option<Box<OpEventLoopFn>>,
name: &'static str,
- deps: Vec<&'static str>,
+ deps: &'static [&'static str],
}
impl ExtensionBuilder {
- pub fn dependencies(&mut self, dependencies: Vec<&'static str>) -> &mut Self {
- self.deps.extend(dependencies);
- self
- }
-
pub fn js(&mut self, js_files: Vec<ExtensionFileSource>) -> &mut Self {
let js_files =
// TODO(bartlomieju): if we're automatically remapping here, then we should