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

Skip to content

Commit 6c7d745

Browse files
committed
JS: Add nodes for static/dynamic argument/parameter arrays
1 parent 5d77c33 commit 6c7d745

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ private module Cached {
3333
} or
3434
TThisNode(StmtContainer f) { f.(Function).getThisBinder() = f or f instanceof TopLevel } or
3535
TFunctionSelfReferenceNode(Function f) or
36+
TStaticArgumentArrayNode(InvokeExpr node) or
37+
TDynamicArgumentArrayNode(InvokeExpr node) { node.isSpreadArgument(_) } or
38+
TStaticParameterArrayNode(Function f) {
39+
f.getAParameter().isRestParameter() or f.usesArgumentsObject()
40+
} or
41+
TDynamicParameterArrayNode(Function f) or
3642
TDestructuredModuleImportNode(ImportDeclaration decl) {
3743
exists(decl.getASpecifier().getImportedName())
3844
} or

javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowPrivate.qll

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,73 @@ class GenericSynthesizedNode extends DataFlow::Node, TGenericSynthesizedNode {
8181
string getTag() { result = tag }
8282
}
8383

84+
/**
85+
* An argument containing an array of all positional arguments with an obvious index, i.e. not affected by a spread argument.
86+
*/
87+
class StaticArgumentArrayNode extends DataFlow::Node, TStaticArgumentArrayNode {
88+
private InvokeExpr invoke;
89+
90+
StaticArgumentArrayNode() { this = TStaticArgumentArrayNode(invoke) }
91+
92+
override StmtContainer getContainer() { result = invoke.getContainer() }
93+
94+
override string toString() { result = "[static argument array]" }
95+
96+
override Location getLocation() { result = invoke.getLocation() }
97+
}
98+
99+
/**
100+
* An argument containing an array of all positional arguments with non-obvious index, i.e. affected by a spread argument.
101+
*
102+
* Only exists for call sites with a spread argument.
103+
*/
104+
class DynamicArgumentArrayNode extends DataFlow::Node, TDynamicArgumentArrayNode {
105+
private InvokeExpr invoke;
106+
107+
DynamicArgumentArrayNode() { this = TDynamicArgumentArrayNode(invoke) }
108+
109+
override StmtContainer getContainer() { result = invoke.getContainer() }
110+
111+
override string toString() { result = "[dynamic argument array]" }
112+
113+
override Location getLocation() { result = invoke.getLocation() }
114+
}
115+
116+
/**
117+
* A parameter containing an array of all positional arguments with an obvious index, i.e. not affected by spread or `.apply()`.
118+
*
119+
* These are read and stored in the function's rest parameter and `arguments` array.
120+
* The node only exists for functions with a rest parameter or which uses the `arguments` array.
121+
*/
122+
class StaticParameterArrayNode extends DataFlow::Node, TStaticParameterArrayNode {
123+
private Function function;
124+
125+
StaticParameterArrayNode() { this = TStaticParameterArrayNode(function) }
126+
127+
override StmtContainer getContainer() { result = function }
128+
129+
override string toString() { result = "[static parameter array]" }
130+
131+
override Location getLocation() { result = function.getLocation() }
132+
}
133+
134+
/**
135+
* A parameter containing an array of all positional argument values with non-obvious index, i.e. affected by spread or `.apply()`.
136+
*
137+
* These are read and assigned into regular positional parameters and stored into rest parameters and the `arguments` array.
138+
*/
139+
class DynamicParameterArrayNode extends DataFlow::Node, TDynamicParameterArrayNode {
140+
private Function function;
141+
142+
DynamicParameterArrayNode() { this = TDynamicParameterArrayNode(function) }
143+
144+
override StmtContainer getContainer() { result = function }
145+
146+
override string toString() { result = "[dynamic parameter array]" }
147+
148+
override Location getLocation() { result = function.getLocation() }
149+
}
150+
84151
cached
85152
newtype TReturnKind =
86153
MkNormalReturnKind() or

0 commit comments

Comments
 (0)