|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | + |
| 4 | +common.skipIfInspectorDisabled(); |
| 5 | + |
| 6 | +const assert = require('assert'); |
| 7 | +const { NodeInstance } = require('../common/inspector-helper.js'); |
| 8 | + |
| 9 | +// An in-process session observes Debugger.paused while the process is paused, |
| 10 | +// so its callback runs from the Isolate::RequestInterrupt handler that |
| 11 | +// Debugger.pause schedules, where V8 asserts that JS is not executed. |
| 12 | +const script = ` |
| 13 | +const { Session } = require('inspector'); |
| 14 | +const session = new Session(); |
| 15 | +let paused = false; |
| 16 | +session.on('Debugger.paused', () => { |
| 17 | + paused = true; |
| 18 | +}); |
| 19 | +session.connect(); |
| 20 | +session.post('Debugger.enable'); |
| 21 | +console.log('Ready'); |
| 22 | +// Spin so that the pause is requested while JS is on the stack, which is what |
| 23 | +// makes V8 break from the interrupt handler instead of on the next call. |
| 24 | +const deadline = Date.now() + ${common.platformTimeout(10000)}; |
| 25 | +while (!paused && Date.now() < deadline); |
| 26 | +console.log(paused ? 'Notified' : 'Not notified'); |
| 27 | +`; |
| 28 | + |
| 29 | +async function runTest() { |
| 30 | + const child = new NodeInstance(undefined, script); |
| 31 | + const session = await child.connectInspectorSession(); |
| 32 | + await session.send({ method: 'NodeRuntime.enable' }); |
| 33 | + await session.waitForNotification('NodeRuntime.waitingForDebugger'); |
| 34 | + await session.send([ |
| 35 | + { 'method': 'Runtime.enable' }, |
| 36 | + { 'method': 'Debugger.enable' }, |
| 37 | + ]); |
| 38 | + await session.send({ method: 'Runtime.runIfWaitingForDebugger' }); |
| 39 | + await session.send({ method: 'NodeRuntime.disable' }); |
| 40 | + await session.waitForNotification('Debugger.paused', 'Break on start'); |
| 41 | + await session.send({ 'method': 'Debugger.resume' }); |
| 42 | + await session.waitForConsoleOutput('log', ['Ready']); |
| 43 | + |
| 44 | + await session.send({ 'method': 'Debugger.pause' }); |
| 45 | + await session.waitForNotification('Debugger.paused', 'Paused'); |
| 46 | + await session.send({ 'method': 'Debugger.resume' }); |
| 47 | + await session.waitForConsoleOutput('log', ['Notified']); |
| 48 | + |
| 49 | + await session.waitForDisconnect(); |
| 50 | + assert.strictEqual((await child.expectShutdown()).exitCode, 0); |
| 51 | +} |
| 52 | + |
| 53 | +runTest().then(common.mustCall()); |
0 commit comments