From 893d8a60cbf7ae3d42655547beb703249b96d895 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 18 Nov 2020 10:57:14 +0100 Subject: [PATCH] errors: refactor to use more primordials PR-URL: https://github.com/nodejs/node/pull/36167 Reviewed-By: James M Snell Reviewed-By: Trivikram Kamat --- lib/internal/errors.js | 8 +++++--- test/parallel/test-errors-systemerror.js | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 33ea2824784ef0..cff0e9d563c5f7 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) => { @@ -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 ` + 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' } );