Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9c9946

Browse files
committed
JS: ForOfStep (unify with Arrays version)
1 parent 1a5eede commit c9c9946

2 files changed

Lines changed: 19 additions & 37 deletions

File tree

javascript/ql/src/semmle/javascript/Arrays.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,4 @@ private module ArrayDataFlow {
289289
)
290290
}
291291
}
292-
293-
/**
294-
* A step for modelling `for of` iteration on arrays.
295-
*/
296-
private class ForOfStep extends PreCallGraphStep {
297-
override predicate loadStep(DataFlow::Node obj, DataFlow::Node e, string prop) {
298-
exists(ForOfStmt forOf |
299-
obj = forOf.getIterationDomain().flow() and
300-
e = DataFlow::lvalueNode(forOf.getLValue()) and
301-
prop = arrayElement()
302-
)
303-
}
304-
}
305292
}

javascript/ql/src/semmle/javascript/Collections.qll

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -152,34 +152,29 @@ private module CollectionDataFlow {
152152
}
153153

154154
/**
155-
* A step for a `for of` statement on a Map, Set, or Iterator.
156-
* For Sets and iterators the l-value are the elements of the set/iterator.
157-
* For Maps the l-value is a tuple containing a key and a value.
155+
* A step for modelling `for of` iteration on arrays, maps, sets, and iterators.
156+
*
157+
* For sets and iterators the l-value are the elements of the set/iterator.
158+
* For maps the l-value is a tuple containing a key and a value.
158159
*/
159-
// This is partially duplicated behavior with the `for of` step for Arrays (`ArrayDataFlow::ForOfStep`).
160-
// This duplication is required for the type-tracking steps defined in `CollectionsTypeTracking`.
161-
private class ForOfStep extends CollectionFlowStep, DataFlow::ValueNode {
162-
ForOfStmt forOf;
163-
DataFlow::Node element;
164-
165-
ForOfStep() {
166-
this.asExpr() = forOf.getIterationDomain() and
167-
element = DataFlow::lvalueNode(forOf.getLValue())
168-
}
169-
170-
override predicate load(DataFlow::Node obj, DataFlow::Node e, PseudoProperty prop) {
171-
obj = this and
172-
e = element and
173-
prop = arrayLikeElement()
160+
private class ForOfStep extends PreCallGraphStep {
161+
override predicate loadStep(DataFlow::Node obj, DataFlow::Node e, string prop) {
162+
exists(ForOfStmt forOf |
163+
obj = forOf.getIterationDomain().flow() and
164+
e = DataFlow::lvalueNode(forOf.getLValue()) and
165+
prop = arrayLikeElement()
166+
)
174167
}
175168

176-
override predicate loadStore(
177-
DataFlow::Node pred, DataFlow::Node succ, PseudoProperty fromProp, PseudoProperty toProp
169+
override predicate loadStoreStep(
170+
DataFlow::Node pred, DataFlow::SourceNode succ, string fromProp, string toProp
178171
) {
179-
pred = this and
180-
succ = element and
181-
fromProp = mapValueAll() and
182-
toProp = "1"
172+
exists(ForOfStmt forOf |
173+
pred = forOf.getIterationDomain().flow() and
174+
succ = DataFlow::lvalueNode(forOf.getLValue()) and
175+
fromProp = mapValueAll() and
176+
toProp = "1"
177+
)
183178
}
184179
}
185180

0 commit comments

Comments
 (0)