2018-08-21 06:54:02 +00:00
|
|
|
// Flags: --expose-internals
|
2017-10-18 23:00:03 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
common.skipIfInspectorDisabled();
|
|
|
|
common.skipIf32Bits();
|
|
|
|
|
|
|
|
const assert = require('assert');
|
2024-06-18 16:02:25 +00:00
|
|
|
const { inspect } = require('util');
|
2018-08-21 06:54:02 +00:00
|
|
|
const { internalBinding } = require('internal/test/binding');
|
2024-06-18 16:02:25 +00:00
|
|
|
const { async_hook_fields, constants, getPromiseHooks } = internalBinding('async_wrap');
|
2019-11-24 05:13:52 +00:00
|
|
|
const { kTotals } = constants;
|
2024-06-18 16:02:25 +00:00
|
|
|
const inspector = require('inspector/promises');
|
2017-10-18 23:00:03 +00:00
|
|
|
|
|
|
|
const setDepth = 'Debugger.setAsyncCallStackDepth';
|
2024-06-18 16:02:25 +00:00
|
|
|
const emptyPromiseHooks = [ undefined, undefined, undefined, undefined ];
|
2017-10-18 23:00:03 +00:00
|
|
|
function verifyAsyncHookDisabled(message) {
|
2019-11-24 05:13:52 +00:00
|
|
|
assert.strictEqual(async_hook_fields[kTotals], 0,
|
|
|
|
`${async_hook_fields[kTotals]} !== 0: ${message}`);
|
2024-06-18 16:02:25 +00:00
|
|
|
const promiseHooks = getPromiseHooks();
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
promiseHooks, emptyPromiseHooks,
|
|
|
|
`${message}: promise hooks ${inspect(promiseHooks)}`
|
|
|
|
);
|
2017-10-18 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function verifyAsyncHookEnabled(message) {
|
2019-11-24 05:13:52 +00:00
|
|
|
assert.strictEqual(async_hook_fields[kTotals], 4,
|
|
|
|
`${async_hook_fields[kTotals]} !== 4: ${message}`);
|
2024-06-18 16:02:25 +00:00
|
|
|
const promiseHooks = getPromiseHooks();
|
|
|
|
assert.notDeepStrictEqual(
|
|
|
|
promiseHooks, emptyPromiseHooks,
|
|
|
|
`${message}: promise hooks ${inspect(promiseHooks)}`
|
|
|
|
);
|
2017-10-18 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// By default inspector async hooks should not have been installed.
|
|
|
|
verifyAsyncHookDisabled('inspector async hook should be disabled at startup');
|
|
|
|
|
|
|
|
const session = new inspector.Session();
|
|
|
|
verifyAsyncHookDisabled('creating a session should not enable async hooks');
|
|
|
|
|
|
|
|
session.connect();
|
|
|
|
verifyAsyncHookDisabled('connecting a session should not enable async hooks');
|
|
|
|
|
2024-06-18 16:02:25 +00:00
|
|
|
(async () => {
|
|
|
|
await session.post('Debugger.enable');
|
2017-10-18 23:00:03 +00:00
|
|
|
verifyAsyncHookDisabled('enabling debugger should not enable async hooks');
|
2024-06-18 16:02:25 +00:00
|
|
|
await assert.rejects(session.post(setDepth, { invalid: 'message' }), { code: 'ERR_INSPECTOR_COMMAND' });
|
|
|
|
verifyAsyncHookDisabled('invalid message should not enable async hooks');
|
|
|
|
await assert.rejects(session.post(setDepth, { maxDepth: 'five' }), { code: 'ERR_INSPECTOR_COMMAND' });
|
|
|
|
verifyAsyncHookDisabled('invalid maxDepth (string) should not enable ' +
|
|
|
|
'async hooks');
|
|
|
|
await assert.rejects(session.post(setDepth, { maxDepth: NaN }), { code: 'ERR_INSPECTOR_COMMAND' });
|
|
|
|
verifyAsyncHookDisabled('invalid maxDepth (NaN) should not enable ' +
|
|
|
|
'async hooks');
|
|
|
|
await session.post(setDepth, { maxDepth: 10 });
|
|
|
|
verifyAsyncHookEnabled('valid message should enable async hooks');
|
|
|
|
|
|
|
|
await session.post(setDepth, { maxDepth: 0 });
|
|
|
|
verifyAsyncHookDisabled('Setting maxDepth to 0 should disable ' +
|
|
|
|
'async hooks');
|
|
|
|
|
|
|
|
await session.post(setDepth, { maxDepth: 32 });
|
|
|
|
verifyAsyncHookEnabled('valid message should enable async hooks');
|
|
|
|
|
|
|
|
await session.post('Debugger.disable');
|
|
|
|
verifyAsyncHookDisabled('Debugger.disable should disable async hooks');
|
|
|
|
|
|
|
|
await session.post('Debugger.enable');
|
|
|
|
verifyAsyncHookDisabled('Enabling debugger should not enable hooks');
|
|
|
|
|
|
|
|
await session.post(setDepth, { maxDepth: 64 });
|
|
|
|
verifyAsyncHookEnabled('valid message should enable async hooks');
|
|
|
|
|
|
|
|
await session.disconnect();
|
|
|
|
|
|
|
|
verifyAsyncHookDisabled('Disconnecting session should disable ' +
|
|
|
|
'async hooks');
|
|
|
|
})().then(common.mustCall());
|