use std::cell::RefCell; use std::convert::Infallible; use std::io; use std::rc::Rc; use std::sync::Arc; use avril_caps::Capabilities; use avril_core::serde_v8::JsBuffer; use avril_core::{Extension, Op}; use avril_host::environment::Environment; use tokio::runtime::Handle; use avril_ext_file::Files; use avril_host::io::response; pub struct Tree; #[allow(dead_code)] impl Tree { pub fn global() -> Arc { Arc::new(Self) } pub(crate) fn stop_live_processes(&self) {} pub fn force_live_processes(&self) {} pub fn stop_sync_processes(&self) {} pub fn claim_term( &self, runtime: &Handle, owner: Arc, ) -> io::Result<()> { #[cfg(unix)] { let _enter = runtime.enter(); let mut termination = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())?; runtime.spawn(async move { while termination.recv().await.is_some() { owner(); } }); } #[cfg(not(unix))] let _ = (runtime, owner); Ok(()) } } pub fn init( runtime: Handle, _caps: Arc, _environment: Rc>, _files: Arc, _owner: tokio_util::sync::CancellationToken, worker: bool, _signal: super::SignalMode, ) -> Extension { let unavailable = || { response(Err::<(), _>(io::Error::new( io::ErrorKind::Unsupported, "Subprocess execution is not supported on this platform", ))) }; let mut ops = vec![ Op::new("op_process_spawn", move |_options: serde_json::Value| { Ok::<_, Infallible>(unavailable()) }), Op::new( "op_process_run_sync", move |_options: (serde_json::Value, Option)| { Ok::<_, Infallible>(unavailable()) }, ), Op::new("op_process_release", |_id: u64| Ok::<_, Infallible>(())), ]; for name in [ "op_process_cancel_read", "op_process_ref", "op_process_kill", "op_process_stop", "op_process_resize", ] { ops.push(Op::new(name, move |_args: serde_json::Value| { Ok::<_, Infallible>(unavailable()) })); } for name in [ "op_process_read", "op_process_write", "op_process_end", "op_process_wait", ] { ops.push(Op::asynchronous_unreferenced( name, move |_args: serde_json::Value| async move { Ok::<_, Infallible>(unavailable()) }, )); } ops.push(Op::asynchronous( "op_process_keepalive", move |_args: serde_json::Value| async move { Ok::<_, Infallible>(unavailable()) }, )); // Signal listeners report NotSupported through the shared ops, like the // file operations map Unsupported. ops.extend(super::signals::ops(&super::signals::State::create( runtime, worker, ))); Extension { name: "ext:process", dependencies: &["ext:encoding", "ext:file", "ext:web", "ext:webstreams"], ops, modules: &[ ( "ext:process/main.js", include_str!(concat!(env!("OUT_DIR"), "/process.js")), ), ( "ext:process/signals.js", include_str!(concat!(env!("OUT_DIR"), "/signals.js")), ), ], entry_point: None, } }