MCPcopy Index your code
hub / github.com/nodejs/node / childMain

Function childMain

test/parallel/test-inspector-connect-main-thread.js:129–170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127}
128
129async function childMain() {
130 // Ensures the worker does not terminate too soon
131 parentPort.on('message', () => { });
132 await (await startWorker(true)).onMessagesSent;
133 const session = new Session();
134 session.connectToMainThread();
135 assert.throws(
136 () => {
137 session.connectToMainThread();
138 },
139 {
140 code: 'ERR_INSPECTOR_ALREADY_CONNECTED',
141 name: 'Error',
142 message: 'The inspector session is already connected'
143 }
144 );
145 await post(session, 'Debugger.enable');
146 await post(session, 'Runtime.enable');
147 await post(session, 'Debugger.setBreakpointByUrl', {
148 'lineNumber': 18,
149 'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
150 'columnNumber': 0,
151 'condition': ''
152 });
153 const pausedPromise = waitForNotification(session, 'Debugger.paused');
154 parentPort.postMessage('Ready');
155 const callFrameId = (await pausedPromise).params.callFrames[0].callFrameId;
156
157 // Delay to ensure main thread is truly suspended
158 await new Promise((resolve) => setTimeout(resolve, 50));
159
160 const { result: { value } } =
161 await post(session,
162 'Debugger.evaluateOnCallFrame',
163 { callFrameId, expression: 'a * 100' });
164 assert.strictEqual(value, 100);
165 await post(session, 'Debugger.resume');
166 await ensureListenerDoesNotInterrupt(session);
167 parentPort.postMessage({ messagesSent });
168 parentPort.close();
169 console.log('Worker is done');
170}
171
172async function skipChildMain() {
173 // Ensures the worker does not terminate too soon

Calls 13

connectToMainThreadMethod · 0.95
waitForNotificationFunction · 0.85
startWorkerFunction · 0.70
postFunction · 0.70
closeMethod · 0.65
pathToFileURLFunction · 0.50
setTimeoutFunction · 0.50
onMethod · 0.45
toStringMethod · 0.45
resolveMethod · 0.45
postMessageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…