diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/metrics.rs | 28 | ||||
-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 |
4 files changed, 36 insertions, 25 deletions
diff --git a/runtime/metrics.rs b/runtime/metrics.rs index b42e0c551..a80ec5e21 100644 --- a/runtime/metrics.rs +++ b/runtime/metrics.rs @@ -101,27 +101,27 @@ impl OpMetrics { } } -use deno_core::BufVec; use deno_core::Op; use deno_core::OpFn; -use deno_core::OpState; -use std::cell::RefCell; use std::collections::HashMap; -use std::rc::Rc; pub fn metrics_op(name: &'static str, op_fn: Box<OpFn>) -> Box<OpFn> { - Box::new(move |op_state: Rc<RefCell<OpState>>, bufs: BufVec| -> Op { + Box::new(move |op_state, payload, buf| -> Op { // TODOs: // * The 'bytes' metrics seem pretty useless, especially now that the // distinction between 'control' and 'data' buffers has become blurry. // * Tracking completion of async ops currently makes us put the boxed // future into _another_ box. Keeping some counters may not be expensive // in itself, but adding a heap allocation for every metric seems bad. - let mut buf_len_iter = bufs.iter().map(|buf| buf.len()); - let bytes_sent_control = buf_len_iter.next().unwrap_or(0); - let bytes_sent_data = buf_len_iter.sum(); - let op = (op_fn)(op_state.clone(), bufs); + // TODO: remove this, doesn't make a ton of sense + let bytes_sent_control = 0; + let bytes_sent_data = match buf { + Some(ref b) => b.len(), + None => 0, + }; + + let op = (op_fn)(op_state.clone(), payload, buf); let op_state_ = op_state.clone(); let mut s = op_state.borrow_mut(); @@ -138,17 +138,17 @@ pub fn metrics_op(name: &'static str, op_fn: Box<OpFn>) -> Box<OpFn> { match op { Op::Sync(buf) => { - metrics.op_sync(bytes_sent_control, bytes_sent_data, buf.len()); + metrics.op_sync(bytes_sent_control, bytes_sent_data, 0); Op::Sync(buf) } Op::Async(fut) => { metrics.op_dispatched_async(bytes_sent_control, bytes_sent_data); let fut = fut - .inspect(move |buf| { + .inspect(move |_resp| { let mut s = op_state_.borrow_mut(); let runtime_metrics = s.borrow_mut::<RuntimeMetrics>(); let metrics = runtime_metrics.ops.get_mut(name).unwrap(); - metrics.op_completed_async(buf.len()); + metrics.op_completed_async(0); }) .boxed_local(); Op::Async(fut) @@ -156,11 +156,11 @@ pub fn metrics_op(name: &'static str, op_fn: Box<OpFn>) -> Box<OpFn> { Op::AsyncUnref(fut) => { metrics.op_dispatched_async_unref(bytes_sent_control, bytes_sent_data); let fut = fut - .inspect(move |buf| { + .inspect(move |_resp| { let mut s = op_state_.borrow_mut(); let runtime_metrics = s.borrow_mut::<RuntimeMetrics>(); let metrics = runtime_metrics.ops.get_mut(name).unwrap(); - metrics.op_completed_async_unref(buf.len()); + metrics.op_completed_async_unref(0); }) .boxed_local(); Op::AsyncUnref(fut) 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, |