Skip to content

Commit 0e446d6

Browse files
aduh95targos
authored andcommitted
debugger: enable linter on internal/inspector/inspect_client
PR-URL: #38417 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 9f0e80a commit 0e446d6

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

‎lib/internal/inspector/inspect_client.js‎

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,28 @@
2020
* IN THE SOFTWARE.
2121
*/
2222

23-
// TODO(trott): enable ESLint
24-
/* eslint-disable */
23+
// TODO(aduh95): use errors exported by the internal/errors module
24+
/* eslint-disable no-restricted-syntax */
2525

2626
'use strict';
27+
28+
const{
29+
ArrayPrototypePush,
30+
Error,
31+
ErrorCaptureStackTrace,
32+
FunctionPrototypeBind,
33+
JSONParse,
34+
JSONStringify,
35+
ObjectKeys,
36+
Promise,
37+
}=primordials;
38+
2739
constBuffer=require('buffer').Buffer;
2840
const{ EventEmitter }=require('events');
2941
consthttp=require('http');
3042
constURL=require('url');
31-
constutil=require('util');
3243

33-
constdebuglog=util.debuglog('inspect');
44+
constdebuglog=require('internal/util/debuglog').debuglog('inspect');
3445

3546
constkOpCodeText=0x1;
3647
constkOpCodeClose=0x8;
@@ -49,14 +60,10 @@ const kTwoBytePayloadLengthField = 126;
4960
constkEightBytePayloadLengthField=127;
5061
constkMaskingKeyWidthInBytes=4;
5162

52-
functionisEmpty(obj){
53-
returnObject.keys(obj).length===0;
54-
}
55-
5663
functionunpackError({ code, message, data }){
5764
consterr=newError(`${message} - ${data}`);
5865
err.code=code;
59-
Error.captureStackTrace(err,unpackError);
66+
ErrorCaptureStackTrace(err,unpackError);
6067
returnerr;
6168
}
6269

@@ -169,7 +176,7 @@ function decodeFrameHybi17(data){
169176
classClientextendsEventEmitter{
170177
constructor(){
171178
super();
172-
this.handleChunk=this._handleChunk.bind(this);
179+
this.handleChunk=FunctionPrototypeBind(this._handleChunk,this);
173180

174181
this._port=undefined;
175182
this._host=undefined;
@@ -202,7 +209,7 @@ class Client extends EventEmitter{
202209
}
203210
letpayload;
204211
try{
205-
payload=JSON.parse(payloadStr);
212+
payload=JSONParse(payloadStr);
206213
}catch(parseError){
207214
parseError.string=payloadStr;
208215
throwparseError;
@@ -247,9 +254,9 @@ class Client extends EventEmitter{
247254
constdata={id: ++this._lastId, method, params };
248255
this._pending[data.id]=(error,result)=>{
249256
if(error)reject(unpackError(error));
250-
elseresolve(isEmpty(result) ? undefined : result);
257+
elseresolve(ObjectKeys(result).length ? result : undefined);
251258
};
252-
constjson=JSON.stringify(data);
259+
constjson=JSONStringify(data);
253260
debuglog('> %s',json);
254261
this._socket.write(encodeFrameHybi17(Buffer.from(json)));
255262
});
@@ -273,15 +280,15 @@ class Client extends EventEmitter{
273280
return;
274281
}
275282
try{
276-
resolve(JSON.parse(resBody));
277-
}catch(parseError){
283+
resolve(JSONParse(resBody));
284+
}catch{
278285
reject(newError(`Response didn't contain JSON: ${resBody}`));
279286

280287
}
281288
}
282289

283290
httpRes.on('error',reject);
284-
httpRes.on('data',(chunk)=>chunks.push(chunk));
291+
httpRes.on('data',(chunk)=>ArrayPrototypePush(chunks,chunk));
285292
httpRes.on('end',parseChunks);
286293
}
287294

@@ -290,17 +297,16 @@ class Client extends EventEmitter{
290297
});
291298
}
292299

293-
connect(port,host){
300+
asyncconnect(port,host){
294301
this._port=port;
295302
this._host=host;
296-
returnthis._discoverWebsocketPath()
297-
.then((urlPath)=>this._connectWebsocket(urlPath));
303+
consturlPath=awaitthis._discoverWebsocketPath();
304+
returnthis._connectWebsocket(urlPath);
298305
}
299306

300-
_discoverWebsocketPath(){
301-
returnthis._fetchJSON('/json')
302-
.then(({0: { webSocketDebuggerUrl }})=>
303-
URL.parse(webSocketDebuggerUrl).path);
307+
async_discoverWebsocketPath(){
308+
const{0: { webSocketDebuggerUrl }}=awaitthis._fetchJSON('/json');
309+
returnURL.parse(webSocketDebuggerUrl).path;
304310
}
305311

306312
_connectWebsocket(urlPath){

0 commit comments

Comments
(0)