Skip to content

Commit

Permalink
Replace for loop with Array.prototype.forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
takasmiley committed Jun 28, 2017
1 parent e72fee4 commit 833ff2c
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions lib/sinon/spy.js
Expand Up @@ -164,20 +164,18 @@ var spyApi = {
invoke: function invoke(func, thisValue, args) {
var matchings = this.matchingFakes(args);
var currentCallId = callId++;
var exception, returnValue, i;
var exception, returnValue;

incrementCallCount.call(this);
push.call(this.thisValues, thisValue);
push.call(this.args, args);
push.call(this.callIds, currentCallId);
if (matchings) {
for (i = 0; i < matchings.length; i++) {
incrementCallCount.call(matchings[i]);
push.call(matchings[i].thisValues, thisValue);
push.call(matchings[i].args, args);
push.call(matchings[i].callIds, currentCallId);
}
}
matchings.forEach(function (matching) {
incrementCallCount.call(matching);
push.call(matching.thisValues, thisValue);
push.call(matching.args, args);
push.call(matching.callIds, currentCallId);
});

// Make call properties available from within the spied function:
createCallProperties.call(this);
Expand All @@ -199,12 +197,10 @@ var spyApi = {

push.call(this.exceptions, exception);
push.call(this.returnValues, returnValue);
if (matchings) {
for (i = 0; i < matchings.length; i++) {
push.call(matchings[i].exceptions, exception);
push.call(matchings[i].returnValues, returnValue);
}
}
matchings.forEach(function (matching) {
push.call(matching.exceptions, exception);
push.call(matching.returnValues, returnValue);
});

var err = new ErrorConstructor();
// 1. Please do not get stack at this point. It may be so very slow, and not actually used
Expand All @@ -214,11 +210,9 @@ var spyApi = {
throw err;
} catch (e) {/* empty */}
push.call(this.errorsWithCallStack, err);
if (matchings) {
for (i = 0; i < matchings.length; i++) {
push.call(matchings[i].errorsWithCallStack, err);
}
}
matchings.forEach(function (matching) {
push.call(matching.errorsWithCallStack, err);
});

// Make return value and exception available in the calls:
createCallProperties.call(this);
Expand Down

0 comments on commit 833ff2c

Please sign in to comment.