Skip to content

Commit 2c43d1d

Browse files
committed
fix FP in superfluous-trailing-arguments related to Function.arguments
1 parent 888c504 commit 2c43d1d

File tree

2 files changed

+17
-1
lines changed
  • javascript/ql

2 files changed

+17
-1
lines changed

javascript/ql/src/semmle/javascript/Functions.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
117117
ArgumentsVariable getArgumentsVariable() { result.getFunction() = this }
118118

119119
/** Holds if the body of this function refers to the function's `arguments` variable. */
120-
predicate usesArgumentsObject() { exists(getArgumentsVariable().getAnAccess()) }
120+
predicate usesArgumentsObject() {
121+
exists(getArgumentsVariable().getAnAccess()) or
122+
exists(PropAccess read |
123+
read.getBase() = getVariable().getAnAccess() and
124+
read.getPropertyName() = "arguments"
125+
)
126+
}
121127

122128
/**
123129
* Holds if this function declares a parameter or local variable named `arguments`.

javascript/ql/test/query-tests/LanguageFeatures/SpuriousArguments/tst.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,13 @@ parseFloat("123", 10);
120120
throwerWithParam(42, 87); // NOT OK
121121
throwerIndirect(42); // OK, but still flagged due to complexity
122122
});
123+
124+
function sum2() {
125+
var result = 0;
126+
for (var i=0,n=sum2.arguments.length; i<n; ++i)
127+
result += sum2.arguments[i];
128+
return result;
129+
}
130+
131+
// OK
132+
sum2(1, 2, 3);

0 commit comments

Comments
 (0)