Skip to content

Commit

Permalink
errors: refactor to use more primordials
Browse files Browse the repository at this point in the history
PR-URL: #36167
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
aduh95 authored and targos committed May 16, 2021
1 parent 986e79a commit 34984f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const {
String,
StringPrototypeEndsWith,
StringPrototypeIncludes,
StringPrototypeMatch,
StringPrototypeSlice,
StringPrototypeSplit,
StringPrototypeStartsWith,
Expand Down Expand Up @@ -96,7 +97,7 @@ const prepareStackTrace = (globalThis, error, trace) => {
if (trace.length === 0) {
return errorString;
}
return `${errorString}\n at ${trace.join('\n at ')}`;
return `${errorString}\n at ${ArrayPrototypeJoin(trace, '\n at ')}`;
};

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

const expectedLength = (msg.match(/%[dfijoOs]/g) || []).length;
const expectedLength =
(StringPrototypeMatch(msg, /%[dfijoOs]/g) || []).length;
assert(
expectedLength === args.length,
`Code: ${key}; The provided arguments length (${args.length}) does not ` +
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-errors-systemerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ assert.throws(
() => { new SystemError(); },
{
name: 'TypeError',
message: 'Cannot read property \'match\' of undefined'
message: 'String.prototype.match called on null or undefined'
}
);

Expand Down

0 comments on commit 34984f3

Please sign in to comment.