JS: add FunctionNode.getThisParameter

This commit is contained in:
Asger F
2018-12-12 16:21:20 +00:00
parent a4b3b1e8c8
commit 635a3cb1ec
4 changed files with 42 additions and 0 deletions

View File

@@ -311,6 +311,25 @@ class FunctionNode extends DataFlow::ValueNode, DataFlow::DefaultSourceNode {
Function getFunction() {
result = astNode
}
/**
* Gets the function whose `this` binding a `this` expression in this function refers to,
* which is the nearest enclosing non-arrow function.
*/
FunctionNode getThisBinder() {
result.getFunction() = getFunction().getThisBinder()
}
/**
* Gets the dataflow node holding the value of the `this` argument passed to the given function.
*
* Has no result for arrow functions, as they ignore the receiver argument.
*
* To get the data flow node for `this` in an arrow function, consider using `getThisBinder().getThisParameter()`.
*/
ThisNode getThisParameter() {
result.getBinder() = this
}
}
/** A data flow node corresponding to an object literal expression. */