diff --git a/benchmark/error/error-class-reg-exp.js b/benchmark/error/error-class-reg-exp.js new file mode 100644 index 00000000000000..de8fced9d653f2 --- /dev/null +++ b/benchmark/error/error-class-reg-exp.js @@ -0,0 +1,23 @@ +'use strict'; + +const common = require('../common.js'); + +const bench = common.createBenchmark(main, { + n: [1e5], +}, { + flags: ['--expose-internals'], +}); + +const instances = Array.from({ length: 1000 }).map(() => 'Uint8Array'); + +function main({ n }) { + const { + codes: { + ERR_INVALID_ARG_TYPE, + }, + } = require('internal/errors'); + bench.start(); + for (let i = 0; i < n; ++i) + new ERR_INVALID_ARG_TYPE('target', instances, 'test'); + bench.end(n); +} diff --git a/lib/internal/errors.js b/lib/internal/errors.js index ab5f84e5d720a6..e84b9f6c851205 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -66,7 +66,8 @@ const isWindows = process.platform === 'win32'; const messages = new SafeMap(); const codes = {}; -const classRegExp = /^([A-Z][a-z0-9]*)+$/; +const classRegExp = /^[A-Z][a-zA-Z0-9]*$/; + // Sorted by a rough estimate on most frequently used entries. const kTypes = [ 'string',