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 Mar 3, 2017
1 parent c8892ff commit e11b3ac
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions lib/sinon/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,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 @@ -195,12 +193,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's may be so very slow, and not actually used
Expand All @@ -210,11 +206,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 e11b3ac

Please sign in to comment.