-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This enables inspector support for contexts created using the vm module. PR-URL: #14465 Reviewed-By: Jan Krems <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Aleksey Kozyatinskiy <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||
'use strict'; | ||||
|
||||
// Flags: --expose-gc | ||||
|
||||
const common = require('../common'); | ||||
common.skipIfInspectorDisabled(); | ||||
|
||||
const { strictEqual } = require('assert'); | ||||
const { runInNewContext } = require('vm'); | ||||
const { Session } = require('inspector'); | ||||
|
||||
const session = new Session(); | ||||
session.connect(); | ||||
|
||||
function notificationPromise(method) { | ||||
return new Promise((resolve) => session.once(method, resolve)); | ||||
} | ||||
|
||||
async function testContextCreatedAndDestroyed() { | ||||
console.log('Testing context created/destroyed notifications'); | ||||
const mainContextPromise = | ||||
notificationPromise('Runtime.executionContextCreated'); | ||||
|
||||
session.post('Runtime.enable'); | ||||
let contextCreated = await mainContextPromise; | ||||
strictEqual('Node.js Main Context', | ||||
contextCreated.params.context.name, | ||||
JSON.stringify(contextCreated)); | ||||
|
||||
const secondContextCreatedPromise = | ||||
notificationPromise('Runtime.executionContextCreated'); | ||||
|
||||
let contextDestroyed = null; | ||||
session.once('Runtime.executionContextDestroyed', | ||||
(notification) => contextDestroyed = notification); | ||||
|
||||
runInNewContext('1 + 1', {}); | ||||
|
||||
contextCreated = await secondContextCreatedPromise; | ||||
strictEqual('VM Context 1', | ||||
contextCreated.params.context.name, | ||||
JSON.stringify(contextCreated)); | ||||
|
||||
// GC is unpredictable... | ||||
while (!contextDestroyed) | ||||
global.gc(); | ||||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
eugeneo
Author
Contributor
|
callbackData->m_inspector->contextCollected(callbackData->m_groupId, |
I am not entirely sure what is considered "JS land" (e.g. Inspector at times exists between V8 loop iterations - not quite the same as "user code"). The notification is sent entirely from native code, nothing is triggered in a user code.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
bnoordhuis
Nov 20, 2017
Member
Right, what I mean is, this is a synchronous loop; contextDestroyed == null
upon entering it. It changes because of the callback on line 34 where the inspector invokes the 'Runtime.executionContextDestroyed'
event listener.
It sounds like the call chain is GC -> inspector -> JS callback, but calling into JS land when the GC is active is unsafe (or so it was in the past, at least.)
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
@eugeneo I have a hard time understanding this. Does the inspector call into JS land from the garbage collector? (I guess it has to, otherwise I don't see
contextDestroyed
can change - and change it does, that I checked.) Isn't that mightily unsafe?