| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f11aa69 commit 1ac93cc
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -945,6 +945,11 @@ function createRepl(inspector) { | |||
| 945 | 945 | ); | |
| 946 | 946 | }); | |
| 947 | 947 | ||
| 948 | + async function runAndInit() { | ||
| 949 | + await inspector.run(); | ||
| 950 | + await initAfterStart(); | ||
| 951 | + } | ||
| 952 | + | ||
| 948 | 953 | function initializeContext(context) { | |
| 949 | 954 | ArrayPrototypeForEach(inspector.domainNames, (domain) => { | |
| 950 | 955 | ObjectDefineProperty(context, domain, { | |
@@ -962,15 +967,15 @@ function createRepl(inspector) { | |||
| 962 | 967 | }, | |
| 963 | 968 | ||
| 964 | 969 | get run() { | |
| 965 | - return inspector.run(); | ||
| 970 | + return runAndInit(); | ||
| 966 | 971 | }, | |
| 967 | 972 | ||
| 968 | 973 | get kill() { | |
| 969 | 974 | return inspector.killChild(); | |
| 970 | 975 | }, | |
| 971 | 976 | ||
| 972 | 977 | get restart() { | |
| 973 | - return inspector.run(); | ||
| 978 | + return runAndInit(); | ||
| 974 | 979 | }, | |
| 975 | 980 | ||
| 976 | 981 | get cont() { | |
@@ -1196,9 +1201,6 @@ function createRepl(inspector) { | |||
| 1196 | 1201 | inspector.client.on('close', () => { | |
| 1197 | 1202 | resetOnStart(); | |
| 1198 | 1203 | }); | |
| 1199 | - inspector.client.on('ready', () => { | ||
| 1200 | - initAfterStart(); | ||
| 1201 | - }); | ||
| 1202 | 1204 | ||
| 1203 | 1205 | // Init once for the initial connection | |
| 1204 | 1206 | await initAfterStart(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,119 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + | ||
| 6 | + common.skipIfInspectorDisabled(); | ||
| 7 | + | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + const { EventEmitter } = require('events'); | ||
| 10 | + const { PassThrough } = require('stream'); | ||
| 11 | + const createRepl = require('internal/debugger/inspect_repl'); | ||
| 12 | + | ||
| 13 | + function createGate() { | ||
| 14 | + let resolve; | ||
| 15 | + const promise = new Promise((res) => { | ||
| 16 | + resolve = res; | ||
| 17 | + }); | ||
| 18 | + return { promise, resolve }; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + function createAgent(domain, calls, gates) { | ||
| 22 | + const agent = new EventEmitter(); | ||
| 23 | + const method = (name) => async () => { | ||
| 24 | + calls.push(`${domain}.${name}`); | ||
| 25 | + if (domain === 'Runtime' && name === 'runIfWaitingForDebugger') { | ||
| 26 | + const gate = gates.shift(); | ||
| 27 | + if (gate) { | ||
| 28 | + await gate.promise; | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + }; | ||
| 32 | + | ||
| 33 | + agent.enable = method('enable'); | ||
| 34 | + agent.setSamplingInterval = method('setSamplingInterval'); | ||
| 35 | + agent.setAsyncCallStackDepth = method('setAsyncCallStackDepth'); | ||
| 36 | + agent.setBlackboxPatterns = method('setBlackboxPatterns'); | ||
| 37 | + agent.setPauseOnExceptions = method('setPauseOnExceptions'); | ||
| 38 | + agent.runIfWaitingForDebugger = method('runIfWaitingForDebugger'); | ||
| 39 | + return agent; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + function evalCommand(repl, command) { | ||
| 43 | + return new Promise((resolve, reject) => { | ||
| 44 | + repl.eval( | ||
| 45 | + command, | ||
| 46 | + repl.context, | ||
| 47 | + 'debugger-repl-test', | ||
| 48 | + (error, result) => { | ||
| 49 | + if (error) { | ||
| 50 | + reject(error); | ||
| 51 | + } else { | ||
| 52 | + resolve(result); | ||
| 53 | + } | ||
| 54 | + }, | ||
| 55 | + ); | ||
| 56 | + }); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + async function assertCommandWaitsForInit(repl, command, gate, calls) { | ||
| 60 | + let settled = false; | ||
| 61 | + const promise = evalCommand(repl, command).then(() => { | ||
| 62 | + settled = true; | ||
| 63 | + }); | ||
| 64 | + | ||
| 65 | + await new Promise(setImmediate); | ||
| 66 | + assert.strictEqual( | ||
| 67 | + settled, | ||
| 68 | + false, | ||
| 69 | + `${command} resolved before post-connect initialization completed: ${calls}`, | ||
| 70 | + ); | ||
| 71 | + | ||
| 72 | + gate.resolve(); | ||
| 73 | + await promise; | ||
| 74 | + assert.strictEqual(settled, true); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + (async () => { | ||
| 78 | + const calls = []; | ||
| 79 | + const runGate = createGate(); | ||
| 80 | + const restartGate = createGate(); | ||
| 81 | + const gates = [null, runGate, restartGate]; | ||
| 82 | + const inspector = { | ||
| 83 | + client: new EventEmitter(), | ||
| 84 | + domainNames: ['Debugger', 'HeapProfiler', 'Profiler', 'Runtime'], | ||
| 85 | + stdin: new PassThrough(), | ||
| 86 | + stdout: new PassThrough(), | ||
| 87 | + run: common.mustCall(async () => { | ||
| 88 | + calls.push('inspector.run'); | ||
| 89 | + }, 2), | ||
| 90 | + suspendReplWhile(fn) { | ||
| 91 | + return fn(); | ||
| 92 | + }, | ||
| 93 | + }; | ||
| 94 | + | ||
| 95 | + for (const domain of inspector.domainNames) { | ||
| 96 | + inspector[domain] = createAgent(domain, calls, gates); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + const repl = await createRepl(inspector)(); | ||
| 100 | + | ||
| 101 | + await assertCommandWaitsForInit(repl, 'run', runGate, calls); | ||
| 102 | + await assertCommandWaitsForInit(repl, 'restart', restartGate, calls); | ||
| 103 | + | ||
| 104 | + assert.deepStrictEqual( | ||
| 105 | + calls.filter((call) => ( | ||
| 106 | + call === 'inspector.run' || | ||
| 107 | + call === 'Runtime.runIfWaitingForDebugger' | ||
| 108 | + )), | ||
| 109 | + [ | ||
| 110 | + 'Runtime.runIfWaitingForDebugger', | ||
| 111 | + 'inspector.run', | ||
| 112 | + 'Runtime.runIfWaitingForDebugger', | ||
| 113 | + 'inspector.run', | ||
| 114 | + 'Runtime.runIfWaitingForDebugger', | ||
| 115 | + ], | ||
| 116 | + ); | ||
| 117 | + | ||
| 118 | + repl.close(); | ||
| 119 | + })().then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments