Skip to content

Commit 9ada68b

Browse files
TrottMylesBorins
authored andcommitted
benchmark: refactor benchmark/assert/throws.js
This is a minor refactor of benchmark/assert/throws.js to reduce exceptions that need to be made for lint compliance. PR-URL: #21030 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent b8470b9 commit 9ada68b

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

benchmark/assert/throws.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const common = require('../common.js');
4-
const assert = require('assert');
4+
const { throws, doesNotThrow } = require('assert');
55

66
const bench = common.createBenchmark(main, {
77
n: [1e6],
@@ -14,8 +14,8 @@ const bench = common.createBenchmark(main, {
1414
});
1515

1616
function main({ n, method }) {
17-
const throws = () => { throw new TypeError('foobar'); };
18-
const doesNotThrow = () => { return 'foobar'; };
17+
const throwError = () => { throw new TypeError('foobar'); };
18+
const doNotThrowError = () => { return 'foobar'; };
1919
const regExp = /foobar/;
2020
const message = 'failure';
2121
var i;
@@ -26,30 +26,28 @@ function main({ n, method }) {
2626
case 'doesNotThrow':
2727
bench.start();
2828
for (i = 0; i < n; ++i) {
29-
// eslint-disable-next-line no-restricted-syntax
30-
assert.doesNotThrow(doesNotThrow);
29+
doesNotThrow(doNotThrowError);
3130
}
3231
bench.end(n);
3332
break;
3433
case 'throws':
3534
bench.start();
3635
for (i = 0; i < n; ++i) {
37-
// eslint-disable-next-line no-restricted-syntax
38-
assert.throws(throws);
36+
throws(throwError);
3937
}
4038
bench.end(n);
4139
break;
4240
case 'throws_TypeError':
4341
bench.start();
4442
for (i = 0; i < n; ++i) {
45-
assert.throws(throws, TypeError, message);
43+
throws(throwError, TypeError, message);
4644
}
4745
bench.end(n);
4846
break;
4947
case 'throws_RegExp':
5048
bench.start();
5149
for (i = 0; i < n; ++i) {
52-
assert.throws(throws, regExp, message);
50+
throws(throwError, regExp, message);
5351
}
5452
bench.end(n);
5553
break;

0 commit comments

Comments
 (0)