From bb53135ed87ec063c9238e1b7de8cf3b44535685 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Tue, 15 Mar 2022 23:43:17 +0100 Subject: cleanup(core): OpPair => OpDecl (#13952) --- core/extensions.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'core/extensions.rs') 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); pub type SourceLoadFn = dyn Fn() -> Result; 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>, - ops: Option>, + ops: Option>, opstate_fn: Option>, middleware_fn: Option>, event_loop_middleware: Option>, @@ -38,7 +43,7 @@ impl Extension { } /// Called at JsRuntime startup to initialize ops in the isolate. - pub fn init_ops(&mut self) -> Option> { + pub fn init_ops(&mut self) -> Option> { // 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, - ops: Vec, + ops: Vec, state: Option>, middleware: Option>, event_loop_middleware: Option>, @@ -94,7 +99,7 @@ impl ExtensionBuilder { self } - pub fn ops(&mut self, ops: Vec) -> &mut Self { + pub fn ops(&mut self, ops: Vec) -> &mut Self { self.ops.extend(ops); self } @@ -109,7 +114,7 @@ impl ExtensionBuilder { pub fn middleware(&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 -- cgit v1.2.3