diff options
Diffstat (limited to 'ext/node')
-rw-r--r-- | ext/node/lib.rs | 2 | ||||
-rw-r--r-- | ext/node/ops/ipc.rs | 24 | ||||
-rw-r--r-- | ext/node/polyfills/02_init.js | 3 | ||||
-rw-r--r-- | ext/node/polyfills/child_process.ts | 4 |
4 files changed, 30 insertions, 3 deletions
diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 77f01b3d3..dd3acd17c 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -30,6 +30,7 @@ mod path; mod polyfill; mod resolution; +pub use ops::ipc::ChildPipeFd; pub use ops::v8::VM_CONTEXT_INDEX; pub use package_json::PackageJson; pub use path::PathClean; @@ -313,6 +314,7 @@ deno_core::extension!(deno_node, ops::util::op_node_guess_handle_type, ops::crypto::op_node_create_private_key, ops::ipc::op_node_ipc_pipe, + ops::ipc::op_node_child_ipc_pipe, ops::ipc::op_node_ipc_write, ops::ipc::op_node_ipc_read, ], diff --git a/ext/node/ops/ipc.rs b/ext/node/ops/ipc.rs index d1aeeb40c..afaccc49f 100644 --- a/ext/node/ops/ipc.rs +++ b/ext/node/ops/ipc.rs @@ -6,6 +6,8 @@ pub use unix::*; #[cfg(windows)] pub use windows::*; +pub struct ChildPipeFd(pub i32); + #[cfg(unix)] mod unix { use std::cell::RefCell; @@ -46,6 +48,22 @@ mod unix { Ok(state.resource_table.add(IpcJsonStreamResource::new(fd)?)) } + // Open IPC pipe from bootstrap options. + #[op2] + #[smi] + pub fn op_node_child_ipc_pipe( + state: &mut OpState, + ) -> Result<Option<ResourceId>, AnyError> { + let fd = match state.try_borrow_mut::<crate::ChildPipeFd>() { + Some(child_pipe_fd) => child_pipe_fd.0, + None => return Ok(None), + }; + + Ok(Some( + state.resource_table.add(IpcJsonStreamResource::new(fd)?), + )) + } + #[op2(async)] pub async fn op_node_ipc_write( state: Rc<RefCell<OpState>>, @@ -492,6 +510,12 @@ mod windows { Err(deno_core::error::not_supported()) } + #[op2(fast)] + #[smi] + pub fn op_node_child_ipc_pipe() -> Result<i32, AnyError> { + Ok(-1) + } + #[op2(async)] pub async fn op_node_ipc_write() -> Result<(), AnyError> { Err(deno_core::error::not_supported()) diff --git a/ext/node/polyfills/02_init.js b/ext/node/polyfills/02_init.js index e5a0279a5..8d9405c16 100644 --- a/ext/node/polyfills/02_init.js +++ b/ext/node/polyfills/02_init.js @@ -12,7 +12,6 @@ let initialized = false; function initialize( usesLocalNodeModulesDir, argv0, - ipcFd, ) { if (initialized) { throw Error("Node runtime already initialized"); @@ -38,7 +37,7 @@ function initialize( // but it's the only way to get `args` and `version` and this point. internals.__bootstrapNodeProcess(argv0, Deno.args, Deno.version); internals.__initWorkerThreads(); - internals.__setupChildProcessIpcChannel(ipcFd); + internals.__setupChildProcessIpcChannel(); // `Deno[Deno.internal].requireImpl` will be unreachable after this line. delete internals.requireImpl; } diff --git a/ext/node/polyfills/child_process.ts b/ext/node/polyfills/child_process.ts index c7d007f46..da82546f6 100644 --- a/ext/node/polyfills/child_process.ts +++ b/ext/node/polyfills/child_process.ts @@ -49,6 +49,7 @@ import { } from "ext:deno_node/internal/util.mjs"; const { core } = globalThis.__bootstrap; +const ops = core.ops; const MAX_BUFFER = 1024 * 1024; @@ -822,7 +823,8 @@ export function execFileSync( return ret.stdout as string | Buffer; } -function setupChildProcessIpcChannel(fd: number) { +function setupChildProcessIpcChannel() { + const fd = ops.op_node_child_ipc_pipe(); if (typeof fd != "number" || fd < 0) return; setupChannel(process, fd); } |