node/typings/internalBinding/process_wrap.d.ts
Yagiz Nizipli 2ab9848fe4
child_process: pass spawn options to the binding positionally
ChildProcess.prototype.spawn() handed a single options object to the
ProcessWrap::Spawn() binding, which then read about a dozen properties
back out individually with Object::Get(). Each of those is a property
lookup across the JS/C++ boundary on every spawn.

Pass file, args, cwd, envPairs, stdio, uid and gid as positional
arguments and pack the boolean flags (detached, windowsHide,
windowsVerbatimArguments) into a single integer whose bit values are
exported from the binding as `constants`. The native side then reads
each value directly from the call arguments.

Add internal typings for the process_wrap binding (previously untyped)
describing the new positional spawn() signature and the exported
constants.

There is no observable behavior change. Spawn wall-clock time is
dominated by the operating system process-creation cost and is
unchanged; this reduces the per-spawn work done on the main thread and
clarifies the contract between the JS and C++ layers.

Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
PR-URL: https://github.com/nodejs/node/pull/63930
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
2026-06-20 17:51:44 +02:00

43 lines
1.1 KiB
TypeScript

import { owner_symbol } from './symbols';
declare namespace InternalProcessWrapBinding {
type StdioType = 'ignore' | 'pipe' | 'overlapped' | 'wrap' | 'inherit' | 'fd';
interface StdioContainer {
type: StdioType;
handle?: object;
fd?: number;
}
class Process {
constructor();
[owner_symbol]?: object;
pid: number;
onexit: (exitCode: number, signalCode: string) => void;
spawn(
file: string,
args: string[] | undefined,
cwd: string | undefined,
envPairs: string[] | undefined,
stdio: StdioContainer[],
flags: number,
uid: number | null | undefined,
gid: number | null | undefined,
): number;
kill(signal: number): number;
ref(): void;
unref(): void;
close(callback?: () => void): void;
}
interface ProcessConstants {
kProcessFlagDetached: number;
kProcessFlagWindowsHide: number;
kProcessFlagWindowsVerbatimArguments: number;
}
}
export interface ProcessWrapBinding {
Process: typeof InternalProcessWrapBinding.Process;
constants: InternalProcessWrapBinding.ProcessConstants;
}