@@ -172,6 +172,14 @@ ObjectDefineProperty(Event.prototype, SymbolToStringTag, {
172172 value : 'Event' ,
173173} ) ;
174174
175+ class NodeCustomEvent extends Event {
176+ constructor ( type , options ) {
177+ super ( type , options ) ;
178+ if ( options && options . detail ) {
179+ this . detail = options . detail ;
180+ }
181+ }
182+ }
175183// The listeners for an EventTarget are maintained as a linked list.
176184// Unfortunately, the way EventTarget is defined, listeners are accounted
177185// using the tuple [handler,capture], and even if we don't actually make
@@ -377,6 +385,9 @@ class EventTarget {
377385 event [ kTarget ] = undefined ;
378386 }
379387
388+ [ kCreateEvent ] ( nodeValue , type ) {
389+ return new NodeCustomEvent ( type , { detail : nodeValue } ) ;
390+ }
380391 [ customInspectSymbol ] ( depth , options ) {
381392 const name = this . constructor . name ;
382393 if ( depth < 0 )
@@ -474,6 +485,14 @@ class NodeEventTarget extends EventTarget {
474485 this . addEventListener ( type , listener , { [ kIsNodeStyleListener ] : true } ) ;
475486 return this ;
476487 }
488+ emit ( type , arg ) {
489+ if ( typeof type !== 'string' ) {
490+ throw new ERR_INVALID_ARG_TYPE ( 'type' , 'string' , type ) ;
491+ }
492+ const hadListeners = this . listenerCount ( type ) > 0 ;
493+ this [ kHybridDispatch ] ( arg , type ) ;
494+ return hadListeners ;
495+ }
477496
478497 once ( type , listener ) {
479498 this . addEventListener ( type , listener ,
@@ -502,6 +521,7 @@ ObjectDefineProperties(NodeEventTarget.prototype, {
502521 on : { enumerable : true } ,
503522 addListener : { enumerable : true } ,
504523 once : { enumerable : true } ,
524+ emit : { enumerable : true } ,
505525 removeAllListeners : { enumerable : true } ,
506526} ) ;
507527
0 commit comments