Skip to content

Commit 74171d1

Browse files
owen-mcCopilot
andcommitted
JS: Fix implicit this flow for arrow super expressions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d068360 commit 74171d1

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,7 @@ module DataFlow {
17671767
exists(ImplicitThisUse use |
17681768
(
17691769
LocalVariableOrThis::thisInContainer(use.getBindingContainer()).isCaptured() or
1770+
use.getBindingContainer() != use.getUseContainer() or
17701771
not use.(ControlFlowNode).getBasicBlock() instanceof ReachableBasicBlock
17711772
) and
17721773
pred = TThisNode(use.getBindingContainer()) and

‎javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib/Ssa.qll‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ private predicate refinementAt(js::Cfg::BasicBlock bb, int i, SsaConfig::SourceV
6868
private predicate explicitVariableRead(js::ControlFlowNode read, SsaConfig::SourceVariable v) {
6969
read.(js::VarUse).getVariable() = v.asLocalVariable()
7070
or
71-
read.(ThisUse).getBindingContainer() = v.asThisContainer()
71+
exists(ThisUse use, js::StmtContainer container |
72+
use = read and
73+
container = v.asThisContainer() and
74+
use.getBindingContainer() = container and
75+
use.getUseContainer() = container
76+
)
7277
}
7378

7479
/** Gets an operation that may update the object evaluated at `read`. */
@@ -143,7 +148,8 @@ private predicate uncapturedExplicitRead(
143148
)
144149
or
145150
not v.isCaptured() and
146-
read.(ThisUse).getBindingContainer() = v.asThisContainer() and
151+
exists(v.asThisContainer()) and
152+
explicitVariableRead(read, v) and
147153
read = readBlock.getNode(readIndex)
148154
)
149155
}

‎javascript/ql/test/library-tests/SharedSsaCompatibility/captured.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,21 @@ function legacyGuardedWithReads(condition) {
112112
}
113113
SINK(value);
114114
}
115+
116+
class ArrowSuperBase {
117+
constructor() {
118+
SINK(this); // $ capturedFlow=arrow-super
119+
}
120+
}
121+
122+
class ArrowSuperDerived extends ArrowSuperBase {
123+
constructor() {
124+
const init = () => super();
125+
init();
126+
}
127+
128+
readSuperInArrow() {
129+
return () => super.toString();
130+
}
131+
}
132+
ArrowSuperDerived.call(SOURCE("arrow-super"));

0 commit comments

Comments
 (0)