diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 45de8e81d6a204..552ef12a3bb0b6 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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) => { @@ -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 ` + diff --git a/test/parallel/test-errors-systemerror.js b/test/parallel/test-errors-systemerror.js index e801871f40af2c..2a20588e75b386 100644 --- a/test/parallel/test-errors-systemerror.js +++ b/test/parallel/test-errors-systemerror.js @@ -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' } );