11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (common.isWindows) { 41cb0ef41Sopenharmony_ci // No way to send CTRL_C_EVENT to processes from JS right now. 51cb0ef41Sopenharmony_ci common.skip('platform not supported'); 61cb0ef41Sopenharmony_ci} 71cb0ef41Sopenharmony_ciif (!common.isMainThread) 81cb0ef41Sopenharmony_ci common.skip('No signal handling available in Workers'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst assert = require('assert'); 111cb0ef41Sopenharmony_ciconst spawn = require('child_process').spawn; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst child = spawn(process.execPath, [ '-i' ], { 141cb0ef41Sopenharmony_ci stdio: [null, null, 2, 'ipc'] 151cb0ef41Sopenharmony_ci}); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cilet stdout = ''; 181cb0ef41Sopenharmony_cichild.stdout.setEncoding('utf8'); 191cb0ef41Sopenharmony_cichild.stdout.on('data', function(c) { 201cb0ef41Sopenharmony_ci stdout += c; 211cb0ef41Sopenharmony_ci}); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_cichild.stdout.once('data', common.mustCall(() => { 241cb0ef41Sopenharmony_ci child.on('message', common.mustCall((msg) => { 251cb0ef41Sopenharmony_ci assert.strictEqual(msg, 'repl is busy'); 261cb0ef41Sopenharmony_ci process.kill(child.pid, 'SIGINT'); 271cb0ef41Sopenharmony_ci child.stdout.once('data', common.mustCall(() => { 281cb0ef41Sopenharmony_ci // Make sure REPL still works. 291cb0ef41Sopenharmony_ci child.stdin.end('"foobar"\n'); 301cb0ef41Sopenharmony_ci })); 311cb0ef41Sopenharmony_ci })); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci child.stdin.write( 341cb0ef41Sopenharmony_ci 'vm.runInThisContext("process.send(\'repl is busy\'); while(true){}", ' + 351cb0ef41Sopenharmony_ci '{ breakOnSigint: true });\n' 361cb0ef41Sopenharmony_ci ); 371cb0ef41Sopenharmony_ci})); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_cichild.on('close', function(code) { 401cb0ef41Sopenharmony_ci const expected = 'Script execution was interrupted by `SIGINT`'; 411cb0ef41Sopenharmony_ci assert.ok( 421cb0ef41Sopenharmony_ci stdout.includes(expected), 431cb0ef41Sopenharmony_ci `Expected stdout to contain "${expected}", got ${stdout}` 441cb0ef41Sopenharmony_ci ); 451cb0ef41Sopenharmony_ci assert.ok( 461cb0ef41Sopenharmony_ci stdout.includes('foobar'), 471cb0ef41Sopenharmony_ci `Expected stdout to contain "foobar", got ${stdout}` 481cb0ef41Sopenharmony_ci ); 491cb0ef41Sopenharmony_ci}); 50