| 82 | } |
| 83 | |
| 84 | #onMessage(message) { |
| 85 | const parsed = JSONParse(message); |
| 86 | try { |
| 87 | if (parsed.id) { |
| 88 | const callback = this.#messageCallbacks.get(parsed.id); |
| 89 | this.#messageCallbacks.delete(parsed.id); |
| 90 | if (callback) { |
| 91 | if (parsed.error) { |
| 92 | return callback( |
| 93 | new ERR_INSPECTOR_COMMAND(parsed.error.code, parsed.error.message), |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | callback(null, parsed.result); |
| 98 | } |
| 99 | } else { |
| 100 | this.emit(parsed.method, parsed); |
| 101 | this.emit('inspectorNotification', parsed); |
| 102 | } |
| 103 | } catch (error) { |
| 104 | process.emitWarning(error); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Posts a message to the inspector back-end. |