Skip to content

Commit 4bd0f34

Browse files
committed
JS: Add debug tools for detecting lost nodes/edges
1 parent c9d3f06 commit 4bd0f34

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

javascript/ql/lib/semmle/javascript/ApiGraphs.qll

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ module API {
819819
* Holds if `rhs` is the right-hand side of a definition of a node that should have an
820820
* incoming edge from `base` labeled `lbl` in the API graph.
821821
*/
822-
private predicate rhs(TApiNode base, Label::ApiLabel lbl, DataFlow::Node rhs) {
822+
predicate rhs(TApiNode base, Label::ApiLabel lbl, DataFlow::Node rhs) {
823823
hasSemantics(rhs) and
824824
(
825825
base = MkRoot() and
@@ -1058,7 +1058,7 @@ module API {
10581058
* Holds if `ref` is a use of a node that should have an incoming edge from `base` labeled
10591059
* `lbl` in the API graph.
10601060
*/
1061-
private predicate use(TApiNode base, Label::ApiLabel lbl, DataFlow::Node ref) {
1061+
predicate use(TApiNode base, Label::ApiLabel lbl, DataFlow::Node ref) {
10621062
hasSemantics(ref) and
10631063
(
10641064
base = MkRoot() and
@@ -1706,6 +1706,43 @@ module API {
17061706

17071707
import Cached
17081708

1709+
private module Debug {
1710+
private module FullInput implements StageInputSig {
1711+
pragma[inline]
1712+
predicate isAdditionalUseRoot(Node node) { none() }
1713+
1714+
pragma[inline]
1715+
predicate isAdditionalDefRoot(Node node) { none() }
1716+
1717+
bindingset[node]
1718+
predicate inScope(DataFlow::Node node) { any() }
1719+
}
1720+
1721+
private module Full = Stage<FullInput>;
1722+
1723+
query predicate missingDefNode(DataFlow::Node node) {
1724+
Full::rhs(_, _, node) and
1725+
not exists(MkDef(node))
1726+
}
1727+
1728+
query predicate missingUseNode(DataFlow::Node node) {
1729+
Full::use(_, _, node) and
1730+
not exists(MkUse(node))
1731+
}
1732+
1733+
query predicate lostEdge(Node pred, Label::ApiLabel lbl, Node succ) {
1734+
Full::edge(pred, lbl, succ) and
1735+
not Cached::edge(pred, lbl, succ)
1736+
}
1737+
1738+
query predicate counts(int numEdges, int numOverlayEdges, float ratio) {
1739+
numEdges = count(Node pred, Label::ApiLabel lbl, Node succ | Full::edge(pred, lbl, succ)) and
1740+
numOverlayEdges =
1741+
count(Node pred, Label::ApiLabel lbl, Node succ | Stage2::edge(pred, lbl, succ)) and
1742+
ratio = numOverlayEdges / numEdges.(float)
1743+
}
1744+
}
1745+
17091746
/**
17101747
* Holds if there is an edge from `pred` to `succ` in the API graph.
17111748
*/

0 commit comments

Comments
 (0)