@@ -171,6 +171,14 @@ Object.defineProperty(Event.prototype, SymbolToStringTag, {
171171 value : 'Event' ,
172172} ) ;
173173
174+ class NodeCustomEvent extends Event {
175+ constructor ( type , options ) {
176+ super ( type , options ) ;
177+ if ( options && options . detail ) {
178+ this . detail = options . detail ;
179+ }
180+ }
181+ }
174182// The listeners for an EventTarget are maintained as a linked list.
175183// Unfortunately, the way EventTarget is defined, listeners are accounted
176184// using the tuple [handler,capture], and even if we don't actually make
@@ -376,6 +384,9 @@ class EventTarget {
376384 event [ kTarget ] = undefined ;
377385 }
378386
387+ [ kCreateEvent ] ( nodeValue , type ) {
388+ return new NodeCustomEvent ( type , { detail : nodeValue } ) ;
389+ }
379390 [ customInspectSymbol ] ( depth , options ) {
380391 const name = this . constructor . name ;
381392 if ( depth < 0 )
@@ -473,6 +484,14 @@ class NodeEventTarget extends EventTarget {
473484 this . addEventListener ( type , listener , { [ kIsNodeStyleListener ] : true } ) ;
474485 return this ;
475486 }
487+ emit ( type , arg ) {
488+ if ( typeof type !== 'string' ) {
489+ throw new ERR_INVALID_ARG_TYPE ( 'type' , 'string' , type ) ;
490+ }
491+ const hadListeners = this . listenerCount ( type ) > 0 ;
492+ this [ kHybridDispatch ] ( arg , type ) ;
493+ return hadListeners ;
494+ }
476495
477496 once ( type , listener ) {
478497 this . addEventListener ( type , listener ,
@@ -501,6 +520,7 @@ Object.defineProperties(NodeEventTarget.prototype, {
501520 on : { enumerable : true } ,
502521 addListener : { enumerable : true } ,
503522 once : { enumerable : true } ,
523+ emit : { enumerable : true } ,
504524 removeAllListeners : { enumerable : true } ,
505525} ) ;
506526
0 commit comments