From 81a6504e670d32bdc5e0a8328c328fdf8e208913 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 15 Dec 2023 16:20:05 +0530 Subject: refactor: setup child process pipe in Rust (#21579) Avoid passing the fd into JS and back into Rust. Instead we setup the child's end of the pipe directly using a special Rust op. --- ext/node/polyfills/02_init.js | 3 +-- ext/node/polyfills/child_process.ts | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'ext/node/polyfills') 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); } -- cgit v1.2.3