Skip to content

Commit ad665b7

Browse files
authored
Merge pull request github#5323 from erik-krogh/staging
Approved by asgerf
2 parents e1adf5e + ee9613f commit ad665b7

File tree

18 files changed

+292
-12
lines changed

18 files changed

+292
-12
lines changed

javascript/ql/src/semmle/javascript/AMD.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import javascript
7+
private import semmle.javascript.internal.CachedStages
78

89
/**
910
* An AMD `define` call.
@@ -298,7 +299,10 @@ private class AmdDependencyImport extends Import {
298299
*/
299300
class AmdModule extends Module {
300301
cached
301-
AmdModule() { exists(unique(AmdModuleDefinition def | amdModuleTopLevel(def, this))) }
302+
AmdModule() {
303+
Stages::DataFlowStage::ref() and
304+
exists(unique(AmdModuleDefinition def | amdModuleTopLevel(def, this)))
305+
}
302306

303307
/** Gets the definition of this module. */
304308
AmdModuleDefinition getDefine() { amdModuleTopLevel(result, this) }

javascript/ql/src/semmle/javascript/AST.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import javascript
66
private import internal.StmtContainers
7+
private import semmle.javascript.internal.CachedStages
78

89
/**
910
* A program element corresponding to JavaScript code, such as an expression
@@ -75,7 +76,7 @@ class ASTNode extends @ast_node, NodeInStmtContainer {
7576

7677
/** Gets the toplevel syntactic unit to which this element belongs. */
7778
cached
78-
TopLevel getTopLevel() { result = getParent().getTopLevel() }
79+
TopLevel getTopLevel() { Stages::Ast::ref() and result = getParent().getTopLevel() }
7980

8081
/**
8182
* Gets the `i`th child node of this node.
@@ -119,7 +120,7 @@ class ASTNode extends @ast_node, NodeInStmtContainer {
119120

120121
/** Gets the parent node of this node, if any. */
121122
cached
122-
ASTNode getParent() { this = result.getAChild() }
123+
ASTNode getParent() { Stages::Ast::ref() and this = result.getAChild() }
123124

124125
/** Gets the first control flow node belonging to this syntactic entity. */
125126
ControlFlowNode getFirstControlFlowNode() { result = this }
@@ -135,6 +136,7 @@ class ASTNode extends @ast_node, NodeInStmtContainer {
135136
*/
136137
cached
137138
private predicate isAmbientInternal() {
139+
Stages::Ast::ref() and
138140
getParent().isAmbientInternal()
139141
or
140142
not isAmbientTopLevel(getTopLevel()) and
@@ -186,7 +188,9 @@ class ASTNode extends @ast_node, NodeInStmtContainer {
186188
* Holds if the given file is a `.d.ts` file.
187189
*/
188190
cached
189-
private predicate isAmbientTopLevel(TopLevel tl) { tl.getFile().getBaseName().matches("%.d.ts") }
191+
private predicate isAmbientTopLevel(TopLevel tl) {
192+
Stages::Ast::ref() and tl.getFile().getBaseName().matches("%.d.ts")
193+
}
190194

191195
/**
192196
* A toplevel syntactic unit; that is, a stand-alone script, an inline script

javascript/ql/src/semmle/javascript/BasicBlocks.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import javascript
77
private import internal.StmtContainers
8+
private import semmle.javascript.internal.CachedStages
89

910
/**
1011
* Holds if `nd` starts a new basic block.
@@ -60,7 +61,9 @@ private module Internal {
6061

6162
cached
6263
predicate useAt(BasicBlock bb, int i, Variable v, VarUse u) {
63-
v = u.getVariable() and bbIndex(bb, u, i)
64+
Stages::BasicBlocks::ref() and
65+
v = u.getVariable() and
66+
bbIndex(bb, u, i)
6467
}
6568

6669
cached

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import javascript
6+
private import semmle.javascript.internal.CachedStages
67

78
/**
89
* A program element that is either an expression or a type annotation.
@@ -109,7 +110,7 @@ class Expr extends @expr, ExprOrStmt, ExprOrType, AST::ValueNode {
109110

110111
/** Gets the constant string value this expression evaluates to, if any. */
111112
cached
112-
string getStringValue() { result = getStringValue(this) }
113+
string getStringValue() { Stages::Ast::ref() and result = getStringValue(this) }
113114

114115
/** Holds if this expression is impure, that is, its evaluation could have side effects. */
115116
predicate isImpure() { any() }
@@ -257,6 +258,7 @@ class Expr extends @expr, ExprOrStmt, ExprOrType, AST::ValueNode {
257258

258259
cached
259260
private DataFlow::Node getCatchParameterFromStmt(Stmt stmt) {
261+
Stages::DataFlowStage::ref() and
260262
result =
261263
DataFlow::parameterNode(stmt.getEnclosingTryCatchStmt().getACatchClause().getAParameter())
262264
}
@@ -806,7 +808,9 @@ class FunctionExpr extends @function_expr, Expr, Function {
806808
/** Gets the statement in which this function expression appears. */
807809
override Stmt getEnclosingStmt() { result = Expr.super.getEnclosingStmt() }
808810

809-
override StmtContainer getEnclosingContainer() { result = Expr.super.getContainer() }
811+
override StmtContainer getEnclosingContainer() {
812+
Stages::Ast::ref() and result = Expr.super.getContainer()
813+
}
810814

811815
override predicate isImpure() { none() }
812816

javascript/ql/src/semmle/javascript/GlobalAccessPaths.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javascript
66
private import semmle.javascript.dataflow.InferredTypes
77
private import semmle.javascript.dataflow.internal.FlowSteps as FlowSteps
8+
private import semmle.javascript.internal.CachedStages
89

910
deprecated module GlobalAccessPath {
1011
/**
@@ -429,7 +430,6 @@ module AccessPath {
429430
/**
430431
* A classification of acccess paths into reads and writes.
431432
*/
432-
cached
433433
private newtype AccessPathKind =
434434
AccessPathRead() or
435435
AccessPathWrite()
@@ -440,6 +440,7 @@ module AccessPath {
440440
*
441441
* Only has a result if there exists both a read and write of the access-path within `bb`.
442442
*/
443+
pragma[nomagic]
443444
private ControlFlowNode rankedAccessPath(
444445
ReachableBasicBlock bb, Root root, string path, int ranking, AccessPathKind type
445446
) {
@@ -539,6 +540,7 @@ module AccessPath {
539540
*/
540541
cached
541542
predicate hasDominatingWrite(DataFlow::PropRead read) {
543+
Stages::FlowSteps::ref() and
542544
// within the same basic block.
543545
exists(ReachableBasicBlock bb, Root root, string path, int ranking |
544546
read.asExpr() = rankedAccessPath(bb, root, path, ranking, AccessPathRead()) and

javascript/ql/src/semmle/javascript/JSDoc.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Provides classes for working with JSDoc comments. */
22

33
import javascript
4+
private import semmle.javascript.internal.CachedStages
45

56
/**
67
* A JSDoc comment.
@@ -57,7 +58,9 @@ class JSDoc extends @jsdoc, Locatable {
5758
abstract class Documentable extends ASTNode {
5859
/** Gets the JSDoc comment for this element, if any. */
5960
cached
60-
JSDoc getDocumentation() { result.getComment().getNextToken() = getFirstToken() }
61+
JSDoc getDocumentation() {
62+
Stages::Ast::ref() and result.getComment().getNextToken() = getFirstToken()
63+
}
6164
}
6265

6366
/**

javascript/ql/src/semmle/javascript/Modules.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import javascript
8+
private import semmle.javascript.internal.CachedStages
89

910
/**
1011
* A module, which may either be an ECMAScript 2015-style module,
@@ -239,6 +240,7 @@ abstract class Import extends ASTNode {
239240
*/
240241
cached
241242
Module getImportedModule() {
243+
Stages::Imports::ref() and
242244
if exists(resolveExternsImport())
243245
then result = resolveExternsImport()
244246
else (

javascript/ql/src/semmle/javascript/SSA.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
import javascript
7878
private import semmle.javascript.dataflow.Refinements
79+
private import semmle.javascript.internal.CachedStages
7980

8081
/**
8182
* A variable that can be SSA converted, that is, a local variable.
@@ -354,6 +355,7 @@ private module Internal {
354355
*/
355356
cached
356357
SsaDefinition getDefReachingEndOf(ReachableBasicBlock bb, SsaSourceVariable v) {
358+
Stages::DataFlowStage::ref() and
357359
exists(int lastRef | lastRef = max(int i | ssaRef(bb, i, v, _)) |
358360
result = getLocalDefinition(bb, lastRef, v)
359361
or

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private import javascript
7272
private import internal.FlowSteps
7373
private import internal.AccessPaths
7474
private import internal.CallGraphs
75+
private import semmle.javascript.internal.CachedStages
7576

7677
/**
7778
* A data flow tracking configuration for finding inter-procedural paths from
@@ -733,6 +734,7 @@ private class FlowStepThroughImport extends AdditionalFlowStep, DataFlow::ValueN
733734
override ImportSpecifier astNode;
734735

735736
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
737+
Stages::FlowSteps::ref() and
736738
pred = this and
737739
succ = DataFlow::ssaDefinitionNode(SSA::definition(astNode))
738740
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private import internal.FlowSteps as FlowSteps
2424
private import internal.DataFlowNode
2525
private import internal.AnalyzedParameters
2626
private import internal.PreCallGraphStep
27+
private import semmle.javascript.internal.CachedStages
2728

2829
module DataFlow {
2930
/**
@@ -1493,6 +1494,7 @@ module DataFlow {
14931494
*/
14941495
cached
14951496
predicate localFlowStep(Node pred, Node succ) {
1497+
Stages::DataFlowStage::ref() and
14961498
// flow from RHS into LHS
14971499
lvalueFlowStep(pred, succ)
14981500
or

0 commit comments

Comments
 (0)