(options, stdin, stdout)
| 70 | |
| 71 | class NodeInspector { |
| 72 | constructor(options, stdin, stdout) { |
| 73 | this.options = options; |
| 74 | this.stdin = stdin; |
| 75 | this.stdout = stdout; |
| 76 | |
| 77 | this.paused = true; |
| 78 | this.child = null; |
| 79 | |
| 80 | if (options.script) { |
| 81 | this._runScript = FunctionPrototypeBind( |
| 82 | launchChildProcess, null, |
| 83 | [options.script, ...options.scriptArgs], |
| 84 | options.host, |
| 85 | options.port, |
| 86 | FunctionPrototypeBind(this.childPrint, this)); |
| 87 | } else { |
| 88 | this._runScript = |
| 89 | () => PromiseResolve([null, options.port, options.host]); |
| 90 | } |
| 91 | |
| 92 | this.client = new InspectClient(); |
| 93 | |
| 94 | this.domainNames = ['Debugger', 'HeapProfiler', 'Profiler', 'Runtime']; |
| 95 | ArrayPrototypeForEach(this.domainNames, (domain) => { |
| 96 | this[domain] = createAgentProxy(domain, this.client); |
| 97 | }); |
| 98 | this.handleDebugEvent = (fullName, params) => { |
| 99 | const { 0: domain, 1: name } = StringPrototypeSplit(fullName, '.', 2); |
| 100 | if (domain in this) { |
| 101 | this[domain].emit(name, params); |
| 102 | } |
| 103 | }; |
| 104 | this.client.on('debugEvent', this.handleDebugEvent); |
| 105 | const startRepl = createRepl(this); |
| 106 | |
| 107 | // Handle all possible exits |
| 108 | process.on('exit', () => this.killChild()); |
| 109 | const exitCodeZero = () => process.exit(kNoFailure); |
| 110 | process.once('SIGTERM', exitCodeZero); |
| 111 | process.once('SIGHUP', exitCodeZero); |
| 112 | |
| 113 | (async () => { |
| 114 | try { |
| 115 | await this.run(); |
| 116 | const repl = await startRepl(); |
| 117 | this.repl = repl; |
| 118 | this.repl.on('exit', exitCodeZero); |
| 119 | this.paused = false; |
| 120 | } catch (error) { |
| 121 | process.nextTick(() => { throw error; }); |
| 122 | } |
| 123 | })(); |
| 124 | } |
| 125 | |
| 126 | suspendReplWhile(fn) { |
| 127 | if (this.repl) { |
nothing calls this directly
no test coverage detected