@@ -33,8 +33,10 @@ const {
3333 Boolean,
3434 Error,
3535 ErrorCaptureStackTrace,
36+ Function,
3637 FunctionPrototypeBind,
3738 FunctionPrototypeCall,
39+ FunctionPrototypeToString,
3840 MathMin,
3941 NumberIsNaN,
4042 ObjectCreate,
@@ -49,6 +51,7 @@ const {
4951 ReflectOwnKeys,
5052 String,
5153 StringPrototypeSplit,
54+ StringPrototypeReplace,
5255 Symbol,
5356 SymbolFor,
5457 SymbolAsyncIterator
@@ -90,9 +93,6 @@ const lazyDOMException = hideStackFrames((message, name) => {
9093} ) ;
9194
9295
93- function EventEmitter ( opts ) {
94- FunctionPrototypeCall ( EventEmitter . init , this , opts ) ;
95- }
9696module . exports = EventEmitter ;
9797module . exports . once = once ;
9898module . exports . on = on ;
@@ -199,7 +199,9 @@ EventEmitter.setMaxListeners =
199199 }
200200 } ;
201201
202- EventEmitter . init = function ( opts ) {
202+ let customInit ;
203+ function EventEmitter ( opts ) {
204+ if ( customInit ) return FunctionPrototypeCall ( customInit , this , opts ) ;
203205
204206 if ( this . _events === undefined ||
205207 this . _events === ObjectGetPrototypeOf ( this ) . _events ) {
@@ -221,7 +223,16 @@ EventEmitter.init = function(opts) {
221223 // prototype lookup in a very sensitive hot path.
222224 this [ kCapture ] = EventEmitter . prototype [ kCapture ] ;
223225 }
224- } ;
226+ }
227+ ObjectDefineProperty ( EventEmitter , 'init' , {
228+ enumerable : true ,
229+ get : ( ) =>
230+ new Function ( StringPrototypeReplace ( FunctionPrototypeToString ( EventEmitter ) ,
231+ / ^ \s * i f \s * \( c u s t o m I n i t \) / , '' ) ) ,
232+ set : ( init ) => {
233+ customInit = init ;
234+ }
235+ } ) ;
225236
226237function addCatch ( that , promise , type , args ) {
227238 if ( ! that [ kCapture ] ) {
0 commit comments