Skip to content

Commit 83d2837

Browse files
aduh95targos
authored andcommitted
errors: refactor to use more primordials
PR-URL: #36167 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 0fbe945 commit 83d2837

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/internal/errors.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const {
4040
String,
4141
StringPrototypeEndsWith,
4242
StringPrototypeIncludes,
43+
StringPrototypeMatch,
4344
StringPrototypeSlice,
4445
StringPrototypeSplit,
4546
StringPrototypeStartsWith,
@@ -96,7 +97,7 @@ const prepareStackTrace = (globalThis, error, trace) => {
9697
if (trace.length === 0) {
9798
return errorString;
9899
}
99-
return `${errorString}\n at ${trace.join('\n at ')}`;
100+
return `${errorString}\n at ${ArrayPrototypeJoin(trace, '\n at ')}`;
100101
};
101102

102103
const maybeOverridePrepareStackTrace = (globalThis, error, trace) => {
@@ -372,10 +373,11 @@ function getMessage(key, args, self) {
372373
`Code: ${key}; The provided arguments length (${args.length}) does not ` +
373374
`match the required ones (${msg.length}).`
374375
);
375-
return msg.apply(self, args);
376+
return ReflectApply(msg, self, args);
376377
}
377378

378-
const expectedLength = (msg.match(/%[dfijoOs]/g) || []).length;
379+
const expectedLength =
380+
(StringPrototypeMatch(msg, /%[dfijoOs]/g) || []).length;
379381
assert(
380382
expectedLength === args.length,
381383
`Code: ${key}; The provided arguments length (${args.length}) does not ` +

test/parallel/test-errors-systemerror.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ assert.throws(
99
() => { new SystemError(); },
1010
{
1111
name: 'TypeError',
12-
message: 'Cannot read property \'match\' of undefined'
12+
message: 'String.prototype.match called on null or undefined'
1313
}
1414
);
1515

0 commit comments

Comments
 (0)