diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/js/globals.ts | 13 | ||||
-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 | ||||
-rw-r--r-- | cli/state.rs | 18 |
5 files changed, 24 insertions, 35 deletions
diff --git a/cli/js/globals.ts b/cli/js/globals.ts index c73a2a6ab..4548c8304 100644 --- a/cli/js/globals.ts +++ b/cli/js/globals.ts @@ -77,14 +77,9 @@ declare global { interface DenoCore { print(s: string, isErr?: boolean): void; - dispatch( - opId: number, - control: Uint8Array, - ...zeroCopy: ArrayBufferView[] - ): Uint8Array | null; + dispatch(opId: number, ...zeroCopy: ArrayBufferView[]): Uint8Array | null; dispatchByName( opName: string, - control: Uint8Array, ...zeroCopy: ArrayBufferView[] ): Uint8Array | null; setAsyncHandler(opId: number, cb: (msg: Uint8Array) => void): void; @@ -101,11 +96,7 @@ declare global { recv(cb: (opId: number, msg: Uint8Array) => void): void; - send( - opId: number, - control: null | ArrayBufferView, - ...data: ArrayBufferView[] - ): null | Uint8Array; + send(opId: number, ...data: ArrayBufferView[]): null | Uint8Array; setMacrotaskCallback(cb: () => boolean): void; 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) => { diff --git a/cli/state.rs b/cli/state.rs index 39bd8a565..5f3873510 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -65,7 +65,7 @@ impl State { pub fn stateful_json_op<D>( &self, dispatcher: D, - ) -> impl Fn(&mut deno_core::CoreIsolateState, &[u8], &mut [ZeroCopyBuf]) -> Op + ) -> impl Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op where D: Fn(&State, Value, &mut [ZeroCopyBuf]) -> Result<JsonOp, OpError>, { @@ -76,7 +76,7 @@ impl State { pub fn stateful_json_op2<D>( &self, dispatcher: D, - ) -> impl Fn(&mut deno_core::CoreIsolateState, &[u8], &mut [ZeroCopyBuf]) -> Op + ) -> impl Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op where D: Fn( &mut deno_core::CoreIsolateState, @@ -95,21 +95,21 @@ impl State { pub fn core_op<D>( &self, dispatcher: D, - ) -> impl Fn(&mut deno_core::CoreIsolateState, &[u8], &mut [ZeroCopyBuf]) -> Op + ) -> impl Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op where - D: Fn(&mut deno_core::CoreIsolateState, &[u8], &mut [ZeroCopyBuf]) -> Op, + D: Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op, { let state = self.clone(); move |isolate_state: &mut deno_core::CoreIsolateState, - control: &[u8], zero_copy: &mut [ZeroCopyBuf]| -> Op { - let bytes_sent_control = control.len() as u64; + let bytes_sent_control = + zero_copy.get(0).map(|s| s.len()).unwrap_or(0) as u64; let bytes_sent_zero_copy = - zero_copy.iter().map(|b| b.len()).sum::<usize>() as u64; + zero_copy[1..].iter().map(|b| b.len()).sum::<usize>() as u64; - let op = dispatcher(isolate_state, control, zero_copy); + let op = dispatcher(isolate_state, zero_copy); match op { Op::Sync(buf) => { @@ -155,7 +155,7 @@ impl State { pub fn stateful_minimal_op2<D>( &self, dispatcher: D, - ) -> impl Fn(&mut deno_core::CoreIsolateState, &[u8], &mut [ZeroCopyBuf]) -> Op + ) -> impl Fn(&mut deno_core::CoreIsolateState, &mut [ZeroCopyBuf]) -> Op where D: Fn( &mut deno_core::CoreIsolateState, |