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