diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index 5c15b96b12..5dbf1e7a34 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -10,6 +10,7 @@ const { ObjectDefineProperty, ObjectGetPrototypeOf, ObjectPrototypeHasOwnProperty, + SafeSet, String, StringPrototypeRepeat, StringPrototypeSlice, @@ -42,7 +43,10 @@ const kReadableOperator = { const kMaxShortStringLength = 12; const kMaxLongStringLength = 512; -const kMethodsWithCustomMessageDiff = ['deepStrictEqual', 'strictEqual', 'partialDeepStrictEqual']; +const kMethodsWithCustomMessageDiff = new SafeSet() + .add('deepStrictEqual') + .add('strictEqual') + .add('partialDeepStrictEqual'); function copyError(source) { const target = ObjectAssign( @@ -263,7 +267,7 @@ class AssertionError extends Error { if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0; if (message != null) { - if (kMethodsWithCustomMessageDiff.includes(operator)) { + if (kMethodsWithCustomMessageDiff.has(operator)) { super(createErrDiff(actual, expected, operator, message, diff)); } else { super(String(message)); @@ -283,7 +287,7 @@ class AssertionError extends Error { expected = copyError(expected); } - if (kMethodsWithCustomMessageDiff.includes(operator)) { + if (kMethodsWithCustomMessageDiff.has(operator)) { super(createErrDiff(actual, expected, operator, message, diff)); } else if (operator === 'notDeepStrictEqual' || operator === 'notStrictEqual') {