summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-12-13 15:44:16 +0530
committerGitHub <noreply@github.com>2023-12-13 11:14:16 +0100
commit5a91a065b882215dde209baf626247e54c21a392 (patch)
tree192cb8b3b0a4037453b5fd5b2a60e4d52d4543a8 /runtime/js
parentbbf8f69cb979be0f36c38ae52b1588e648b3252e (diff)
fix: implement child_process IPC (#21490)
This PR implements the Node child_process IPC functionality in Deno on Unix systems. For `fd > 2` a duplex unix pipe is set up between the parent and child processes. Currently implements data passing via the channel in the JSON serialization format.
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/40_process.js10
-rw-r--r--runtime/js/99_main.js3
2 files changed, 12 insertions, 1 deletions
diff --git a/runtime/js/40_process.js b/runtime/js/40_process.js
index b8e05ce5a..e628aeb4a 100644
--- a/runtime/js/40_process.js
+++ b/runtime/js/40_process.js
@@ -159,6 +159,7 @@ function spawnChildInner(opFn, command, apiName, {
stderr = "piped",
signal = undefined,
windowsRawArguments = false,
+ ipc = -1,
} = {}) {
const child = opFn({
cmd: pathFromURL(command),
@@ -172,6 +173,7 @@ function spawnChildInner(opFn, command, apiName, {
stdout,
stderr,
windowsRawArguments,
+ ipc,
}, apiName);
return new ChildProcess(illegalConstructorKey, {
...child,
@@ -203,6 +205,12 @@ class ChildProcess {
#waitPromise;
#waitComplete = false;
+ #pipeFd;
+ // internal, used by ext/node
+ get _pipeFd() {
+ return this.#pipeFd;
+ }
+
#pid;
get pid() {
return this.#pid;
@@ -239,6 +247,7 @@ class ChildProcess {
stdinRid,
stdoutRid,
stderrRid,
+ pipeFd, // internal
} = null) {
if (key !== illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
@@ -246,6 +255,7 @@ class ChildProcess {
this.#rid = rid;
this.#pid = pid;
+ this.#pipeFd = pipeFd;
if (stdinRid !== null) {
this.#stdin = writableStreamForRid(stdinRid);
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 0469b38bf..5b4b164a2 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -440,6 +440,7 @@ function bootstrapMainRuntime(runtimeOptions) {
3: inspectFlag,
5: hasNodeModulesDir,
6: maybeBinaryNpmCommandName,
+ 7: nodeIpcFd,
} = runtimeOptions;
performance.setTimeOrigin(DateNow());
@@ -545,7 +546,7 @@ function bootstrapMainRuntime(runtimeOptions) {
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
if (nodeBootstrap) {
- nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName);
+ nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName, nodeIpcFd);
}
}