Skip to content

Commit 254af4f

Browse files
committed
JS: Rewrite LodashUnderscore::AnalyzedThisInBoundCallback
1 parent fea5a43 commit 254af4f

File tree

1 file changed

+71
-74
lines changed

1 file changed

+71
-74
lines changed

javascript/ql/src/semmle/javascript/frameworks/LodashUnderscore.qll

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -407,112 +407,109 @@ module LodashUnderscore {
407407
* However, since the function could be invoked in another way, we additionally
408408
* still infer the ordinary abstract value.
409409
*/
410-
private class AnalyzedThisInBoundCallback extends AnalyzedNode, DataFlow::ThisNode {
411-
AnalyzedNode thisSource;
410+
private class LodashCallbackAsPartialInvoke extends DataFlow::PartialInvokeNode::Range,
411+
DataFlow::CallNode {
412+
int callbackIndex;
413+
int contextIndex;
412414

413-
AnalyzedThisInBoundCallback() {
414-
exists(
415-
DataFlow::CallNode bindingCall, string binderName, int callbackIndex, int contextIndex,
416-
int argumentCount
417-
|
418-
bindingCall = LodashUnderscore::member(binderName).getACall() and
419-
bindingCall.getNumArgument() = argumentCount and
420-
getBinder() = bindingCall.getCallback(callbackIndex) and
421-
thisSource = bindingCall.getArgument(contextIndex)
415+
LodashCallbackAsPartialInvoke() {
416+
exists(string name, int argumentCount |
417+
this = LodashUnderscore::member(name).getACall() and
418+
getNumArgument() = argumentCount
422419
|
423420
(
424-
binderName = "bind" or
425-
binderName = "callback" or
426-
binderName = "iteratee"
421+
name = "bind" or
422+
name = "callback" or
423+
name = "iteratee"
427424
) and
428425
callbackIndex = 0 and
429426
contextIndex = 1 and
430427
argumentCount = 2
431428
or
432429
(
433-
binderName = "all" or
434-
binderName = "any" or
435-
binderName = "collect" or
436-
binderName = "countBy" or
437-
binderName = "detect" or
438-
binderName = "dropRightWhile" or
439-
binderName = "dropWhile" or
440-
binderName = "each" or
441-
binderName = "eachRight" or
442-
binderName = "every" or
443-
binderName = "filter" or
444-
binderName = "find" or
445-
binderName = "findIndex" or
446-
binderName = "findKey" or
447-
binderName = "findLast" or
448-
binderName = "findLastIndex" or
449-
binderName = "findLastKey" or
450-
binderName = "forEach" or
451-
binderName = "forEachRight" or
452-
binderName = "forIn" or
453-
binderName = "forInRight" or
454-
binderName = "groupBy" or
455-
binderName = "indexBy" or
456-
binderName = "map" or
457-
binderName = "mapKeys" or
458-
binderName = "mapValues" or
459-
binderName = "max" or
460-
binderName = "min" or
461-
binderName = "omit" or
462-
binderName = "partition" or
463-
binderName = "pick" or
464-
binderName = "reject" or
465-
binderName = "remove" or
466-
binderName = "select" or
467-
binderName = "some" or
468-
binderName = "sortBy" or
469-
binderName = "sum" or
470-
binderName = "takeRightWhile" or
471-
binderName = "takeWhile" or
472-
binderName = "tap" or
473-
binderName = "thru" or
474-
binderName = "times" or
475-
binderName = "unzipWith" or
476-
binderName = "zipWith"
430+
name = "all" or
431+
name = "any" or
432+
name = "collect" or
433+
name = "countBy" or
434+
name = "detect" or
435+
name = "dropRightWhile" or
436+
name = "dropWhile" or
437+
name = "each" or
438+
name = "eachRight" or
439+
name = "every" or
440+
name = "filter" or
441+
name = "find" or
442+
name = "findIndex" or
443+
name = "findKey" or
444+
name = "findLast" or
445+
name = "findLastIndex" or
446+
name = "findLastKey" or
447+
name = "forEach" or
448+
name = "forEachRight" or
449+
name = "forIn" or
450+
name = "forInRight" or
451+
name = "groupBy" or
452+
name = "indexBy" or
453+
name = "map" or
454+
name = "mapKeys" or
455+
name = "mapValues" or
456+
name = "max" or
457+
name = "min" or
458+
name = "omit" or
459+
name = "partition" or
460+
name = "pick" or
461+
name = "reject" or
462+
name = "remove" or
463+
name = "select" or
464+
name = "some" or
465+
name = "sortBy" or
466+
name = "sum" or
467+
name = "takeRightWhile" or
468+
name = "takeWhile" or
469+
name = "tap" or
470+
name = "thru" or
471+
name = "times" or
472+
name = "unzipWith" or
473+
name = "zipWith"
477474
) and
478475
callbackIndex = 1 and
479476
contextIndex = 2 and
480477
argumentCount = 3
481478
or
482479
(
483-
binderName = "foldl" or
484-
binderName = "foldr" or
485-
binderName = "inject" or
486-
binderName = "reduce" or
487-
binderName = "reduceRight" or
488-
binderName = "transform"
480+
name = "foldl" or
481+
name = "foldr" or
482+
name = "inject" or
483+
name = "reduce" or
484+
name = "reduceRight" or
485+
name = "transform"
489486
) and
490487
callbackIndex = 1 and
491488
contextIndex = 3 and
492489
argumentCount = 4
493490
or
494491
(
495-
binderName = "sortedlastIndex"
492+
name = "sortedlastIndex"
496493
or
497-
binderName = "assign"
494+
name = "assign"
498495
or
499-
binderName = "eq"
496+
name = "eq"
500497
or
501-
binderName = "extend"
498+
name = "extend"
502499
or
503-
binderName = "merge"
500+
name = "merge"
504501
or
505-
binderName = "sortedIndex" and
506-
binderName = "uniq"
502+
name = "sortedIndex" and
503+
name = "uniq"
507504
) and
508505
callbackIndex = 2 and
509506
contextIndex = 3 and
510507
argumentCount = 4
511508
)
512509
}
513510

514-
override AbstractValue getALocalValue() {
515-
result = thisSource.getALocalValue() or
516-
result = AnalyzedNode.super.getALocalValue()
511+
override DataFlow::Node getBoundReceiver(DataFlow::Node callback) {
512+
callback = getArgument(callbackIndex) and
513+
result = getArgument(contextIndex)
517514
}
518515
}

0 commit comments

Comments
 (0)