@@ -106,8 +106,6 @@ function lazyEventEmitterAsyncResource() {
106
106
AsyncResource,
107
107
} = require ( 'async_hooks' ) ;
108
108
109
- const kEventEmitter = Symbol ( 'kEventEmitter' ) ;
110
- const kAsyncResource = Symbol ( 'kAsyncResource' ) ;
111
109
class EventEmitterReferencingAsyncResource extends AsyncResource {
112
110
/**
113
111
* @param {EventEmitter } ee
@@ -119,16 +117,14 @@ function lazyEventEmitterAsyncResource() {
119
117
*/
120
118
constructor ( ee , type , options ) {
121
119
super ( type , options ) ;
122
- this [ kEventEmitter ] = ee ;
120
+ this . #eventEmitter = ee ;
123
121
}
124
122
125
123
/**
126
124
* @type {EventEmitter }
127
125
*/
128
126
get eventEmitter ( ) {
129
- if ( this [ kEventEmitter ] === undefined )
130
- throw new ERR_INVALID_THIS ( 'EventEmitterReferencingAsyncResource' ) ;
131
- return this [ kEventEmitter ] ;
127
+ return this . #eventEmitter;
132
128
}
133
129
}
134
130
@@ -154,8 +150,7 @@ function lazyEventEmitterAsyncResource() {
154
150
}
155
151
super ( options ) ;
156
152
157
- this [ kAsyncResource ] =
158
- new EventEmitterReferencingAsyncResource ( this , name , options ) ;
153
+ this . #asyncResource = new EventEmitterReferencingAsyncResource ( this , name , options ) ;
159
154
}
160
155
161
156
/**
@@ -164,9 +159,7 @@ function lazyEventEmitterAsyncResource() {
164
159
* @returns {boolean }
165
160
*/
166
161
emit ( event , ...args ) {
167
- if ( this [ kAsyncResource ] === undefined )
168
- throw new ERR_INVALID_THIS ( 'EventEmitterAsyncResource' ) ;
169
- const { asyncResource } = this ;
162
+ const asyncResource = this . #asyncResource;
170
163
ArrayPrototypeUnshift ( args , super . emit , this , event ) ;
171
164
return ReflectApply ( asyncResource . runInAsyncScope , asyncResource ,
172
165
args ) ;
@@ -176,36 +169,28 @@ function lazyEventEmitterAsyncResource() {
176
169
* @returns {void }
177
170
*/
178
171
emitDestroy ( ) {
179
- if ( this [ kAsyncResource ] === undefined )
180
- throw new ERR_INVALID_THIS ( 'EventEmitterAsyncResource' ) ;
181
- this . asyncResource . emitDestroy ( ) ;
172
+ this . #asyncResource. emitDestroy ( ) ;
182
173
}
183
174
184
175
/**
185
176
* @type {number }
186
177
*/
187
178
get asyncId ( ) {
188
- if ( this [ kAsyncResource ] === undefined )
189
- throw new ERR_INVALID_THIS ( 'EventEmitterAsyncResource' ) ;
190
- return this . asyncResource . asyncId ( ) ;
179
+ return this . #asyncResource. asyncId ( ) ;
191
180
}
192
181
193
182
/**
194
183
* @type {number }
195
184
*/
196
185
get triggerAsyncId ( ) {
197
- if ( this [ kAsyncResource ] === undefined )
198
- throw new ERR_INVALID_THIS ( 'EventEmitterAsyncResource' ) ;
199
- return this . asyncResource . triggerAsyncId ( ) ;
186
+ return this . #asyncResource. triggerAsyncId ( ) ;
200
187
}
201
188
202
189
/**
203
190
* @type {EventEmitterReferencingAsyncResource }
204
191
*/
205
192
get asyncResource ( ) {
206
- if ( this [ kAsyncResource ] === undefined )
207
- throw new ERR_INVALID_THIS ( 'EventEmitterAsyncResource' ) ;
208
- return this [ kAsyncResource ] ;
193
+ return this . #asyncResource;
209
194
}
210
195
} ;
211
196
}
0 commit comments