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

Skip to content

Commit 1c815f1

Browse files
committed
JS: ArrayCopySpread
1 parent 151420f commit 1c815f1

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,21 @@ private module ArrayDataFlow {
104104
*
105105
* Such a step can occur both with the `push` and `unshift` methods, or when creating a new array.
106106
*/
107-
private class ArrayCopySpread extends DataFlow::AdditionalFlowStep {
108-
DataFlow::Node spreadArgument; // the spread argument containing the elements to be copied.
109-
DataFlow::Node base; // the object where the elements should be copied to.
110-
111-
ArrayCopySpread() {
112-
exists(DataFlow::MethodCallNode mcn | mcn = this |
113-
mcn.getMethodName() = ["push", "unshift"] and
114-
spreadArgument = mcn.getASpreadArgument() and
115-
base = mcn.getReceiver().getALocalSource()
116-
)
117-
or
118-
spreadArgument = this.(DataFlow::ArrayCreationNode).getASpreadArgument() and
119-
base = this
120-
}
121-
107+
private class ArrayCopySpread extends DataFlow::SharedFlowStep {
122108
override predicate loadStoreStep(
123109
DataFlow::Node pred, DataFlow::Node succ, string fromProp, string toProp
124110
) {
125-
pred = spreadArgument and
126-
succ = base and
127111
fromProp = arrayLikeElement() and
128-
toProp = arrayElement()
112+
toProp = arrayElement() and
113+
(
114+
exists(DataFlow::MethodCallNode mcn |
115+
mcn.getMethodName() = ["push", "unshift"] and
116+
pred = mcn.getASpreadArgument() and
117+
succ = mcn.getReceiver().getALocalSource()
118+
)
119+
or
120+
pred = succ.(DataFlow::ArrayCreationNode).getASpreadArgument()
121+
)
129122
}
130123
}
131124

0 commit comments

Comments
 (0)