Skip to content

Commit 0f12b31

Browse files
committed
[Refactor] avoid needing a call-bound push
1 parent 861c17c commit 0f12b31

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

lib/results.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ var $exec = callBound('RegExp.prototype.exec');
1212
var $split = callBound('String.prototype.split');
1313
var $replace = callBound('String.prototype.replace');
1414
var $shift = callBound('Array.prototype.shift');
15-
var $push = callBound('Array.prototype.push');
1615
var yamlIndicators = /:|-|\?/;
1716
var nextTick = typeof setImmediate !== 'undefined'
1817
? setImmediate
@@ -169,7 +168,7 @@ Results.prototype.createStream = function (opts) {
169168
};
170169

171170
Results.prototype.push = function (t) {
172-
$push(this.tests, t);
171+
this.tests[this.tests.length] = t;
173172
this._watch(t);
174173
this.emit('_push', t);
175174
};

lib/test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ var objectToString = callBound('Object.prototype.toString');
2525
var $split = callBound('String.prototype.split');
2626
var $replace = callBound('String.prototype.replace');
2727
var $strSlice = callBound('String.prototype.slice');
28-
var $push = callBound('Array.prototype.push');
2928
var $shift = callBound('Array.prototype.shift');
3029
var $slice = callBound('Array.prototype.slice');
3130

@@ -155,7 +154,7 @@ Test.prototype.run = function run() {
155154
Test.prototype.test = function test(name, opts, cb) {
156155
var self = this;
157156
var t = new Test(name, opts, cb);
158-
$push(this._progeny, t);
157+
this._progeny[this._progeny.length] = t;
159158
this.pendingCount++;
160159
this.emit('test', t);
161160
t.on('prerun', function () {
@@ -235,12 +234,12 @@ function wrapFunction(original) {
235234
var completed = false;
236235
try {
237236
var returned = bound ? bound(this, arguments) : void undefined;
238-
$push(calls, { args: args, receiver: this, returned: returned });
237+
calls[calls.length] = { args: args, receiver: this, returned: returned };
239238
completed = true;
240239
return returned;
241240
} finally {
242241
if (!completed) {
243-
$push(calls, { args: args, receiver: this, threw: true });
242+
calls[calls.length] = { args: args, receiver: this, threw: true };
244243
}
245244
}
246245
},
@@ -326,16 +325,16 @@ Test.prototype.intercept = function intercept(obj, property) {
326325
try {
327326
var returned = getter(this, arguments);
328327
completed = true;
329-
$push(calls, { type: 'get', success: true, value: returned, args: args, receiver: this });
328+
calls[calls.length] = { type: 'get', success: true, value: returned, args: args, receiver: this };
330329
return returned;
331330
} finally {
332331
if (!completed) {
333-
$push(calls, { type: 'get', success: false, threw: true, args: args, receiver: this });
332+
calls[calls.length] = { type: 'get', success: false, threw: true, args: args, receiver: this };
334333
}
335334
}
336335
}
337336
}
338-
$push(calls, { type: 'get', success: true, value: value, args: args, receiver: this });
337+
calls[calls.length] = { type: 'get', success: true, value: value, args: args, receiver: this };
339338
return value;
340339
}
341340

@@ -346,19 +345,19 @@ Test.prototype.intercept = function intercept(obj, property) {
346345
try {
347346
var returned = setter(this, arguments);
348347
completed = true;
349-
$push(calls, { type: 'set', success: true, value: v, args: args, receiver: this });
348+
calls[calls.length] = { type: 'set', success: true, value: v, args: args, receiver: this };
350349
return returned;
351350
} finally {
352351
if (!completed) {
353-
$push(calls, { type: 'set', success: false, threw: true, args: args, receiver: this });
352+
calls[calls.length] = { type: 'set', success: false, threw: true, args: args, receiver: this };
354353
}
355354
}
356355
}
357356
var canSet = isAccessor || writable;
358357
if (canSet) {
359358
value = v;
360359
}
361-
$push(calls, { type: 'set', success: !!canSet, value: value, args: args, receiver: this });
360+
calls[calls.length] = { type: 'set', success: !!canSet, value: value, args: args, receiver: this };
362361

363362
if (!canSet && strictMode) {
364363
throw new TypeError('Cannot assign to read only property `' + inspect(property) + '` of object `' + inspect(obj) + '`');
@@ -855,7 +854,8 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
855854
var keys = objectKeys(expected);
856855
// Special handle errors to make sure the name and the message are compared as well.
857856
if (expected instanceof Error) {
858-
$push(keys, 'name', 'message');
857+
keys[keys.length] = 'name';
858+
keys[keys.length] = 'message';
859859
} else if (keys.length === 0) {
860860
throw new TypeError('`throws` validation object must not be empty');
861861
}

0 commit comments

Comments
 (0)