Skip to content

Commit ad67015

Browse files
committed
JS: Address comments
1 parent d05b904 commit ad67015

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

docs/language/learn-ql/javascript/type-tracking.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ Use this template to define backward type tracking predicates:
431431
Note that these predicates all return ``SourceNode``,
432432
so attempts to track a non-source node, such as an identifier or string literal,
433433
will not work.
434+
If this becomes an issue, see
435+
`TypeTracker.smallstep <https://help.semmle.com/qldoc/javascript/semmle/javascript/dataflow/TypeTracking.qll/predicate.TypeTracking$TypeTracker$smallstep.2.html>`__.
434436

435437
Also note that the predicates taking a ``TypeTracker`` or ``TypeBackTracker`` can often be made ``private``,
436438
as they are typically only used as an intermediate result to compute the other predicate.
@@ -441,7 +443,7 @@ Limitations
441443
As mentioned, type tracking will track values in and out of function calls and properties,
442444
but only within some limits.
443445

444-
Type tracking does not always track *through* functions, that is, if a value flows into a parameter
446+
For example, type tracking does not always track *through* functions, that is, if a value flows into a parameter
445447
and back out of the return value, it might not be tracked back out to the call site again.
446448
Here's an example that the model from this tutorial won't find:
447449

@@ -458,7 +460,7 @@ This is an example of where `data flow configurations <https://help.semmle.com/Q
458460
When to use type tracking
459461
-------------------------
460462

461-
Type tracking and data flow configurations are essentially competing solutions to the same
463+
Type tracking and data flow configurations are different solutions to the same
462464
problem, each with their own tradeoffs.
463465

464466
Type tracking can be used in any number of predicates, which may depend on each other

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,29 @@ class TypeTracker extends TTypeTracker {
187187
)
188188
}
189189

190-
/**
190+
/**
191191
* Gets the summary that corresponds to having taken a forwards
192192
* local, heap and/or inter-procedural step from `pred` to `succ`.
193193
*
194194
* Unlike `TypeTracker::step`, this predicate exposes all edges
195195
* in the flow graph, and not just the edges between `SourceNode`s.
196196
* It may therefore be less performant.
197+
*
198+
* Type tracking predicates using small steps typically take the following form:
199+
* ```ql
200+
* DataFlow::Node myType(DataFlow::TypeTracker t) {
201+
* t.start() and
202+
* result = < source of myType >
203+
* or
204+
* exists (DataFlow::TypeTracker t2 |
205+
* t = t2.smallstep(myType(t2), result)
206+
* )
207+
* }
208+
*
209+
* DataFlow::Node myType() {
210+
* result = myType(DataFlow::TypeTracker::end())
211+
* }
212+
* ```
197213
*/
198214
pragma[inline]
199215
TypeTracker smallstep(DataFlow::Node pred, DataFlow::Node succ) {
@@ -319,6 +335,22 @@ class TypeBackTracker extends TTypeBackTracker {
319335
* Unlike `TypeBackTracker::step`, this predicate exposes all edges
320336
* in the flowgraph, and not just the edges between
321337
* `SourceNode`s. It may therefore be less performant.
338+
*
339+
* Type tracking predicates using small steps typically take the following form:
340+
* ```ql
341+
* DataFlow::Node myType(DataFlow::TypeBackTracker t) {
342+
* t.start() and
343+
* result = < some API call >.getArgument(< n >)
344+
* or
345+
* exists (DataFlow::TypeTracker t2 |
346+
* t = t2.smallstep(result, myType(t2))
347+
* )
348+
* }
349+
*
350+
* DataFlow::Node myType() {
351+
* result = myType(DataFlow::TypeBackTracker::end())
352+
* }
353+
* ```
322354
*/
323355
pragma[inline]
324356
TypeBackTracker smallstep(DataFlow::Node pred, DataFlow::Node succ) {

0 commit comments

Comments
 (0)