Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3dcb134

Browse files
committed
JS: Improve documentation
1 parent cf24fa2 commit 3dcb134

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

  • javascript/ql/src/semmle/javascript/dataflow

javascript/ql/src/semmle/javascript/dataflow/Nodes.qll

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,32 @@ class InvokeNode extends DataFlow::SourceNode {
9494
* Gets a function passed as the `i`th argument of this invocation.
9595
*
9696
* This predicate only performs local data flow tracking.
97-
* Use `getACallbackSource` to handle interprocedural flow of callback functions.
97+
* Consider using `getABoundCallbackParameter` to handle interprocedural flow of callback functions.
9898
*/
9999
FunctionNode getCallback(int i) { result.flowsTo(getArgument(i)) }
100100

101101
/**
102-
* Gets a function passed as the `i`th argument of this invocation,
103-
* possibly through non-local data flow and bound by partial function invocations.
102+
* Gets a parameter of a callback passed into this call.
103+
*
104+
* `callback` indicates which argument the callback passed into, and `param`
105+
* is the index of the parameter in the callback function.
106+
*
107+
* For example, for the call below, `getABoundCallbackParameter(1, 0)` refers
108+
* to the parameter `e` (the first parameter of the second callback argument):
109+
* ```js
110+
* addEventHandler("click", e => { ... })
111+
* ```
112+
*
113+
* This predicate takes interprocedural data flow into account, as well as
114+
* partial function applications such as `.bind`.
115+
*
116+
* For example, for the call below `getABoundCallbackParameter(1, 0)` returns the parameter `e`,
117+
* (the first parameter of the second callback argument), since the first parameter of `foo`
118+
* has been bound by the `bind` call:
119+
* ```js
120+
* function foo(x, e) { }
121+
* addEventHandler("click", foo.bind(this, "value of x"))
122+
* ```
104123
*/
105124
ParameterNode getABoundCallbackParameter(int callback, int param) {
106125
exists(int boundArgs |

0 commit comments

Comments
 (0)