diff options
Diffstat (limited to 'ext/node/polyfills')
-rw-r--r-- | ext/node/polyfills/internal/child_process.ts | 20 | ||||
-rw-r--r-- | ext/node/polyfills/process.ts | 6 |
2 files changed, 16 insertions, 10 deletions
diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts index 30c249277..175119afa 100644 --- a/ext/node/polyfills/internal/child_process.ts +++ b/ext/node/polyfills/internal/child_process.ts @@ -56,6 +56,7 @@ import { StringPrototypeSlice } from "ext:deno_node/internal/primordials.mjs"; import { StreamBase } from "ext:deno_node/internal_binding/stream_wrap.ts"; import { Pipe, socketType } from "ext:deno_node/internal_binding/pipe_wrap.ts"; import { Socket } from "node:net"; +import { kDetached, kExtraStdio, kIpc } from "ext:runtime/40_process.js"; export function mapValues<T, O>( record: Readonly<Record<string, T>>, @@ -109,6 +110,7 @@ export function stdioStringToArray( const kClosesNeeded = Symbol("_closesNeeded"); const kClosesReceived = Symbol("_closesReceived"); +const kCanDisconnect = Symbol("_canDisconnect"); // We only want to emit a close event for the child process when all of // the writable streams have closed. The value of `child[kClosesNeeded]` should be 1 + @@ -222,7 +224,7 @@ export class ChildProcess extends EventEmitter { #spawned = Promise.withResolvers<void>(); [kClosesNeeded] = 1; [kClosesReceived] = 0; - canDisconnect = false; + [kCanDisconnect] = false; constructor( command: string, @@ -238,6 +240,7 @@ export class ChildProcess extends EventEmitter { shell = false, signal, windowsVerbatimArguments = false, + detached, } = options || {}; const normalizedStdio = normalizeStdioOption(stdio); const [ @@ -275,8 +278,9 @@ export class ChildProcess extends EventEmitter { stdout: toDenoStdio(stdout), stderr: toDenoStdio(stderr), windowsRawArguments: windowsVerbatimArguments, - ipc, // internal - extraStdio: extraStdioNormalized, + [kIpc]: ipc, // internal + [kExtraStdio]: extraStdioNormalized, + [kDetached]: detached, }).spawn(); this.pid = this.#process.pid; @@ -387,8 +391,8 @@ export class ChildProcess extends EventEmitter { this.emit("exit", exitCode, signalCode); await this.#_waitForChildStreamsToClose(); this.#closePipes(); - maybeClose(this); nextTick(flushStdio, this); + maybeClose(this); }); })(); } catch (err) { @@ -421,7 +425,7 @@ export class ChildProcess extends EventEmitter { } /* Cancel any pending IPC I/O */ - if (this.canDisconnect) { + if (this[kCanDisconnect]) { this.disconnect?.(); } @@ -552,7 +556,7 @@ export interface ChildProcessOptions { stdio?: Array<NodeStdio | number | Stream | null | undefined> | NodeStdio; /** - * NOTE: This option is not yet implemented. + * Whether to spawn the process in a detached state. */ detached?: boolean; @@ -1416,7 +1420,7 @@ export function setupChannel(target: any, ipc: number) { } target.connected = false; - target.canDisconnect = false; + target[kCanDisconnect] = false; control[kControlDisconnect](); process.nextTick(() => { target.channel = null; @@ -1424,7 +1428,7 @@ export function setupChannel(target: any, ipc: number) { target.emit("disconnect"); }); }; - target.canDisconnect = true; + target[kCanDisconnect] = true; // Start reading messages from the channel. readLoop(); diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index f84255814..d7e21b657 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -267,9 +267,11 @@ memoryUsage.rss = function (): number { // Returns a negative error code than can be recognized by errnoException function _kill(pid: number, sig: number): number { + const maybeMapErrno = (res: number) => + res === 0 ? res : uv.mapSysErrnoToUvErrno(res); // signal 0 does not exist in constants.os.signals, thats why it have to be handled explicitly if (sig === 0) { - return op_node_process_kill(pid, 0); + return maybeMapErrno(op_node_process_kill(pid, 0)); } const maybeSignal = Object.entries(constants.os.signals).find(( [_, numericCode], @@ -278,7 +280,7 @@ function _kill(pid: number, sig: number): number { if (!maybeSignal) { return uv.codeMap.get("EINVAL"); } - return op_node_process_kill(pid, sig); + return maybeMapErrno(op_node_process_kill(pid, sig)); } export function dlopen(module, filename, _flags) { |