mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
debugger: enable linter on internal/inspector/inspect_client
PR-URL: https://github.com/nodejs/node/pull/38417 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
1 parent
9f0e80aa4d
commit
0e446d6048
1 file changed
+29
-23
@@ -20,17 +20,28 @@
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// TODO(trott): enable ESLint
|
||||
/* eslint-disable */
|
||||
// TODO(aduh95): use errors exported by the internal/errors module
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
ArrayPrototypePush,
|
||||
Error,
|
||||
ErrorCaptureStackTrace,
|
||||
FunctionPrototypeBind,
|
||||
JSONParse,
|
||||
JSONStringify,
|
||||
ObjectKeys,
|
||||
Promise,
|
||||
} = primordials;
|
||||
|
||||
const Buffer = require('buffer').Buffer;
|
||||
const { EventEmitter } = require('events');
|
||||
const http = require('http');
|
||||
const URL = require('url');
|
||||
const util = require('util');
|
||||
|
||||
const debuglog = util.debuglog('inspect');
|
||||
const debuglog = require('internal/util/debuglog').debuglog('inspect');
|
||||
|
||||
const kOpCodeText = 0x1;
|
||||
const kOpCodeClose = 0x8;
|
||||
@@ -49,14 +60,10 @@ const kTwoBytePayloadLengthField = 126;
|
||||
const kEightBytePayloadLengthField = 127;
|
||||
const kMaskingKeyWidthInBytes = 4;
|
||||
|
||||
function isEmpty(obj) {
|
||||
return Object.keys(obj).length === 0;
|
||||
}
|
||||
|
||||
function unpackError({ code, message, data }) {
|
||||
const err = new Error(`${message} - ${data}`);
|
||||
err.code = code;
|
||||
Error.captureStackTrace(err, unpackError);
|
||||
ErrorCaptureStackTrace(err, unpackError);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -169,7 +176,7 @@ function decodeFrameHybi17(data) {
|
||||
class Client extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this.handleChunk = this._handleChunk.bind(this);
|
||||
this.handleChunk = FunctionPrototypeBind(this._handleChunk, this);
|
||||
|
||||
this._port = undefined;
|
||||
this._host = undefined;
|
||||
@@ -202,7 +209,7 @@ class Client extends EventEmitter {
|
||||
}
|
||||
let payload;
|
||||
try {
|
||||
payload = JSON.parse(payloadStr);
|
||||
payload = JSONParse(payloadStr);
|
||||
} catch (parseError) {
|
||||
parseError.string = payloadStr;
|
||||
throw parseError;
|
||||
@@ -247,9 +254,9 @@ class Client extends EventEmitter {
|
||||
const data = { id: ++this._lastId, method, params };
|
||||
this._pending[data.id] = (error, result) => {
|
||||
if (error) reject(unpackError(error));
|
||||
else resolve(isEmpty(result) ? undefined : result);
|
||||
else resolve(ObjectKeys(result).length ? result : undefined);
|
||||
};
|
||||
const json = JSON.stringify(data);
|
||||
const json = JSONStringify(data);
|
||||
debuglog('> %s', json);
|
||||
this._socket.write(encodeFrameHybi17(Buffer.from(json)));
|
||||
});
|
||||
@@ -273,15 +280,15 @@ class Client extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolve(JSON.parse(resBody));
|
||||
} catch (parseError) {
|
||||
resolve(JSONParse(resBody));
|
||||
} catch {
|
||||
reject(new Error(`Response didn't contain JSON: ${resBody}`));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
httpRes.on('error', reject);
|
||||
httpRes.on('data', (chunk) => chunks.push(chunk));
|
||||
httpRes.on('data', (chunk) => ArrayPrototypePush(chunks, chunk));
|
||||
httpRes.on('end', parseChunks);
|
||||
}
|
||||
|
||||
@@ -290,17 +297,16 @@ class Client extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
connect(port, host) {
|
||||
async connect(port, host) {
|
||||
this._port = port;
|
||||
this._host = host;
|
||||
return this._discoverWebsocketPath()
|
||||
.then((urlPath) => this._connectWebsocket(urlPath));
|
||||
const urlPath = await this._discoverWebsocketPath();
|
||||
return this._connectWebsocket(urlPath);
|
||||
}
|
||||
|
||||
_discoverWebsocketPath() {
|
||||
return this._fetchJSON('/json')
|
||||
.then(({ 0: { webSocketDebuggerUrl } }) =>
|
||||
URL.parse(webSocketDebuggerUrl).path);
|
||||
async _discoverWebsocketPath() {
|
||||
const { 0: { webSocketDebuggerUrl } } = await this._fetchJSON('/json');
|
||||
return URL.parse(webSocketDebuggerUrl).path;
|
||||
}
|
||||
|
||||
_connectWebsocket(urlPath) {
|
||||
|
||||
Reference in new issue
Block a user