Skip to content

Commit 142e256

Browse files
Uzlopakruyadorno
authored andcommitted
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 3a9ea09 commit 142e256

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+
constcommon=require('../common.js');
4+
5+
constbench=common.createBenchmark(main,{
6+
n: [1e5],
7+
},{
8+
flags: ['--expose-internals'],
9+
});
10+
11+
constinstances=Array.from({length: 1000}).map(()=>'Uint8Array');
12+
13+
functionmain({ n }){
14+
const{
15+
codes: {
16+
ERR_INVALID_ARG_TYPE,
17+
},
18+
}=require('internal/errors');
19+
bench.start();
20+
for(leti=0;i<n;++i)
21+
newERR_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
constmessages=newSafeMap();
6767
constcodes={};
6868

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

0 commit comments

Comments
(0)