Skip to content

Commit 81b96a8

Browse files
committed
JS: Ensure MkClassInstance exists for base classes
1 parent 29a6145 commit 81b96a8

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,7 @@ module API {
696696
or
697697
any(Type t).hasUnderlyingType(m, _)
698698
} or
699-
MkClassInstance(DataFlow::ClassNode cls) {
700-
hasSemantics(cls) and
701-
(
702-
cls = trackDefNode(_)
703-
or
704-
cls.getAnInstanceReference() = trackDefNode(_)
705-
)
706-
} or
699+
MkClassInstance(DataFlow::ClassNode cls) { needsDefNode(cls) } or
707700
MkDef(DataFlow::Node nd) { rhs(_, _, nd) } or
708701
MkUse(DataFlow::Node nd) { use(_, _, nd) } or
709702
/** A use of a TypeScript type. */
@@ -716,6 +709,17 @@ module API {
716709
trackUseNode(src, true, bound, "").flowsTo(nd.getCalleeNode())
717710
}
718711

712+
private predicate needsDefNode(DataFlow::ClassNode cls) {
713+
hasSemantics(cls) and
714+
(
715+
cls = trackDefNode(_)
716+
or
717+
cls.getAnInstanceReference() = trackDefNode(_)
718+
or
719+
needsDefNode(cls.getADirectSubClass())
720+
)
721+
}
722+
719723
class TDef = MkModuleDef or TNonModuleDef;
720724

721725
class TNonModuleDef = MkModuleExport or MkClassInstance or MkDef or MkSyntheticCallbackArg;

javascript/ql/test/library-tests/ModelGeneration/ModelGeneration.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typeModel
3737
| (subclass).A | subclass | Member[A] |
3838
| (subclass).A.prototype | (subclass).A | Instance |
3939
| (subclass).A.prototype | (subclass).B.prototype | |
40+
| (subclass).A.prototype | (subclass).ExposedMidSubClass.prototype~expr1 | |
4041
| (subclass).A.prototype.a | (subclass).A.prototype | Member[a] |
4142
| (subclass).B | subclass | Member[B] |
4243
| (subclass).B.prototype | (subclass).B | Instance |
@@ -51,6 +52,7 @@ typeModel
5152
| (subclass).ExposedMidSubClass | subclass | Member[ExposedMidSubClass] |
5253
| (subclass).ExposedMidSubClass.prototype | (subclass).ExposedMidSubClass | Instance |
5354
| (subclass).ExposedMidSubClass.prototype.m | (subclass).ExposedMidSubClass.prototype | Member[m] |
55+
| (subclass).ExposedMidSubClass.prototype~expr1 | (subclass).ExposedMidSubClass.prototype | |
5456
| upstream-lib | (reexport).func | ReturnValue |
5557
| upstream-lib | reexport | Member[lib] |
5658
| upstream-lib.Type | (subclass).D.prototype | |

javascript/ql/test/library-tests/ModelGeneration/subclass/subclass.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export class D extends upstream.Type {
1717
}
1818

1919
// Test case where subclass chain goes through an internal class
20-
// TODO: we miss the subclass chain between ExposedMidSubClass and A
2120
class InternalMidClass extends A {}
2221

2322
export class ExposedMidSubClass extends InternalMidClass {

0 commit comments

Comments
 (0)