Skip to content

Commit 99bd6f1

Browse files
authored
Merge pull request #10234 from asgerf/js/def-nodes-for-class-members
JS: Make API graph more sparse for escaping class instance members
2 parents f846c26 + 32c8688 commit 99bd6f1

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,14 @@ module API {
663663
or
664664
any(Type t).hasUnderlyingType(m, _)
665665
} or
666-
MkClassInstance(DataFlow::ClassNode cls) { cls = trackDefNode(_) and hasSemantics(cls) } or
666+
MkClassInstance(DataFlow::ClassNode cls) {
667+
hasSemantics(cls) and
668+
(
669+
cls = trackDefNode(_)
670+
or
671+
cls.getAnInstanceReference() = trackDefNode(_)
672+
)
673+
} or
667674
MkAsyncFuncResult(DataFlow::FunctionNode f) {
668675
f = trackDefNode(_) and f.getFunction().isAsync() and hasSemantics(f)
669676
} or
@@ -755,16 +762,6 @@ module API {
755762
.getStaticMember(name, DataFlow::MemberKind::getter())
756763
.getAReturn()
757764
)
758-
or
759-
// If `new C()` escapes, generate edges to its instance members
760-
exists(DataFlow::ClassNode cls, string name |
761-
pred = cls.getAClassReference().getAnInstantiation() and
762-
lbl = Label::member(name)
763-
|
764-
rhs = cls.getInstanceMethod(name)
765-
or
766-
rhs = cls.getInstanceMember(name, DataFlow::MemberKind::getter()).getAReturn()
767-
)
768765
)
769766
or
770767
exists(DataFlow::ClassNode cls, string name |
@@ -1253,9 +1250,13 @@ module API {
12531250
succ = MkUse(ref)
12541251
)
12551252
or
1256-
exists(DataFlow::Node rhs |
1257-
rhs(pred, lbl, rhs) and
1253+
exists(DataFlow::Node rhs | rhs(pred, lbl, rhs) |
12581254
succ = MkDef(rhs)
1255+
or
1256+
exists(DataFlow::ClassNode cls |
1257+
cls.getAnInstanceReference() = rhs and
1258+
succ = MkClassInstance(cls)
1259+
)
12591260
)
12601261
or
12611262
exists(DataFlow::Node def |

0 commit comments

Comments
 (0)