Skip to content

Commit d05b904

Browse files
committed
JS: Add type tracking templates to cheat sheet
1 parent 54661f0 commit d05b904

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/language/learn-ql/javascript/dataflow-cheat-sheet.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,49 @@ String matching
160160
- x.\ `regexpMatch <https://help.semmle.com/qldoc/javascript/predicate.string$regexpMatch.1.html>`__\ ("(?i).*escape.*") -- holds if x contains
161161
"escape" (case insensitive)
162162

163+
Type tracking
164+
-------------
165+
166+
See also: :doc:`Type tracking tutorial <type-tracking>`.
167+
168+
Use the following template to define forward type tracking predicates:
169+
170+
.. code-block:: ql
171+
172+
import DataFlow
173+
174+
SourceNode myType(TypeTracker t) {
175+
t.start() and
176+
result = /* SourceNode to track */
177+
or
178+
exists(TypeTracker t2 |
179+
result = myType(t2).track(t2, t)
180+
)
181+
}
182+
183+
SourceNode myType() {
184+
result = myType(TypeTracker::end())
185+
}
186+
187+
Use the following template to define backward type tracking predicates:
188+
189+
.. code-block:: ql
190+
191+
import DataFlow
192+
193+
SourceNode myType(TypeBackTracker t) {
194+
t.start() and
195+
result = (/* argument to track */).getALocalSource()
196+
or
197+
exists(TypeBackTracker t2 |
198+
result = myType(t2).backtrack(t2, t)
199+
)
200+
}
201+
202+
SourceNode myType() {
203+
result = myType(TypeBackTracker::end())
204+
}
205+
163206
Troubleshooting
164207
---------------
165208

0 commit comments

Comments
 (0)