diff options
Diffstat (limited to 'core/extensions.rs')
-rw-r--r-- | core/extensions.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/core/extensions.rs b/core/extensions.rs index 129e7b62a..b981e6da2 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -38,6 +38,7 @@ impl OpDecl { #[derive(Default)] pub struct Extension { js_files: Option<Vec<SourcePair>>, + esm_files: Option<Vec<SourcePair>>, ops: Option<Vec<OpDecl>>, opstate_fn: Option<Box<OpStateFn>>, middleware_fn: Option<Box<OpMiddlewareFn>>, @@ -81,13 +82,20 @@ impl Extension { /// returns JS source code to be loaded into the isolate (either at snapshotting, /// or at startup). as a vector of a tuple of the file name, and the source code. - pub fn init_js(&self) -> &[SourcePair] { + pub fn get_js_sources(&self) -> &[SourcePair] { match &self.js_files { Some(files) => files, None => &[], } } + pub fn get_esm_sources(&self) -> &[SourcePair] { + match &self.esm_files { + Some(files) => files, + None => &[], + } + } + /// Called at JsRuntime startup to initialize ops in the isolate. pub fn init_ops(&mut self) -> Option<Vec<OpDecl>> { // TODO(@AaronO): maybe make op registration idempotent @@ -145,6 +153,7 @@ impl Extension { #[derive(Default)] pub struct ExtensionBuilder { js: Vec<SourcePair>, + esm: Vec<SourcePair>, ops: Vec<OpDecl>, state: Option<Box<OpStateFn>>, middleware: Option<Box<OpMiddlewareFn>>, @@ -164,6 +173,11 @@ impl ExtensionBuilder { self } + pub fn esm(&mut self, js_files: Vec<SourcePair>) -> &mut Self { + self.esm.extend(js_files); + self + } + pub fn ops(&mut self, ops: Vec<OpDecl>) -> &mut Self { self.ops.extend(ops); self @@ -195,10 +209,12 @@ impl ExtensionBuilder { pub fn build(&mut self) -> Extension { let js_files = Some(std::mem::take(&mut self.js)); + let esm_files = Some(std::mem::take(&mut self.esm)); let ops = Some(std::mem::take(&mut self.ops)); let deps = Some(std::mem::take(&mut self.deps)); Extension { js_files, + esm_files, ops, opstate_fn: self.state.take(), middleware_fn: self.middleware.take(), |