Skip to content

Commit

Permalink
refactored native calls
Browse files Browse the repository at this point in the history
  • Loading branch information
fearphage committed Jun 25, 2018
1 parent c4c5099 commit 421bb3d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
11 changes: 6 additions & 5 deletions lib/sinon/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ var functionName = require("./util/core/function-name");
var nextTick = require("./util/core/next-tick");
var valueToString = require("./util/core/value-to-string");

var slice = Array.prototype.slice;
var join = Array.prototype.join;
var concat = require("./var/concat");
var join = require("./var/join");
var slice = require("./var/slice");
var useLeftMostCallback = -1;
var useRightMostCallback = -2;

Expand All @@ -24,7 +25,7 @@ function getCallback(behavior, args) {
}

if (callArgAt === useRightMostCallback) {
argumentList = slice.call(args).reverse();
argumentList = slice(args).reverse();
}

var callArgProp = behavior.callArgProp;
Expand Down Expand Up @@ -57,7 +58,7 @@ function getCallbackError(behavior, func, args) {
}

if (args.length > 0) {
msg += " Received [" + join.call(args, ", ") + "]";
msg += " Received [" + join(args, ", ") + "]";
}

return msg;
Expand Down Expand Up @@ -205,7 +206,7 @@ function createBehavior(behaviorMethod) {

function addBehavior(stub, name, fn) {
proto[name] = function () {
fn.apply(this, [this].concat([].slice.call(arguments)));
fn.apply(this, concat([this], slice(arguments)));
return this.stub || this;
};

Expand Down
8 changes: 5 additions & 3 deletions lib/sinon/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var deepEqual = require("./util/core/deep-equal").use(sinonMatch);
var functionName = require("./util/core/function-name");
var sinonFormat = require("./util/core/format");
var valueToString = require("./util/core/value-to-string");

var concat = require("./var/concat");
var slice = require("./var/slice");
var filter = require("./var/filter");

Expand Down Expand Up @@ -108,7 +110,7 @@ var callProto = {
},

callArgWith: function (pos) {
return this.callArgOnWith.apply(this, [pos, null].concat(slice(arguments, 1)));
return this.callArgOnWith.apply(this, concat([pos, null], slice(arguments, 1)));
},

callArgOnWith: function (pos, thisValue) {
Expand All @@ -130,7 +132,7 @@ var callProto = {
},

yield: function () {
return this.yieldOn.apply(this, [null].concat(slice(arguments, 0)));
return this.yieldOn.apply(this, concat([null], slice(arguments, 0)));
},

yieldOn: function (thisValue) {
Expand All @@ -147,7 +149,7 @@ var callProto = {
},

yieldTo: function (prop) {
return this.yieldToOn.apply(this, [prop, null].concat(slice(arguments, 1)));
return this.yieldToOn.apply(this, concat([prop, null], slice(arguments, 1)));
},

yieldToOn: function (prop, thisValue) {
Expand Down
6 changes: 6 additions & 0 deletions lib/sinon/var/concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";

var call = require("./call");
var array = require("./array");

module.exports = call.bind(array.concat);
6 changes: 6 additions & 0 deletions lib/sinon/var/join.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";

var call = require("./call");
var array = require("./array");

module.exports = call.bind(array.join);

0 comments on commit 421bb3d

Please sign in to comment.