diff options
Diffstat (limited to 'runtime/ops')
-rw-r--r-- | runtime/ops/mod.rs | 4 | ||||
-rw-r--r-- | runtime/ops/plugin.rs | 21 | ||||
-rw-r--r-- | runtime/ops/worker_host.rs | 8 |
3 files changed, 22 insertions, 11 deletions
diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs index 2e94d99f5..073b17c86 100644 --- a/runtime/ops/mod.rs +++ b/runtime/ops/mod.rs @@ -48,7 +48,7 @@ pub fn reg_json_async<F, V, R, RV>( F: Fn(Rc<RefCell<OpState>>, V, BufVec) -> R + 'static, V: DeserializeOwned, R: Future<Output = Result<RV, AnyError>> + 'static, - RV: Serialize, + RV: Serialize + 'static, { rt.register_op(name, metrics_op(name, json_op_async(op_fn))); } @@ -57,7 +57,7 @@ pub fn reg_json_sync<F, V, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) where F: Fn(&mut OpState, V, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static, V: DeserializeOwned, - R: Serialize, + R: Serialize + 'static, { rt.register_op(name, metrics_op(name, json_op_sync(op_fn))); } diff --git a/runtime/ops/plugin.rs b/runtime/ops/plugin.rs index 6952cf77f..7fc59d082 100644 --- a/runtime/ops/plugin.rs +++ b/runtime/ops/plugin.rs @@ -10,6 +10,7 @@ use deno_core::BufVec; use deno_core::JsRuntime; use deno_core::Op; use deno_core::OpAsyncFuture; +use deno_core::OpFn; use deno_core::OpId; use deno_core::OpState; use deno_core::Resource; @@ -18,7 +19,6 @@ use dlopen::symbor::Library; use log::debug; use serde::Deserialize; use std::borrow::Cow; -use std::cell::RefCell; use std::path::PathBuf; use std::pin::Pin; use std::rc::Rc; @@ -110,11 +110,17 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> { dispatch_op_fn: plugin_api::DispatchOpFn, ) -> OpId { let plugin_lib = self.plugin_lib.clone(); - let plugin_op_fn = move |state_rc: Rc<RefCell<OpState>>, - mut zero_copy: BufVec| { + let plugin_op_fn: Box<OpFn> = Box::new(move |state_rc, _payload, buf| { + // For sig compat map Option<ZeroCopyBuf> to BufVec + let mut bufs: BufVec = match buf { + Some(b) => vec![b], + None => vec![], + } + .into(); + let mut state = state_rc.borrow_mut(); let mut interface = PluginInterface::new(&mut state, &plugin_lib); - let op = dispatch_op_fn(&mut interface, &mut zero_copy); + let op = dispatch_op_fn(&mut interface, &mut bufs); match op { sync_op @ Op::Sync(..) => sync_op, Op::Async(fut) => Op::Async(PluginOpAsyncFuture::new(&plugin_lib, fut)), @@ -123,13 +129,10 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> { } _ => unreachable!(), } - }; + }); self.state.op_table.register_op( name, - metrics_op( - Box::leak(Box::new(name.to_string())), - Box::new(plugin_op_fn), - ), + metrics_op(Box::leak(Box::new(name.to_string())), plugin_op_fn), ) } } diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index cddde985a..424e7a70c 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -255,6 +255,14 @@ impl<'de> de::Visitor<'de> for ParseBooleanOrStringVec { formatter.write_str("a vector of strings or a boolean") } + // visit_unit maps undefined/missing values to false + fn visit_unit<E>(self) -> Result<UnaryPermissionBase, E> + where + E: de::Error, + { + self.visit_bool(false) + } + fn visit_bool<E>(self, v: bool) -> Result<UnaryPermissionBase, E> where E: de::Error, |