mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
a3abc42587
Implementing the inspector session object as an async resource causes unwanted context change when a breakpoint callback function is being called. Modelling the inspector api without the AsyncWrap base class ensures that the callback has access to the AsyncLocalStorage instance that is active in the affected user function. See `test-inspector-async-context-brk.js` for an illustration of the use case. PR-URL: https://github.com/nodejs/node/pull/51501 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
common.skipIfInspectorDisabled();
|
|
|
|
const assert = require('assert');
|
|
const { Session } = require('inspector');
|
|
const path = require('path');
|
|
const { pathToFileURL } = require('url');
|
|
|
|
function debugged() {
|
|
return 42;
|
|
}
|
|
|
|
async function test() {
|
|
const session1 = new Session();
|
|
const session2 = new Session();
|
|
|
|
session1.connect();
|
|
session2.connect();
|
|
|
|
let session1Paused = false;
|
|
let session2Paused = false;
|
|
|
|
session1.on('Debugger.paused', () => session1Paused = true);
|
|
session2.on('Debugger.paused', () => session2Paused = true);
|
|
|
|
console.log('Connected');
|
|
|
|
session1.post('Debugger.enable');
|
|
session2.post('Debugger.enable');
|
|
console.log('Debugger was enabled');
|
|
|
|
await new Promise((resolve, reject) => {
|
|
session1.post('Debugger.setBreakpointByUrl', {
|
|
'lineNumber': 12,
|
|
'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
|
|
'columnNumber': 0,
|
|
'condition': ''
|
|
}, (error, result) => {
|
|
return error ? reject(error) : resolve(result);
|
|
});
|
|
});
|
|
console.log('Breakpoint was set');
|
|
|
|
debugged();
|
|
|
|
// Both sessions will receive the paused event
|
|
assert(session1Paused);
|
|
assert(session2Paused);
|
|
console.log('Breakpoint was hit');
|
|
|
|
session1.disconnect();
|
|
session2.disconnect();
|
|
console.log('Sessions were disconnected');
|
|
}
|
|
|
|
const interval = setInterval(() => {}, 1000);
|
|
test().then(common.mustCall(() => {
|
|
clearInterval(interval);
|
|
console.log('Done!');
|
|
}));
|