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

Skip to content

Commit 6534219

Browse files
committed
JS: Move AdditionalPartialInvokeNode to Nodes.qll
1 parent 15f0e85 commit 6534219

2 files changed

Lines changed: 57 additions & 51 deletions

File tree

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

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,6 @@ abstract class AdditionalSink extends DataFlow::Node {
432432
predicate isSinkFor(Configuration cfg, FlowLabel lbl) { none() }
433433
}
434434

435-
/**
436-
* An invocation that is modeled as a partial function application.
437-
*
438-
* This contributes additional argument-passing flow edges that should be added to all data flow configurations.
439-
*/
440-
abstract class AdditionalPartialInvokeNode extends DataFlow::InvokeNode {
441-
/**
442-
* Holds if `argument` is passed as argument `index` to the function in `callback`.
443-
*/
444-
abstract predicate isPartialArgument(DataFlow::Node callback, DataFlow::Node argument, int index);
445-
}
446-
447435
/**
448436
* Additional flow step to model flow from import specifiers into the SSA variable
449437
* corresponding to the imported variable.
@@ -457,45 +445,6 @@ private class FlowStepThroughImport extends AdditionalFlowStep, DataFlow::ValueN
457445
}
458446
}
459447

460-
/**
461-
* A partial call through the built-in `Function.prototype.bind`.
462-
*/
463-
private class BindPartialCall extends AdditionalPartialInvokeNode, DataFlow::MethodCallNode {
464-
BindPartialCall() { getMethodName() = "bind" }
465-
466-
override predicate isPartialArgument(DataFlow::Node callback, DataFlow::Node argument, int index) {
467-
callback = getReceiver() and
468-
argument = getArgument(index + 1)
469-
}
470-
}
471-
472-
/**
473-
* A partial call through `_.partial`.
474-
*/
475-
private class LodashPartialCall extends AdditionalPartialInvokeNode {
476-
LodashPartialCall() { this = LodashUnderscore::member("partial").getACall() }
477-
478-
override predicate isPartialArgument(DataFlow::Node callback, DataFlow::Node argument, int index) {
479-
callback = getArgument(0) and
480-
argument = getArgument(index + 1)
481-
}
482-
}
483-
484-
/**
485-
* A partial call through `ramda.partial`.
486-
*/
487-
private class RamdaPartialCall extends AdditionalPartialInvokeNode {
488-
RamdaPartialCall() { this = DataFlow::moduleMember("ramda", "partial").getACall() }
489-
490-
override predicate isPartialArgument(DataFlow::Node callback, DataFlow::Node argument, int index) {
491-
callback = getArgument(0) and
492-
exists(DataFlow::ArrayCreationNode array |
493-
array.flowsTo(getArgument(1)) and
494-
argument = array.getElement(index)
495-
)
496-
}
497-
}
498-
499448
/**
500449
* Holds if there is a flow step from `pred` to `succ` described by `summary`
501450
* under configuration `cfg`.

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,3 +964,60 @@ module ClassNode {
964964
}
965965
}
966966
}
967+
968+
/**
969+
* An invocation that is modeled as a partial function application.
970+
*
971+
* This contributes additional argument-passing flow edges that should be added to all data flow configurations.
972+
*/
973+
abstract class AdditionalPartialInvokeNode extends DataFlow::InvokeNode {
974+
/**
975+
* Holds if `argument` is passed as argument `index` to the function in `callback`.
976+
*/
977+
abstract predicate isPartialArgument(DataFlow::Node callback, DataFlow::Node argument, int index);
978+
979+
/** Gets the data flow node referring to the bound function, if such a node exists. */
980+
DataFlow::SourceNode getBoundFunction(int boundArgs) { none() }
981+
}
982+
983+
/**
984+
* A partial call through the built-in `Function.prototype.bind`.
985+
*/
986+
private class BindPartialCall extends AdditionalPartialInvokeNode, DataFlow::MethodCallNode {
987+
BindPartialCall() { getMethodName() = "bind" }
988+
989+
override predicate isPartialArgument(DataFlow::Node callback, DataFlow::Node argument, int index) {
990+
index >= 0 and
991+
callback = getReceiver() and
992+
argument = getArgument(index + 1)
993+
}
994+
}
995+
996+
/**
997+
* A partial call through `_.partial`.
998+
*/
999+
private class LodashPartialCall extends AdditionalPartialInvokeNode {
1000+
LodashPartialCall() { this = LodashUnderscore::member("partial").getACall() }
1001+
1002+
override predicate isPartialArgument(DataFlow::Node callback, DataFlow::Node argument, int index) {
1003+
index >= 0 and
1004+
callback = getArgument(0) and
1005+
argument = getArgument(index + 1)
1006+
}
1007+
}
1008+
1009+
/**
1010+
* A partial call through `ramda.partial`.
1011+
*/
1012+
private class RamdaPartialCall extends AdditionalPartialInvokeNode {
1013+
RamdaPartialCall() { this = DataFlow::moduleMember("ramda", "partial").getACall() }
1014+
1015+
private DataFlow::ArrayCreationNode getArgumentsArray() {
1016+
result.flowsTo(getArgument(1))
1017+
}
1018+
1019+
override predicate isPartialArgument(DataFlow::Node callback, DataFlow::Node argument, int index) {
1020+
callback = getArgument(0) and
1021+
argument = getArgumentsArray().getElement(index)
1022+
}
1023+
}

0 commit comments

Comments
 (0)