Skip to content

Commit e629e6b

Browse files
committed
changes based on review
1 parent 8131618 commit e629e6b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

javascript/ql/src/Declarations/DeadStoreOfProperty.ql

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ predicate isDeadAssignment(string name, DataFlow::PropWrite assign1, DataFlow::P
9797
}
9898

9999
/**
100-
* Holds if `assign` assigns a property `name` that may be accessed somewhere else in the same block,
100+
* Holds if `assign` assigns a property that may be accessed somewhere else in the same block,
101101
* `after` indicates if the access happens before or after the node for `assign`.
102102
*/
103-
predicate maybeAccessesAssignedPropInBlock(DataFlow::PropWrite assign, boolean after) {
103+
predicate maybeAssignsAccessedPropInBlock(DataFlow::PropWrite assign, boolean after) {
104104
(
105105
// early pruning - manual magic
106106
after = true and postDominatedPropWrite(_, assign, _, false)
@@ -176,11 +176,13 @@ ControlFlowNode getANodeBeforeWrite(DataFlow::PropWrite write, ReachableBasicBlo
176176
}
177177

178178
/**
179-
* Gets a successor inside `bb` in the control-flow graph that does not pass through an impure expression (except for writes to `name`).
180-
* Stops after the first write to `name` that happens after `node`.
179+
* Gets a successor inside `bb` in the control-flow graph that does not pass through an impure expression (except for writes to the same property).
180+
* Stops after the first write to same property that happens after `node`.
181+
*
182+
* `node` always corresponds to the CFG node of a `DataFlow::PropWrite` with a known name.
181183
*/
182184
ControlFlowNode getAPureSuccessor(ControlFlowNode node) {
183-
// stop at impure expressions (except writes to `name`)
185+
// stop at reads of `name` and at impure expressions (except writes to `name`)
184186
not (
185187
maybeAccessesProperty(result, getPropertyWriteName(node)) and
186188
not result =
@@ -197,10 +199,10 @@ ControlFlowNode getAPureSuccessor(ControlFlowNode node) {
197199
)
198200
or
199201
// recursive case
200-
exists(ControlFlowNode pred | pred = getAPureSuccessor(node) | result = pred.getASuccessor()) and
202+
result = getAPureSuccessor(node).getASuccessor() and
201203
// stop at basic-block boundaries
202204
not result instanceof BasicBlock and
203-
// make sure we stop after the first write to `name` that comes after `node`.
205+
// make sure we stop after the first write to the same property that comes after `node`.
204206
(
205207
not result.getAPredecessor() =
206208
any(DataFlow::PropWrite write | write.getPropertyName() = getPropertyWriteName(node))
@@ -250,9 +252,9 @@ predicate noPropAccessBetweenGlobal(
250252
|
251253
postDominatedPropWrite(name, assign1, assign2, false) and // early pruning
252254
write1 = assign1.getWriteNode() and
253-
not maybeAccessesAssignedPropInBlock(assign1, true) and
255+
not maybeAssignsAccessedPropInBlock(assign1, true) and
254256
write2 = assign2.getWriteNode() and
255-
not maybeAccessesAssignedPropInBlock(assign2, false) and
257+
not maybeAssignsAccessedPropInBlock(assign2, false) and
256258
write1.getBasicBlock() = block1 and
257259
write2.getBasicBlock() = block2 and
258260
not block1 = block2 and

javascript/ql/test/query-tests/Declarations/DeadStoreOfProperty/tst.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
o.defaulted2 = 42;
9393

9494
var o = {};
95-
o.pure18 = 42; // NOT OK TODO: Currently have duplicate result.
95+
o.pure18 = 42; // NOT OK
9696
o.pure18 = 42; // NOT OK
9797
o.pure18 = 42;
9898

0 commit comments

Comments
 (0)