Skip to content

Commit c3eee59

Browse files
anonrigRafaelGSS
authored andcommitted
inspector: use private fields instead of symbols
PR-URL: #50776 Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]>
1 parent eacf4ba commit c3eee59

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

‎lib/inspector.js‎

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const{
44
JSONParse,
55
JSONStringify,
66
SafeMap,
7-
Symbol,
87
SymbolDispose,
98
}=primordials;
109

@@ -45,28 +44,19 @@ const{
4544
console,
4645
}=internalBinding('inspector');
4746

48-
constconnectionSymbol=Symbol('connectionProperty');
49-
constmessageCallbacksSymbol=Symbol('messageCallbacks');
50-
constnextIdSymbol=Symbol('nextId');
51-
constonMessageSymbol=Symbol('onMessage');
52-
5347
classSessionextendsEventEmitter{
54-
constructor(){
55-
super();
56-
this[connectionSymbol]=null;
57-
this[nextIdSymbol]=1;
58-
this[messageCallbacksSymbol]=newSafeMap();
59-
}
48+
#connection =null;
49+
#nextId =1;
50+
#messageCallbacks =newSafeMap();
6051

6152
/**
6253
* Connects the session to the inspector back-end.
6354
* @returns{void}
6455
*/
6556
connect(){
66-
if(this[connectionSymbol])
57+
if(this.#connection)
6758
thrownewERR_INSPECTOR_ALREADY_CONNECTED('The inspector session');
68-
this[connectionSymbol]=
69-
newConnection((message)=>this[onMessageSymbol](message));
59+
this.#connection =newConnection((message)=>this.#onMessage(message));
7060
}
7161

7262
/**
@@ -77,23 +67,24 @@ class Session extends EventEmitter{
7767
connectToMainThread(){
7868
if(isMainThread)
7969
thrownewERR_INSPECTOR_NOT_WORKER();
80-
if(this[connectionSymbol])
70+
if(this.#connection)
8171
thrownewERR_INSPECTOR_ALREADY_CONNECTED('The inspector session');
82-
this[connectionSymbol]=
72+
this.#connection=
8373
newMainThreadConnection(
84-
(message)=>queueMicrotask(()=>this[onMessageSymbol](message)));
74+
(message)=>queueMicrotask(()=>this.#onMessage(message)));
8575
}
8676

87-
[onMessageSymbol](message){
77+
#onMessage(message){
8878
constparsed=JSONParse(message);
8979
try{
9080
if(parsed.id){
91-
constcallback=this[messageCallbacksSymbol].get(parsed.id);
92-
this[messageCallbacksSymbol].delete(parsed.id);
81+
constcallback=this.#messageCallbacks.get(parsed.id);
82+
this.#messageCallbacks.delete(parsed.id);
9383
if(callback){
9484
if(parsed.error){
95-
returncallback(newERR_INSPECTOR_COMMAND(parsed.error.code,
96-
parsed.error.message));
85+
returncallback(
86+
newERR_INSPECTOR_COMMAND(parsed.error.code,parsed.error.message),
87+
);
9788
}
9889

9990
callback(null,parsed.result);
@@ -127,18 +118,18 @@ class Session extends EventEmitter{
127118
validateFunction(callback,'callback');
128119
}
129120

130-
if(!this[connectionSymbol]){
121+
if(!this.#connection){
131122
thrownewERR_INSPECTOR_NOT_CONNECTED();
132123
}
133-
constid=this[nextIdSymbol]++;
124+
constid=this.#nextId++;
134125
constmessage={ id, method };
135126
if(params){
136127
message.params=params;
137128
}
138129
if(callback){
139-
this[messageCallbacksSymbol].set(id,callback);
130+
this.#messageCallbacks.set(id,callback);
140131
}
141-
this[connectionSymbol].dispatch(JSONStringify(message));
132+
this.#connection.dispatch(JSONStringify(message));
142133
}
143134

144135
/**
@@ -148,16 +139,16 @@ class Session extends EventEmitter{
148139
* @returns{void}
149140
*/
150141
disconnect(){
151-
if(!this[connectionSymbol])
142+
if(!this.#connection)
152143
return;
153-
this[connectionSymbol].disconnect();
154-
this[connectionSymbol]=null;
155-
constremainingCallbacks=this[messageCallbacksSymbol].values();
144+
this.#connection.disconnect();
145+
this.#connection=null;
146+
constremainingCallbacks=this.#messageCallbacks.values();
156147
for(constcallbackofremainingCallbacks){
157148
process.nextTick(callback,newERR_INSPECTOR_CLOSED());
158149
}
159-
this[messageCallbacksSymbol].clear();
160-
this[nextIdSymbol]=1;
150+
this.#messageCallbacks.clear();
151+
this.#nextId=1;
161152
}
162153
}
163154

0 commit comments

Comments
(0)