Skip to content

Commit 1be47db

Browse files
committed
JS: Factor out more JS-specific code
1 parent 2d509eb commit 1be47db

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

javascript/ql/lib/semmle/javascript/frameworks/data/internal/ApiGraphModels.qll

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ API::Node getSuccessorFromNode(API::Node node, AccessPathToken token) {
287287
* Gets an API-graph successor for the given invocation.
288288
*/
289289
bindingset[token]
290-
API::Node getSuccessorFromInvoke(API::InvokeNode invoke, AccessPathToken token) {
290+
API::Node getSuccessorFromInvoke(Specific::InvokeNode invoke, AccessPathToken token) {
291291
token.getName() = "Argument" and
292292
(
293293
result = invoke.getParameter(getAnIntFromStringUnbounded(token.getAnArgument()))
@@ -308,7 +308,7 @@ API::Node getSuccessorFromInvoke(API::InvokeNode invoke, AccessPathToken token)
308308
* Holds if `invoke` invokes a call-site filter given by `token`.
309309
*/
310310
pragma[inline]
311-
private predicate invocationMatchesCallSiteFilter(API::InvokeNode invoke, AccessPathToken token) {
311+
private predicate invocationMatchesCallSiteFilter(Specific::InvokeNode invoke, AccessPathToken token) {
312312
token.getName() = "WithArity" and
313313
invoke.getNumArgument() = getAnIntFromStringUnbounded(token.getAnArgument())
314314
or
@@ -322,10 +322,6 @@ pragma[nomagic]
322322
API::Node getNodeFromPath(string package, string type, AccessPath path, int n) {
323323
isRelevantFullPath(package, type, path) and
324324
(
325-
type = "" and
326-
n = 0 and
327-
result = API::moduleImport(package)
328-
or
329325
n = 0 and
330326
exists(string package2, string type2, AccessPath path2 |
331327
typeModel(package, type, package2, type2, path2) and
@@ -353,15 +349,15 @@ API::Node getNodeFromPath(string package, string type, AccessPath path) {
353349
*
354350
* Unlike `getNodeFromPath`, the `path` may end with one or more call-site filters.
355351
*/
356-
API::InvokeNode getInvocationFromPath(string package, string type, AccessPath path, int n) {
357-
result = getNodeFromPath(package, type, path, n).getAnInvocation()
352+
Specific::InvokeNode getInvocationFromPath(string package, string type, AccessPath path, int n) {
353+
result = Specific::getAnInvocationOf(getNodeFromPath(package, type, path, n))
358354
or
359355
result = getInvocationFromPath(package, type, path, n - 1) and
360356
invocationMatchesCallSiteFilter(result, path.getToken(n - 1))
361357
}
362358

363359
/** Gets an invocation identified by the given `(package, type, path)` tuple. */
364-
API::InvokeNode getInvocationFromPath(string package, string type, AccessPath path) {
360+
Specific::InvokeNode getInvocationFromPath(string package, string type, AccessPath path) {
365361
result = getInvocationFromPath(package, type, path, path.getNumToken())
366362
}
367363

@@ -472,12 +468,22 @@ module ModelOutput {
472468
)
473469
}
474470

471+
/**
472+
* Holds if a relevant CSV summary row has the given `kind`, `input` and `output`.
473+
*/
474+
predicate summaryModel(string input, string output, string kind) {
475+
exists(string package |
476+
isRelevantPackage(package) and
477+
summaryModel(package, _, _, input, output, kind)
478+
)
479+
}
480+
475481
/**
476482
* Holds if a summary edge with the given `input, output, kind` columns have a `package, type, path` tuple
477483
* that resolves to `baseNode`.
478484
*/
479485
predicate resolvedSummaryBase(
480-
API::InvokeNode baseNode, AccessPath input, AccessPath output, string kind
486+
Specific::InvokeNode baseNode, AccessPath input, AccessPath output, string kind
481487
) {
482488
exists(string package, string type, AccessPath path |
483489
summaryModel(package, type, path, input, output, kind) and

javascript/ql/lib/semmle/javascript/frameworks/data/internal/ApiGraphModelsSpecific.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ private API::Node getGlobalNode(string globalName) {
7272
/** Gets a JavaScript-specific interpretation of the `(package, type, path)` tuple after resolving the first `n` access path tokens. */
7373
bindingset[package, type, path]
7474
API::Node getExtraNodeFromPath(string package, string type, AccessPath path, int n) {
75+
type = "" and
76+
n = 0 and
77+
result = API::moduleImport(package)
78+
or
7579
// Global variable accesses is via the 'global' package
7680
exists(AccessPathToken token |
7781
package = getAPackageAlias("global") and
@@ -180,3 +184,8 @@ predicate summaryStep(API::Node pred, API::Node succ, string kind) {
180184
succ = getNodeFromInputOutputPath(base, output)
181185
)
182186
}
187+
188+
class InvokeNode = API::InvokeNode;
189+
190+
/** Gets an `InvokeNode` corresponding to an invocation of `node`. */
191+
InvokeNode getAnInvocationOf(API::Node node) { result = node.getAnInvocation() }

0 commit comments

Comments
 (0)