mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
JS: add FunctionNode.getThisParameter
This commit is contained in:
@@ -311,6 +311,25 @@ class FunctionNode extends DataFlow::ValueNode, DataFlow::DefaultSourceNode {
|
|||||||
Function getFunction() {
|
Function getFunction() {
|
||||||
result = astNode
|
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. */
|
/** A data flow node corresponding to an object literal expression. */
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
| tst.js:1:1:13:1 | functio ... \\n };\\n} | tst.js:1:1:1:0 | this |
|
||||||
|
| tst.js:2:3:2:21 | function inner() {} | tst.js:2:3:2:2 | this |
|
||||||
|
| tst.js:5:11:5:10 | () {} | tst.js:5:11:5:10 | this |
|
||||||
|
| tst.js:6:11:6:15 | () {} | tst.js:6:11:6:10 | this |
|
||||||
|
| tst.js:10:15:10:19 | () {} | tst.js:10:15:10:14 | this |
|
||||||
|
| tst.js:11:15:11:20 | (x) {} | tst.js:11:15:11:14 | this |
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import javascript
|
||||||
|
|
||||||
|
from DataFlow::FunctionNode function
|
||||||
|
select function, function.getThisParameter()
|
||||||
13
javascript/ql/test/library-tests/ThisParameter/tst.js
Normal file
13
javascript/ql/test/library-tests/ThisParameter/tst.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
function f() {
|
||||||
|
function inner() {}
|
||||||
|
let arrow = () => 5;
|
||||||
|
|
||||||
|
class C {
|
||||||
|
method() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
let obj = {
|
||||||
|
get getter() {},
|
||||||
|
set setter(x) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user