File tree Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -355,8 +355,16 @@ module DOM {
355
355
)
356
356
or
357
357
// A receiver node of an event handler on a DOM node
358
- exists ( string handler | handler .matches ( "on%" ) |
359
- this = domValueRef ( ) .getAPropertySource ( handler ) .( DataFlow:: FunctionNode ) .getReceiver ( )
358
+ exists ( DataFlow:: SourceNode domNode , DataFlow:: FunctionNode eventHandler |
359
+ // NOTE: we do not use `getABoundFunctionValue()`, since bound functions tend to have
360
+ // a different receiver anyway
361
+ eventHandler = domNode .getAPropertySource ( any ( string n | n .matches ( "on%" ) ) )
362
+ or
363
+ eventHandler =
364
+ domNode .getAMethodCall ( "addEventListener" ) .getArgument ( 1 ) .getAFunctionValue ( )
365
+ |
366
+ domNode = domValueRef ( ) and
367
+ this = eventHandler .getReceiver ( )
360
368
)
361
369
or
362
370
this = DataFlow:: thisNode ( any ( EventHandlerCode evt ) )
Original file line number Diff line number Diff line change 1
1
test_documentRef
2
2
| customization.js:2:13:2:31 | customGetDocument() |
3
3
| event-handler-receiver.js:1:1:1:8 | document |
4
+ | event-handler-receiver.js:5:1:5:8 | document |
4
5
| nameditems.js:1:1:1:8 | document |
5
6
test_locationRef
6
7
| customization.js:3:3:3:14 | doc.location |
7
- | event-handler-receiver.js:2:49:2:56 | location |
8
8
test_domValueRef
9
9
| customization.js:4:3:4:20 | doc.getElementById |
10
10
| customization.js:4:3:4:28 | doc.get ... 'test') |
@@ -13,6 +13,10 @@ test_domValueRef
13
13
| event-handler-receiver.js:1:1:1:32 | documen ... my-id') |
14
14
| event-handler-receiver.js:1:44:1:43 | this |
15
15
| event-handler-receiver.js:2:3:2:17 | this.parentNode |
16
+ | event-handler-receiver.js:5:1:5:23 | documen ... entById |
17
+ | event-handler-receiver.js:5:1:5:32 | documen ... my-id') |
18
+ | event-handler-receiver.js:5:60:5:59 | this |
19
+ | event-handler-receiver.js:6:3:6:17 | this.parentNode |
16
20
| nameditems.js:1:1:1:23 | documen ... entById |
17
21
| nameditems.js:1:1:1:30 | documen ... ('foo') |
18
22
| nameditems.js:1:1:2:19 | documen ... em('x') |
Original file line number Diff line number Diff line change 3
3
< body >
4
4
< button onclick ="alert(this.tagName); "> Click me</ button >
5
5
</ body >
6
- </ html >
6
+ </ html >
Original file line number Diff line number Diff line change 1
- document . getElementById ( 'my-id' ) . onclick = function ( ) {
2
- this . parentNode . innerHTML = '<h2><a href="' + location . href + '">A link</a></h2> '; // NOT OK
1
+ document . getElementById ( 'my-id' ) . onclick = function ( ) {
2
+ this . parentNode . innerHTML = '<b>hello</b> ' ; // `this` is a DOM element
3
3
} ;
4
+
5
+ document . getElementById ( 'my-id' ) . addEventListener ( "click" , function ( ev ) {
6
+ this . parentNode . innerHTML = '<b>hello</b>' ; // `this` is a DOM element
7
+ } ) ;
You can’t perform that action at this time.
0 commit comments