-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_hooks,inspector: implement inspector api without async_wrap
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: #51501 Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Stephen Belanger <[email protected]>
- Loading branch information
Showing
6 changed files
with
64 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const { AsyncLocalStorage } = require('async_hooks'); | ||
const als = new AsyncLocalStorage(); | ||
|
||
function getStore() { | ||
return als.getStore(); | ||
} | ||
|
||
common.skipIfInspectorDisabled(); | ||
|
||
const assert = require('assert'); | ||
const { Session } = require('inspector'); | ||
const path = require('path'); | ||
const { pathToFileURL } = require('url'); | ||
|
||
let valueInFunction = 0; | ||
let valueInBreakpoint = 0; | ||
|
||
function debugged() { | ||
valueInFunction = getStore(); | ||
return 42; | ||
} | ||
|
||
async function test() { | ||
const session = new Session(); | ||
|
||
session.connect(); | ||
session.post('Debugger.enable'); | ||
|
||
session.on('Debugger.paused', () => { | ||
valueInBreakpoint = getStore(); | ||
}); | ||
|
||
await new Promise((resolve, reject) => { | ||
session.post('Debugger.setBreakpointByUrl', { | ||
'lineNumber': 22, | ||
'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(), | ||
'columnNumber': 0, | ||
'condition': '' | ||
}, (error, result) => { | ||
return error ? reject(error) : resolve(result); | ||
}); | ||
}); | ||
|
||
als.run(1, debugged); | ||
assert.strictEqual(valueInFunction, valueInBreakpoint); | ||
assert.strictEqual(valueInFunction, 1); | ||
|
||
session.disconnect(); | ||
} | ||
|
||
const interval = setInterval(() => {}, 1000); | ||
test().then(common.mustCall(() => { | ||
clearInterval(interval); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters