debug-host.ts 945 B

12345678910111213141516171819202122232425262728
  1. /** Child-process fixture whose Host main thread is paused and resumed through the Inspector Worker. */
  2. import { createInterface } from 'node:readline'
  3. import { startInspector } from '../../src/host/bridge/controller.ts'
  4. const inspector = await startInspector({ port: 0, captureFetch: false })
  5. function breakpointProbe(value: number): number {
  6. const local = value
  7. return local + 1
  8. }
  9. Object.defineProperty(globalThis, '__inspectorBreakpointProbe', { value: breakpointProbe, configurable: true })
  10. process.stdout.write(`${JSON.stringify(inspector.endpoint)}\n`)
  11. const input = createInterface({ input: process.stdin, terminal: false })
  12. input.on('line', (line) => {
  13. if (line === 'run') {
  14. Object.defineProperty(globalThis, '__inspectorBreakpointResult', {
  15. value: breakpointProbe(41),
  16. configurable: true,
  17. })
  18. }
  19. if (line === 'stop') {
  20. input.close()
  21. void inspector.close().then(() => { process.exit(0) })
  22. }
  23. })