mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
JS: support FP pattern for js/unbound-event-handler-receiver
This commit is contained in:
@@ -18,7 +18,15 @@ private predicate isBoundInMethod(MethodDeclaration method) {
|
||||
bindingMethod.getDeclaringClass() = method.getDeclaringClass() and
|
||||
not bindingMethod.isStatic() and
|
||||
thiz.getBinder().getAstNode() = bindingMethod.getBody()
|
||||
|
|
||||
|
|
||||
exists (DataFlow::MethodCallNode bind, DataFlow::PropWrite w |
|
||||
// this[x] = <expr>.bind(...)
|
||||
w = thiz.getAPropertyWrite() and
|
||||
not exists(w.getPropertyName()) and
|
||||
bind.getMethodName() = "bind" and
|
||||
bind.flowsTo(w.getRhs())
|
||||
)
|
||||
or
|
||||
// require("auto-bind")(this)
|
||||
thiz.flowsTo(DataFlow::moduleImport("auto-bind").getACall().getArgument(0))
|
||||
or
|
||||
|
||||
@@ -134,4 +134,25 @@ class Component2 extends React.Component {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Component3 extends React.Component {
|
||||
|
||||
render() {
|
||||
return <div>
|
||||
<div onClick={this.bound_throughIterator}/> // OK
|
||||
</div>
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
Object.getOwnPropertyNames( Component3.prototype )
|
||||
.filter( prop => typeof this[ prop ] === 'function' )
|
||||
.forEach( prop => ( this[ prop ] = this[ prop ].bind( this ) ) );
|
||||
}
|
||||
|
||||
bound_throughIterator() {
|
||||
this.setState({ });
|
||||
}
|
||||
}
|
||||
|
||||
// semmle-extractor-options: --experimental
|
||||
|
||||
Reference in New Issue
Block a user