diff options
| author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2022-03-15 23:43:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-15 23:43:17 +0100 |
| commit | bb53135ed87ec063c9238e1b7de8cf3b44535685 (patch) | |
| tree | 76dfbbfedf1de3482b1d179c46aa855bc6a8e544 /core/extensions.rs | |
| parent | 5d60ee7f1280d8000b918e7fb9e11e3ddca779e7 (diff) | |
cleanup(core): OpPair => OpDecl (#13952)
Diffstat (limited to 'core/extensions.rs')
| -rw-r--r-- | core/extensions.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/core/extensions.rs b/core/extensions.rs index 7361165f0..ae4537af4 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -6,15 +6,20 @@ use std::task::Context; pub type SourcePair = (&'static str, Box<SourceLoadFn>); pub type SourceLoadFn = dyn Fn() -> Result<String, Error>; pub type OpFnRef = v8::FunctionCallback; -pub type OpPair = (&'static str, OpFnRef); -pub type OpMiddlewareFn = dyn Fn(&'static str, OpFnRef) -> OpFnRef; +pub type OpMiddlewareFn = dyn Fn(OpDecl) -> OpDecl; pub type OpStateFn = dyn Fn(&mut OpState) -> Result<(), Error>; pub type OpEventLoopFn = dyn Fn(&mut OpState, &mut Context) -> bool; +#[derive(Clone, Copy)] +pub struct OpDecl { + pub name: &'static str, + pub v8_fn_ptr: OpFnRef, +} + #[derive(Default)] pub struct Extension { js_files: Option<Vec<SourcePair>>, - ops: Option<Vec<OpPair>>, + ops: Option<Vec<OpDecl>>, opstate_fn: Option<Box<OpStateFn>>, middleware_fn: Option<Box<OpMiddlewareFn>>, event_loop_middleware: Option<Box<OpEventLoopFn>>, @@ -38,7 +43,7 @@ impl Extension { } /// Called at JsRuntime startup to initialize ops in the isolate. - pub fn init_ops(&mut self) -> Option<Vec<OpPair>> { + pub fn init_ops(&mut self) -> Option<Vec<OpDecl>> { // TODO(@AaronO): maybe make op registration idempotent if self.initialized { panic!("init_ops called twice: not idempotent or correct"); @@ -82,7 +87,7 @@ impl Extension { #[derive(Default)] pub struct ExtensionBuilder { js: Vec<SourcePair>, - ops: Vec<OpPair>, + ops: Vec<OpDecl>, state: Option<Box<OpStateFn>>, middleware: Option<Box<OpMiddlewareFn>>, event_loop_middleware: Option<Box<OpEventLoopFn>>, @@ -94,7 +99,7 @@ impl ExtensionBuilder { self } - pub fn ops(&mut self, ops: Vec<OpPair>) -> &mut Self { + pub fn ops(&mut self, ops: Vec<OpDecl>) -> &mut Self { self.ops.extend(ops); self } @@ -109,7 +114,7 @@ impl ExtensionBuilder { pub fn middleware<F>(&mut self, middleware_fn: F) -> &mut Self where - F: Fn(&'static str, OpFnRef) -> OpFnRef + 'static, + F: Fn(OpDecl) -> OpDecl + 'static, { self.middleware = Some(Box::new(middleware_fn)); self |
