1// Check that abrupt termination when async call stack recording is enabled
2// does not segfault the process.
3'use strict';
4const common = require('../common');
5common.skipIfInspectorDisabled();
6common.skipIf32Bits();
7
8const { strictEqual } = require('assert');
9const eyecatcher = 'nou, houdoe he?';
10
11if (process.argv[2] === 'child') {
12  const { Session } = require('inspector');
13  const { promisify } = require('util');
14  const { internalBinding } = require('internal/test/binding');
15  const { registerAsyncHook } = internalBinding('inspector');
16  (async () => {
17    let enabled = 0;
18    registerAsyncHook(() => ++enabled, () => {});
19    const session = new Session();
20    session.connect();
21    session.post = promisify(session.post);
22    await session.post('Debugger.enable');
23    strictEqual(enabled, 0);
24    await session.post('Debugger.setAsyncCallStackDepth', { maxDepth: 42 });
25    strictEqual(enabled, 1);
26    throw new Error(eyecatcher);
27  })().finally(common.mustCall());
28} else {
29  const { spawnSync } = require('child_process');
30  const options = { encoding: 'utf8' };
31  const proc = spawnSync(
32    process.execPath, ['--expose-internals', __filename, 'child'], options);
33  strictEqual(proc.status, 1);
34  strictEqual(proc.signal, null);
35  strictEqual(proc.stderr.includes(eyecatcher), true);
36}
37