Skip to content

Commit 31aebc7

Browse files
committed
JS: Improve handling of Closure
1 parent bf38400 commit 31aebc7

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

javascript/ql/lib/semmle/javascript/GlobalAccessPaths.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ module AccessPath {
272272
result = decl.getIdentifier().(GlobalVarDecl).getName() and
273273
root.isGlobal()
274274
)
275+
or
276+
exists(Closure::ClosureModule mod |
277+
node = mod.getExportsVariable().getAnAssignedExpr().flow() and
278+
root.isGlobal() and
279+
result = mod.getClosureNamespace()
280+
)
275281
}
276282

277283
/** A module for computing an access to a variable that happens after a property has been written onto it */

javascript/ql/lib/semmle/javascript/dataflow/internal/CallGraphs.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ module CallGraph {
1414
Function getAFunctionValue(AnalyzedNode node) {
1515
result = node.getAValue().(AbstractCallable).getFunction()
1616
or
17-
node = NameResolution::trackFunctionValue(result).toDataFlowNode().(DataFlow::SourceNode)
17+
node = NameResolution::trackFunctionValue(result).toDataFlowNode()
18+
or
19+
exists(DataFlow::Node pred |
20+
AccessPath::step(pred, node) and
21+
result = getAFunctionValue(pred)
22+
)
1823
}
1924

2025
/** Holds if the type inferred for `node` is indefinite due to global flow. */

javascript/ql/lib/semmle/javascript/internal/NameResolution.qll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ module NameResolution {
194194
node2 = req
195195
)
196196
or
197-
exists(Closure::ClosureModule mod |
198-
node1 = mod.getExportsVariable() and
199-
node2 = mod
200-
)
201-
or
202197
exists(ImmediatelyInvokedFunctionExpr fun, int i |
203198
node1 = fun.getArgument(i) and
204199
node2 = fun.getParameter(i)
@@ -319,6 +314,12 @@ module NameResolution {
319314
)
320315
or
321316
result = mod.(Closure::ClosureModule).getExportsVariable().getAnAssignedExpr()
317+
or
318+
exists(ExportDefaultDeclaration exprt |
319+
mod instanceof Closure::ClosureModule and
320+
exprt.getContainer() = mod and
321+
result = exprt.getOperand()
322+
)
322323
}
323324

324325
/** Gets a node that is bulk-exported from the given module. */

0 commit comments

Comments
 (0)