diff options
Diffstat (limited to 'cli/ops')
-rw-r--r-- | cli/ops/dispatch_json.rs | 13 | ||||
-rw-r--r-- | cli/ops/dispatch_minimal.rs | 11 | ||||
-rw-r--r-- | cli/ops/plugin.rs | 4 |
3 files changed, 13 insertions, 15 deletions
diff --git a/cli/ops/dispatch_json.rs b/cli/ops/dispatch_json.rs index 97a02991f..26ffc7d33 100644 --- a/cli/ops/dispatch_json.rs +++ b/cli/ops/dispatch_json.rs @@ -46,7 +46,7 @@ struct AsyncArgs { pub fn json_op<D>( d: D, -) -> impl Fn(&mut CoreIsolateState, &[u8], &mut [ZeroCopyBuf]) -> Op +) -> impl Fn(&mut CoreIsolateState, &mut [ZeroCopyBuf]) -> Op where D: Fn( &mut CoreIsolateState, @@ -54,10 +54,9 @@ where &mut [ZeroCopyBuf], ) -> Result<JsonOp, OpError>, { - move |isolate_state: &mut CoreIsolateState, - control: &[u8], - zero_copy: &mut [ZeroCopyBuf]| { - let async_args: AsyncArgs = match serde_json::from_slice(control) { + move |isolate_state: &mut CoreIsolateState, zero_copy: &mut [ZeroCopyBuf]| { + assert!(!zero_copy.is_empty(), "Expected JSON string at position 0"); + let async_args: AsyncArgs = match serde_json::from_slice(&zero_copy[0]) { Ok(args) => args, Err(e) => { let buf = serialize_result(None, Err(OpError::from(e))); @@ -67,9 +66,9 @@ where let promise_id = async_args.promise_id; let is_sync = promise_id.is_none(); - let result = serde_json::from_slice(control) + let result = serde_json::from_slice(&zero_copy[0]) .map_err(OpError::from) - .and_then(|args| d(isolate_state, args, zero_copy)); + .and_then(|args| d(isolate_state, args, &mut zero_copy[1..])); // Convert to Op match result { diff --git a/cli/ops/dispatch_minimal.rs b/cli/ops/dispatch_minimal.rs index eac5ad055..45b90ef81 100644 --- a/cli/ops/dispatch_minimal.rs +++ b/cli/ops/dispatch_minimal.rs @@ -116,14 +116,13 @@ fn test_parse_min_record() { pub fn minimal_op<D>( d: D, -) -> impl Fn(&mut CoreIsolateState, &[u8], &mut [ZeroCopyBuf]) -> Op +) -> impl Fn(&mut CoreIsolateState, &mut [ZeroCopyBuf]) -> Op where D: Fn(&mut CoreIsolateState, bool, i32, &mut [ZeroCopyBuf]) -> MinimalOp, { - move |isolate_state: &mut CoreIsolateState, - control: &[u8], - zero_copy: &mut [ZeroCopyBuf]| { - let mut record = match parse_min_record(control) { + move |isolate_state: &mut CoreIsolateState, zero_copy: &mut [ZeroCopyBuf]| { + assert!(!zero_copy.is_empty(), "Expected record at position 0"); + let mut record = match parse_min_record(&zero_copy[0]) { Some(r) => r, None => { let e = OpError::type_error("Unparsable control buffer".to_string()); @@ -138,7 +137,7 @@ where }; let is_sync = record.promise_id == 0; let rid = record.arg; - let min_op = d(isolate_state, is_sync, rid, zero_copy); + let min_op = d(isolate_state, is_sync, rid, &mut zero_copy[1..]); match min_op { MinimalOp::Sync(sync_result) => Op::Sync(match sync_result { diff --git a/cli/ops/plugin.rs b/cli/ops/plugin.rs index 775178f1e..16debac50 100644 --- a/cli/ops/plugin.rs +++ b/cli/ops/plugin.rs @@ -110,9 +110,9 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> { let plugin_lib = self.plugin_lib.clone(); self.isolate_state.op_registry.register( name, - move |isolate_state, control, zero_copy| { + move |isolate_state, zero_copy| { let mut interface = PluginInterface::new(isolate_state, &plugin_lib); - let op = dispatch_op_fn(&mut interface, control, zero_copy); + let op = dispatch_op_fn(&mut interface, zero_copy); match op { sync_op @ Op::Sync(..) => sync_op, Op::Async(fut) => { |