11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst child_process = require('child_process'); 51cb0ef41Sopenharmony_ciconst { once } = require('events'); 61cb0ef41Sopenharmony_ciconst { inspect } = require('util'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciif (process.argv[2] !== 'child') { 91cb0ef41Sopenharmony_ci for (const value of [null, 42, Infinity, 'foo']) { 101cb0ef41Sopenharmony_ci assert.throws(() => { 111cb0ef41Sopenharmony_ci child_process.spawn(process.execPath, [], { serialization: value }); 121cb0ef41Sopenharmony_ci }, { 131cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_VALUE', 141cb0ef41Sopenharmony_ci message: "The property 'options.serialization' " + 151cb0ef41Sopenharmony_ci "must be one of: undefined, 'json', 'advanced'. " + 161cb0ef41Sopenharmony_ci `Received ${inspect(value)}` 171cb0ef41Sopenharmony_ci }); 181cb0ef41Sopenharmony_ci } 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci (async () => { 211cb0ef41Sopenharmony_ci const cp = child_process.spawn(process.execPath, [__filename, 'child'], 221cb0ef41Sopenharmony_ci { 231cb0ef41Sopenharmony_ci stdio: ['ipc', 'inherit', 'inherit'], 241cb0ef41Sopenharmony_ci serialization: 'advanced' 251cb0ef41Sopenharmony_ci }); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci const circular = {}; 281cb0ef41Sopenharmony_ci circular.circular = circular; 291cb0ef41Sopenharmony_ci for await (const message of [ 301cb0ef41Sopenharmony_ci { uint8: new Uint8Array(4) }, 311cb0ef41Sopenharmony_ci { float64: new Float64Array([ Math.PI ]) }, 321cb0ef41Sopenharmony_ci { buffer: Buffer.from('Hello!') }, 331cb0ef41Sopenharmony_ci { map: new Map([{ a: 1 }, { b: 2 }]) }, 341cb0ef41Sopenharmony_ci { bigInt: 1337n }, 351cb0ef41Sopenharmony_ci circular, 361cb0ef41Sopenharmony_ci new Error('Something went wrong'), 371cb0ef41Sopenharmony_ci new RangeError('Something range-y went wrong'), 381cb0ef41Sopenharmony_ci ]) { 391cb0ef41Sopenharmony_ci cp.send(message); 401cb0ef41Sopenharmony_ci const [ received ] = await once(cp, 'message'); 411cb0ef41Sopenharmony_ci assert.deepStrictEqual(received, message); 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci cp.disconnect(); 451cb0ef41Sopenharmony_ci })().then(common.mustCall()); 461cb0ef41Sopenharmony_ci} else { 471cb0ef41Sopenharmony_ci process.on('message', (msg) => process.send(msg)); 481cb0ef41Sopenharmony_ci} 49