Skip to content

Commit 5f8d924

Browse files
committed
events: set EventEmitterAsyncResource fields private
1 parent 1d2603b commit 5f8d924

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

lib/events.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ function lazyEventEmitterAsyncResource() {
106106
AsyncResource,
107107
} = require('async_hooks');
108108

109-
const kEventEmitter = Symbol('kEventEmitter');
110-
const kAsyncResource = Symbol('kAsyncResource');
111109
class EventEmitterReferencingAsyncResource extends AsyncResource {
112110
/**
113111
* @param {EventEmitter} ee
@@ -119,16 +117,14 @@ function lazyEventEmitterAsyncResource() {
119117
*/
120118
constructor(ee, type, options) {
121119
super(type, options);
122-
this[kEventEmitter] = ee;
120+
this.#eventEmitter = ee;
123121
}
124122

125123
/**
126124
* @type {EventEmitter}
127125
*/
128126
get eventEmitter() {
129-
if (this[kEventEmitter] === undefined)
130-
throw new ERR_INVALID_THIS('EventEmitterReferencingAsyncResource');
131-
return this[kEventEmitter];
127+
return this.#eventEmitter;
132128
}
133129
}
134130

@@ -154,8 +150,7 @@ function lazyEventEmitterAsyncResource() {
154150
}
155151
super(options);
156152

157-
this[kAsyncResource] =
158-
new EventEmitterReferencingAsyncResource(this, name, options);
153+
this.#asyncResource = new EventEmitterReferencingAsyncResource(this, name, options);
159154
}
160155

161156
/**
@@ -164,9 +159,7 @@ function lazyEventEmitterAsyncResource() {
164159
* @returns {boolean}
165160
*/
166161
emit(event, ...args) {
167-
if (this[kAsyncResource] === undefined)
168-
throw new ERR_INVALID_THIS('EventEmitterAsyncResource');
169-
const { asyncResource } = this;
162+
const asyncResource = this.#asyncResource;
170163
ArrayPrototypeUnshift(args, super.emit, this, event);
171164
return ReflectApply(asyncResource.runInAsyncScope, asyncResource,
172165
args);
@@ -176,36 +169,28 @@ function lazyEventEmitterAsyncResource() {
176169
* @returns {void}
177170
*/
178171
emitDestroy() {
179-
if (this[kAsyncResource] === undefined)
180-
throw new ERR_INVALID_THIS('EventEmitterAsyncResource');
181-
this.asyncResource.emitDestroy();
172+
this.#asyncResource.emitDestroy();
182173
}
183174

184175
/**
185176
* @type {number}
186177
*/
187178
get asyncId() {
188-
if (this[kAsyncResource] === undefined)
189-
throw new ERR_INVALID_THIS('EventEmitterAsyncResource');
190-
return this.asyncResource.asyncId();
179+
return this.#asyncResource.asyncId();
191180
}
192181

193182
/**
194183
* @type {number}
195184
*/
196185
get triggerAsyncId() {
197-
if (this[kAsyncResource] === undefined)
198-
throw new ERR_INVALID_THIS('EventEmitterAsyncResource');
199-
return this.asyncResource.triggerAsyncId();
186+
return this.#asyncResource.triggerAsyncId();
200187
}
201188

202189
/**
203190
* @type {EventEmitterReferencingAsyncResource}
204191
*/
205192
get asyncResource() {
206-
if (this[kAsyncResource] === undefined)
207-
throw new ERR_INVALID_THIS('EventEmitterAsyncResource');
208-
return this[kAsyncResource];
193+
return this.#asyncResource;
209194
}
210195
};
211196
}

0 commit comments

Comments
 (0)