Skip to content

Commit db9ac72

Browse files
author
Max Schaefer
authored
Merge pull request #957 from esben-semmle/js/another-autobinder-model
JS: model one more 'autobind' for js/unbound-event-handler-receiver
2 parents 12ed2ca + 27cae0c commit db9ac72

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

javascript/ql/src/Expressions/UnboundEventHandlerReceiver.ql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ private predicate isBoundInMethod(MethodDeclaration method) {
2828
)
2929
or
3030
// require("auto-bind")(this)
31-
thiz.flowsTo(DataFlow::moduleImport("auto-bind").getACall().getArgument(0))
31+
exists (string mod |
32+
mod = "auto-bind" or
33+
mod = "react-autobind" |
34+
thiz.flowsTo(DataFlow::moduleImport(mod).getACall().getArgument(0))
35+
)
3236
or
3337
exists(string name | name = method.getName() |
3438
exists(DataFlow::MethodCallNode bind |

javascript/ql/test/query-tests/Expressions/UnboundEventHandlerReceiver/tst.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import autoBind from 'auto-bind';
3-
3+
import reactAutobind from 'react-autobind';
44
class Component0 extends React.Component {
55

66
render() {
@@ -155,4 +155,22 @@ class Component3 extends React.Component {
155155
}
156156
}
157157

158+
class Component4 extends React.Component {
159+
160+
render() {
161+
return <div>
162+
<div onClick={this.bound_throughReactAutobind}/> // OK
163+
</div>
164+
}
165+
166+
constructor(props) {
167+
super(props);
168+
reactAutobind(this);
169+
}
170+
171+
bound_throughReactAutobind() {
172+
this.setState({ });
173+
}
174+
}
175+
158176
// semmle-extractor-options: --experimental

0 commit comments

Comments
 (0)