Skip to content

Commit db8217b

Browse files
authored
errors: improve classRegExp in errors.js
PR-URL: #49643 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent f42a103 commit db8217b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [1e5],
7+
}, {
8+
flags: ['--expose-internals'],
9+
});
10+
11+
const instances = Array.from({ length: 1000 }).map(() => 'Uint8Array');
12+
13+
function main({ n }) {
14+
const {
15+
codes: {
16+
ERR_INVALID_ARG_TYPE,
17+
},
18+
} = require('internal/errors');
19+
bench.start();
20+
for (let i = 0; i < n; ++i)
21+
new ERR_INVALID_ARG_TYPE('target', instances, 'test');
22+
bench.end(n);
23+
}

lib/internal/errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ const isWindows = process.platform === 'win32';
6666
const messages = new SafeMap();
6767
const codes = {};
6868

69-
const classRegExp = /^([A-Z][a-z0-9]*)+$/;
69+
const classRegExp = /^[A-Z][a-zA-Z0-9]*$/;
70+
7071
// Sorted by a rough estimate on most frequently used entries.
7172
const kTypes = [
7273
'string',

0 commit comments

Comments
 (0)