Skip to content

Commit a476fc5

Browse files
committed
revert Array.from change
1 parent 68ffd52 commit a476fc5

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

javascript/ql/src/semmle/javascript/dataflow/Nodes.qll

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -598,23 +598,18 @@ class ArrayConstructorInvokeNode extends DataFlow::InvokeNode {
598598
* new Array('apple', 'orange')
599599
* Array(16)
600600
* new Array(16)
601-
* Array.from(1,2,3);
602601
* ```
603602
*/
604603
class ArrayCreationNode extends DataFlow::ValueNode, DataFlow::SourceNode {
605604
ArrayCreationNode() {
606605
this instanceof ArrayLiteralNode or
607-
this instanceof ArrayConstructorInvokeNode or
608-
this = DataFlow::globalVarRef("Array").getAPropertyRead("from").getACall()
606+
this instanceof ArrayConstructorInvokeNode
609607
}
610608

611609
/** Gets the `i`th initial element of this array, if one is provided. */
612610
DataFlow::ValueNode getElement(int i) {
613611
result = this.(ArrayLiteralNode).getElement(i) or
614-
result = this.(ArrayConstructorInvokeNode).getElement(i) or
615-
exists(DataFlow::CallNode call | call.getCalleeName() = "from" and call = this |
616-
result = call.getArgument(i)
617-
)
612+
result = this.(ArrayConstructorInvokeNode).getElement(i)
618613
}
619614

620615
/** Gets an initial element of this array, if one if provided. */
@@ -623,10 +618,7 @@ class ArrayCreationNode extends DataFlow::ValueNode, DataFlow::SourceNode {
623618
/** Gets the initial size of the created array, if it can be determined. */
624619
int getSize() {
625620
result = this.(ArrayLiteralNode).getSize() or
626-
result = this.(ArrayConstructorInvokeNode).getSize() or
627-
exists(DataFlow::CallNode call | call.getCalleeName() = "from" and call = this |
628-
result = call.getNumArgument()
629-
)
621+
result = this.(ArrayConstructorInvokeNode).getSize()
630622
}
631623
}
632624

javascript/ql/test/library-tests/Arrays/DataFlow.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
| arrays.js:2:16:2:23 | "source" | arrays.js:16:23:16:23 | e |
55
| arrays.js:2:16:2:23 | "source" | arrays.js:20:8:20:16 | arr.pop() |
66
| arrays.js:18:22:18:29 | "source" | arrays.js:18:50:18:50 | e |
7-
| arrays.js:22:25:22:32 | "source" | arrays.js:23:8:23:17 | arr2.pop() |
7+
| arrays.js:22:15:22:22 | "source" | arrays.js:23:8:23:17 | arr2.pop() |
88
| arrays.js:25:15:25:22 | "source" | arrays.js:26:8:26:17 | arr3.pop() |
99
| arrays.js:29:21:29:28 | "source" | arrays.js:30:8:30:17 | arr4.pop() |
1010
| arrays.js:29:21:29:28 | "source" | arrays.js:33:8:33:17 | arr5.pop() |
1111
| arrays.js:29:21:29:28 | "source" | arrays.js:35:8:35:26 | arr5.slice(2).pop() |
1212
| arrays.js:29:21:29:28 | "source" | arrays.js:41:8:41:17 | arr6.pop() |
13-
| arrays.js:44:14:44:21 | "source" | arrays.js:45:10:45:18 | ary.pop() |
13+
| arrays.js:44:4:44:11 | "source" | arrays.js:45:10:45:18 | ary.pop() |

javascript/ql/test/library-tests/Arrays/arrays.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
sink(arr.pop()); // NOT OK
2121

22-
var arr2 = Array.from("source");
22+
var arr2 = ["source"];
2323
sink(arr2.pop()); // NOT OK
2424

2525
var arr3 = ["source"];
@@ -41,7 +41,7 @@
4141
sink(arr6.pop()); // NOT OK
4242

4343

44-
Array.from("source").forEach((e, i, ary) => {
44+
["source"].forEach((e, i, ary) => {
4545
sink(ary.pop()); // NOT OK
4646
sink(ary); // OK - its the array itself, not an element.
4747
})

0 commit comments

Comments
 (0)