errors: refactor to use more primordials

PR-URL: https://github.com/nodejs/node/pull/36167
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Antoine du Hamel
2020-11-18 10:57:14 +01:00
parent 2425589262
commit 893d8a60cb
2 changed files with 6 additions and 4 deletions

View File

@@ -40,6 +40,7 @@ const {
String,
StringPrototypeEndsWith,
StringPrototypeIncludes,
StringPrototypeMatch,
StringPrototypeSlice,
StringPrototypeSplit,
StringPrototypeStartsWith,
@@ -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) => {
@@ -376,10 +377,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 ` +

View File

@@ -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'
}
);