Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
JS: Avoid bad join ordering in ClosureModule
  • Loading branch information
asgerf committed May 6, 2020
commit 639f04386c9716c422585f9a7678c1d5e46b55e8
23 changes: 17 additions & 6 deletions javascript/ql/src/semmle/javascript/Closure.qll
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,28 @@ module Closure {
override DefaultClosureModuleDeclaration range;
}

private GlobalVariable googVariable() {
variables(result, "goog", any(GlobalScope sc))
}

pragma[nomagic]
private MethodCallExpr googModuleDeclExpr() {
result.getReceiver() = googVariable().getAnAccess() and
result.getMethodName() = ["module", "declareModuleId"]
}

pragma[nomagic]
private MethodCallExpr googModuleDeclExprInContainer(StmtContainer container) {
result.getReceiver() = googModuleDeclExpr() and
container = result.getContainer()
}

/**
* A module using the Closure module system, declared using `goog.module()` or `goog.declareModuleId()`.
*/
class ClosureModule extends Module {
ClosureModule() {
// Use AST-based predicate to cut recursive dependencies.
exists(MethodCallExpr call |
getAStmt().(ExprStmt).getExpr() = call and
call.getReceiver().(GlobalVarAccess).getName() = "goog" and
(call.getMethodName() = "module" or call.getMethodName() = "declareModuleId")
)
exists(googModuleDeclExprInContainer(this))
}

/**
Expand Down