Skip to content
Myr

ipc-input.js

This file

Path

lib/ipc/ipc-input.js

55 lines · 1.5 KiB · JavaScript

Last changed by

Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a

History of this file

Take it

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

line 1why, one step back
1import {serialize} from 'node:v8';

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 2why, one step back
2import {sendMessage} from './send.js';

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 3–13why, one step back
3
4// Validate the `ipcInput` option5export const validateIpcInputOption = ({ipcInput, ipc, serialization}) => {6 if (ipcInput === undefined) {7 return;8 }910 if (!ipc) {11 throw new Error('The `ipcInput` option cannot be set unless the `ipc` option is `true`.');12 }13

Harden some thingsSindre Sorhusbefore adoption4a0a121

lines 14–15why, one step back
14 // An invalid `serialization` option is reported by `node:child_process` when spawning, like when `ipcInput` is not used
15 validateIpcInput[serialization]?.(ipcInput);

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 16–21why, one step back
16};
1718const validateAdvancedInput = ipcInput => {19 try {20 serialize(ipcInput);21 } catch (error) {

Improve IPC error messages (#1090)ehmickybefore adoptione6b012a

line 22why, one step back
22 throw new Error('The `ipcInput` option is not serializable with a structured clone.', {cause: error});

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 23–27why, one step back
23 }
24};2526const validateJsonInput = ipcInput => {27 try {

Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a

lines 28–31why, one step back
28 // `JSON.stringify()` returns `undefined` instead of throwing for values it cannot represent, such as functions and symbols
29 if (JSON.stringify(ipcInput) === undefined) {30 throw new TypeError('The value cannot be represented as JSON.');31 }

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

line 32why, one step back
32 } catch (error) {

Improve IPC error messages (#1090)ehmickybefore adoptione6b012a

line 33why, one step back
33 throw new Error('The `ipcInput` option is not serializable with JSON.', {cause: error});

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 34–37why, one step back
34 }
35};3637const validateIpcInput = {

Harden some thingsSindre Sorhusbefore adoption4a0a121

line 38why, one step back
38 __proto__: null,

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 39–43why, one step back
39 advanced: validateAdvancedInput,
40 json: validateJsonInput,41};4243// When the `ipcInput` option is set, it is sent as an initial IPC message to the subprocess

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 44why, one step back
44export const sendIpcInput = async (subprocess, ipcInput, ipc) => {

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 45–48why, one step back
45 if (ipcInput === undefined) {
46 return;47 }48

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

lines 49–54why, one step back
49 await sendMessage({
50 anyProcess: subprocess,51 channel: subprocess.channel,52 isSubprocess: false,53 ipc,54 }, ipcInput);

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

line 55why, one step back
55};