@@ -894,17 +894,52 @@ module NodeJSLib {
894894 DataFlow:: SourceNode ref ( ) { result = EventEmitter:: trackEventEmitter ( this ) }
895895 }
896896
897+ /**
898+ * Gets an import of the NodeJS EventEmitter.
899+ */
900+ private DataFlow:: SourceNode getAnEventEmitterImport ( ) {
901+ result = DataFlow:: moduleImport ( "events" ) or
902+ result = DataFlow:: moduleMember ( "events" , "EventEmitter" )
903+ }
904+
897905 /**
898906 * An instance of an EventEmitter that is imported through the 'events' module.
899907 */
900908 private class ImportedNodeJSEventEmitter extends NodeJSEventEmitter {
901909 ImportedNodeJSEventEmitter ( ) {
902- exists ( DataFlow:: SourceNode clazz |
903- clazz = DataFlow:: moduleImport ( "events" ) or
904- clazz = DataFlow:: moduleMember ( "events" , "EventEmitter" )
905- |
906- this = clazz .getAnInstantiation ( )
907- )
910+ this = getAnEventEmitterImport ( ) .getAnInstantiation ( )
911+ }
912+ }
913+
914+ /**
915+ * A class that extends EventEmitter.
916+ */
917+ private class EventEmitterSubClass extends DataFlow:: ClassNode {
918+ EventEmitterSubClass ( ) {
919+ this .getASuperClassNode ( ) .getALocalSource ( ) = getAnEventEmitterImport ( ) or
920+ this .getADirectSuperClass ( ) instanceof EventEmitterSubClass
921+ }
922+
923+ private DataFlow:: SourceNode ref ( DataFlow:: TypeTracker t ) {
924+ t .start ( ) and result = this
925+ or
926+ exists ( DataFlow:: TypeTracker t2 | result = ref ( t2 ) .track ( t2 , t ) )
927+ }
928+
929+ /**
930+ * Gets a reference to this class.
931+ */
932+ DataFlow:: SourceNode ref ( ) { result = ref ( DataFlow:: TypeTracker:: end ( ) ) }
933+ }
934+
935+ /**
936+ * An instantiation of a class that extends EventEmitter.
937+ *
938+ * By extending `NodeJSEventEmitter' we get data-flow on the events passing through this EventEmitter.
939+ */
940+ private class CustomEventEmitter extends NodeJSEventEmitter {
941+ CustomEventEmitter ( ) {
942+ this = any ( EventEmitterSubClass clazz ) .ref ( ) .getAnInstantiation ( )
908943 }
909944 }
910945
0 commit comments