diff options
Diffstat (limited to 'runtime/ops/process.rs')
-rw-r--r-- | runtime/ops/process.rs | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index d6b4dcc1f..c2ca2c687 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -8,8 +8,6 @@ use crate::permissions::Permissions; use deno_core::error::bad_resource_id; use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::serde_json::json; -use deno_core::serde_json::Value; use deno_core::AsyncMutFuture; use deno_core::AsyncRefCell; use deno_core::OpState; @@ -18,6 +16,7 @@ use deno_core::Resource; use deno_core::ResourceId; use deno_core::ZeroCopyBuf; use serde::Deserialize; +use serde::Serialize; use std::borrow::Cow; use std::cell::RefCell; use std::rc::Rc; @@ -81,11 +80,22 @@ impl ChildResource { } } +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +// TODO(@AaronO): maybe find a more descriptive name or a convention for return structs +struct RunInfo { + rid: ResourceId, + pid: Option<u32>, + stdin_rid: Option<ResourceId>, + stdout_rid: Option<ResourceId>, + stderr_rid: Option<ResourceId>, +} + fn op_run( state: &mut OpState, run_args: RunArgs, _zero_copy: Option<ZeroCopyBuf>, -) -> Result<Value, AnyError> { +) -> Result<RunInfo, AnyError> { state.borrow::<Permissions>().run.check()?; let args = run_args.cmd; @@ -166,28 +176,28 @@ fn op_run( }; let child_rid = state.resource_table.add(child_resource); - Ok(json!({ - "rid": child_rid, - "pid": pid, - "stdinRid": stdin_rid, - "stdoutRid": stdout_rid, - "stderrRid": stderr_rid, - })) + Ok(RunInfo { + rid: child_rid, + pid, + stdin_rid, + stdout_rid, + stderr_rid, + }) } -#[derive(Deserialize)] +#[derive(Serialize)] #[serde(rename_all = "camelCase")] -pub struct RunStatusArgs { - rid: ResourceId, +struct RunStatus { + got_signal: bool, + exit_code: i32, + exit_signal: i32, } async fn op_run_status( state: Rc<RefCell<OpState>>, - args: RunStatusArgs, + rid: ResourceId, _zero_copy: Option<ZeroCopyBuf>, -) -> Result<Value, AnyError> { - let rid = args.rid; - +) -> Result<RunStatus, AnyError> { { let s = state.borrow(); s.borrow::<Permissions>().run.check()?; @@ -212,11 +222,11 @@ async fn op_run_status( .expect("Should have either an exit code or a signal."); let got_signal = signal.is_some(); - Ok(json!({ - "gotSignal": got_signal, - "exitCode": code.unwrap_or(-1), - "exitSignal": signal.unwrap_or(-1), - })) + Ok(RunStatus { + got_signal, + exit_code: code.unwrap_or(-1), + exit_signal: signal.unwrap_or(-1), + }) } #[cfg(unix)] @@ -280,10 +290,10 @@ fn op_kill( state: &mut OpState, args: KillArgs, _zero_copy: Option<ZeroCopyBuf>, -) -> Result<Value, AnyError> { +) -> Result<(), AnyError> { super::check_unstable(state, "Deno.kill"); state.borrow::<Permissions>().run.check()?; kill(args.pid, args.signo)?; - Ok(json!({})) + Ok(()) } |