• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const spawn = require('child_process').spawn;
6const vm = require('vm');
7const node = process.execPath;
8
9if (process.argv[2] === 'child') {
10  throw new Error('child error');
11} else if (process.argv[2] === 'vm') {
12  // Refs: https://github.com/nodejs/node/issues/13258
13  // This *should* still crash.
14  new vm.Script('[', {});
15} else {
16  run('', 'child', null);
17  run('--abort-on-uncaught-exception', 'child',
18      ['SIGABRT', 'SIGTRAP', 'SIGILL']);
19  run('--abort-on-uncaught-exception', 'vm', ['SIGABRT', 'SIGTRAP', 'SIGILL']);
20}
21
22function run(flags, argv2, signals) {
23  const args = [__filename, argv2];
24  if (flags)
25    args.unshift(flags);
26
27  const child = spawn(node, args);
28  child.on('exit', common.mustCall(function(code, sig) {
29    if (common.isWindows) {
30      if (signals)
31        assert.strictEqual(code, 0x80000003);
32      else
33        assert.strictEqual(code, 1);
34    } else if (signals) {
35      assert(signals.includes(sig), `Unexpected signal ${sig}`);
36    } else {
37      assert.strictEqual(sig, null);
38    }
39  }));
40}
41