Skip to content

Commit 70de437

Browse files
committedJul 2, 2023
[Performance] use call-bind for autobinding
This avoids a stack overflow with lots of nested tests
1 parent 2043b2e commit 70de437

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed
 

‎lib/test.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var EventEmitter = require('events').EventEmitter;
88
var has = require('has');
99
var isRegExp = require('is-regex');
1010
var trim = require('string.prototype.trim');
11+
var callBind = require('call-bind');
1112
var callBound = require('call-bind/callBound');
1213
var forEach = require('for-each');
1314
var inspect = require('object-inspect');
@@ -91,12 +92,7 @@ function Test(name_, opts_, cb_) {
9192
var self = this;
9293
for (var prop in self) {
9394
if (typeof self[prop] === 'function') {
94-
self[prop] = (function bind(propName) {
95-
var val = self[propName];
96-
return function bound() {
97-
return val.apply(self, arguments);
98-
};
99-
}(prop));
95+
self[prop] = callBind(self[prop], self);
10096
}
10197
}
10298
}

‎test/async-await.js

-2
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ tap.test('sync-error', function (t) {
210210
'',
211211
'Error: oopsie',
212212
' at Test.myTest ($TEST/async-await/sync-error.js:$LINE:$COL)',
213-
' at Test.bound [as _cb] ($TAPE/lib/test.js:$LINE:$COL)',
214213
' at Test.run ($TAPE/lib/test.js:$LINE:$COL)',
215-
' at Test.bound [as run] ($TAPE/lib/test.js:$LINE:$COL)',
216214
node17 ? [
217215
'',
218216
'Node.js ' + process.version

‎test/teardown.js

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ tap.test('teardowns', function (tt) {
4040
' [... stack stripped ...]',
4141
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
4242
' [... stack stripped ...]',
43+
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
44+
' [... stack stripped ...]',
4345
' ...',
4446
'# nested teardown (nested fail level)',
4547
'# nested teardown (nested fail level) 2',

0 commit comments

Comments
 (0)
Please sign in to comment.