@@ -388,23 +388,33 @@ module DOM {
388
388
}
389
389
}
390
390
391
- /**
392
- * Gets a reference to a DOM event.
393
- */
394
- private DataFlow:: SourceNode domEventSource ( ) {
395
- // e.g. <form onSubmit={e => e.target}/>
396
- exists ( JsxAttribute attr | attr .getName ( ) .matches ( "on%" ) |
397
- result = attr .getValue ( ) .flow ( ) .getABoundFunctionValue ( 0 ) .getParameter ( 0 )
398
- )
399
- or
400
- // node.addEventListener("submit", e => e.target)
401
- result = domValueRef ( ) .getAMethodCall ( "addEventListener" ) .getABoundCallbackParameter ( 1 , 0 )
402
- or
403
- // node.onSubmit = (e => e.target);
404
- exists ( DataFlow:: PropWrite write | write = domValueRef ( ) .getAPropertyWrite ( ) |
405
- write .getPropertyName ( ) .matches ( "on%" ) and
406
- result = write .getRhs ( ) .getAFunctionValue ( ) .getParameter ( 0 )
407
- )
391
+ /** A data flow node that is a source of DOM events. */
392
+ class DomEventSource extends DataFlow:: Node instanceof DomEventSource:: Range { }
393
+
394
+ /** Companion module to the `DomEventSource` class. */
395
+ module DomEventSource {
396
+ /**
397
+ * A data flow node that should be considered a source of DOM events.
398
+ */
399
+ abstract class Range extends DataFlow:: Node { }
400
+
401
+ private class DefaultRange extends Range {
402
+ DefaultRange ( ) {
403
+ // e.g. <form onSubmit={e => e.target}/>
404
+ exists ( JsxAttribute attr | attr .getName ( ) .matches ( "on%" ) |
405
+ this = attr .getValue ( ) .flow ( ) .getABoundFunctionValue ( 0 ) .getParameter ( 0 )
406
+ )
407
+ or
408
+ // node.addEventListener("submit", e => e.target)
409
+ this = domValueRef ( ) .getAMethodCall ( "addEventListener" ) .getABoundCallbackParameter ( 1 , 0 )
410
+ or
411
+ // node.onSubmit = (e => e.target);
412
+ exists ( DataFlow:: PropWrite write | write = domValueRef ( ) .getAPropertyWrite ( ) |
413
+ write .getPropertyName ( ) .matches ( "on%" ) and
414
+ this = write .getRhs ( ) .getAFunctionValue ( ) .getParameter ( 0 )
415
+ )
416
+ }
417
+ }
408
418
}
409
419
410
420
/** Gets a data flow node that refers directly to a value from the DOM. */
@@ -419,7 +429,7 @@ module DOM {
419
429
result = domValueRef ( ) .getAMethodCall ( [ "item" , "namedItem" ] )
420
430
or
421
431
t .startInProp ( "target" ) and
422
- result = domEventSource ( )
432
+ result instanceof DomEventSource
423
433
or
424
434
t .startInProp ( DataFlow:: PseudoProperties:: arrayElement ( ) ) and
425
435
result = domElementCollection ( )
0 commit comments