Skip to content

Commit 1db2e6c

Browse files
author
Esben Sparre Andreasen
committed
JS: add source code examples to docstrings
1 parent 3aae1d1 commit 1db2e6c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

javascript/ql/src/semmle/javascript/DefensiveProgramming.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ module Internal {
6262

6363
/**
6464
* An equality test for `null` and `undefined`.
65+
*
66+
* Examples: `e === undefined` or `typeof e !== undefined`.
6567
*/
6668
private abstract class UndefinedNullTest extends EqualityTest {
6769
/** Gets the unique Boolean value that this test evaluates to, if any. */
@@ -75,6 +77,8 @@ module Internal {
7577

7678
/**
7779
* A dis- or conjunction that tests if an expression is `null` or `undefined` in either branch.
80+
*
81+
* Example: a branch in `x === null || x === undefined`.
7882
*/
7983
private class CompositeUndefinedNullTestPart extends DefensiveExpressionTest {
8084

@@ -103,6 +107,8 @@ module Internal {
103107

104108
/**
105109
* A test for `undefined` or `null` in an if-statement.
110+
*
111+
* Example: `if (x === null) ...`.
106112
*/
107113
private class SanityCheckingUndefinedNullGuard extends DefensiveExpressionTest {
108114

@@ -143,6 +149,8 @@ module Internal {
143149

144150
/**
145151
* A value comparison for `null` and `undefined`.
152+
*
153+
* Examples: `x === null` or `x != undefined`.
146154
*/
147155
private class NullUndefinedComparison extends UndefinedNullTest {
148156

@@ -188,6 +196,8 @@ module Internal {
188196

189197
/**
190198
* An expression that throws an exception if one of its subexpressions evaluates to `null` or `undefined`.
199+
*
200+
* Examples: `sub.p` or `sub()`.
191201
*/
192202
private class UndefinedNullCrashUse extends Expr {
193203

@@ -212,6 +222,8 @@ module Internal {
212222

213223
/**
214224
* An expression that throws an exception if one of its subexpressions is not a `function`.
225+
*
226+
* Example: `sub()`.
215227
*/
216228
private class NonFunctionCallCrashUse extends Expr {
217229

@@ -263,6 +275,8 @@ module Internal {
263275

264276
/**
265277
* A defensive expression that tests for `undefined` and `null` using a truthiness test.
278+
*
279+
* Examples: The condition in `if(x) { x.p; }` or `!x || x.m()`.
266280
*/
267281
private class UndefinedNullTruthinessGuard extends DefensiveExpressionTest {
268282

@@ -294,6 +308,8 @@ module Internal {
294308

295309
/**
296310
* A defensive expression that tests for `undefined` and `null`.
311+
*
312+
* Example: the condition in `if(x !== null) { x.p; }`.
297313
*/
298314
private class UndefinedNullTypeGuard extends DefensiveExpressionTest {
299315

@@ -321,6 +337,8 @@ module Internal {
321337

322338
/**
323339
* A test for the value of a `typeof` expression.
340+
*
341+
* Example: `typeof x === 'undefined'`.
324342
*/
325343
private class TypeofTest extends EqualityTest {
326344
Expr operand;
@@ -363,6 +381,8 @@ module Internal {
363381

364382
/**
365383
* A defensive expression that tests if an expression has type `function`.
384+
*
385+
* Example: the condition in `if(typeof x === 'function') x()`.
366386
*/
367387
private class FunctionTypeGuard extends DefensiveExpressionTest {
368388

@@ -391,6 +411,8 @@ module Internal {
391411

392412
/**
393413
* A test for `undefined` using a `typeof` expression.
414+
*
415+
* Example: `typeof x === undefined'.
394416
*/
395417
class TypeofUndefinedTest extends UndefinedNullTest {
396418

0 commit comments

Comments
 (0)