Skip to content

Commit a16753c

Browse files
committed
JS: Add documentation
1 parent f3c80c7 commit a16753c

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

javascript/ql/src/semmle/javascript/dataflow/internal/AccessPaths.qll

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,38 @@ private SsaVariable getRefinedVariable(SsaVariable variable) {
4343
result = variable.getDefinition().(SsaRefinementNode).getAnInput()
4444
}
4545

46-
private SsaVariable getARefinementOf(SsaVariable variable) {
47-
variable = getRefinedVariable(result)
48-
}
46+
private SsaVariable getARefinementOf(SsaVariable variable) { variable = getRefinedVariable(result) }
4947

5048
/**
51-
* A representation of a (nested) property access on an SSA variable
49+
* A representation of a (nested) property access on an SSA variable or captured variable
5250
* where each property name is either constant or itself an SSA variable.
5351
*/
5452
private newtype TAccessPath =
53+
/**
54+
* An access path rooted in an SSA variable.
55+
*
56+
* Refinement nodes are treated as no-ops so that all uses of a refined value are
57+
* given the same access path. Refinement nodes are therefore never treated as roots.
58+
*/
5559
MkSsaRoot(SsaVariable var) {
5660
not exists(getRefinedVariable(var)) and
57-
not var.getSourceVariable().isCaptured()
58-
}
59-
or
60-
MkCapturedRoot(LocalVariable var) {
61-
var.isCaptured()
62-
}
63-
or
61+
not var.getSourceVariable().isCaptured() // Handled by MkCapturedRoot
62+
} or
63+
/**
64+
* An access path rooted in a captured variable.
65+
*
66+
* The SSA form for captured variables is too conservative for constructing
67+
* access paths across function boundaries, so in this case we use the source
68+
* variable as the root.
69+
*/
70+
MkCapturedRoot(LocalVariable var) { var.isCaptured() } or
71+
/**
72+
* An access path rooted in the receiver of a function.
73+
*/
6474
MkThisRoot(Function function) { function.getThisBinder() = function } or
75+
/**
76+
* A property access on an access path.
77+
*/
6578
MkAccessStep(AccessPath base, PropertyName name) {
6679
exists(PropAccess pacc |
6780
pacc.getBase() = base.getAnInstance() and
@@ -70,7 +83,7 @@ private newtype TAccessPath =
7083
}
7184

7285
/**
73-
* A representation of a (nested) property access on an SSA variable
86+
* A representation of a (nested) property access on an SSA variable or captured variable
7487
* where each property name is either constant or itself an SSA variable.
7588
*/
7689
class AccessPath extends TAccessPath {

0 commit comments

Comments
 (0)