diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index db69a5a54dad59..a895da2ad12945 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -98,8 +98,11 @@ function isEqualBoxedPrimitive(val1, val2) { return isBigIntObject(val2) && BigIntPrototype.valueOf(val1) === BigIntPrototype.valueOf(val2); } - return isSymbolObject(val2) && - SymbolPrototype.valueOf(val1) === SymbolPrototype.valueOf(val2); + if (isSymbolObject(val1)) { + return isSymbolObject(val2) && + SymbolPrototype.valueOf(val1) === SymbolPrototype.valueOf(val2); + } + return false; } // Notes: Type tags are historical [[Class]] properties that can be set by @@ -221,7 +224,9 @@ function innerDeepEqual(val1, val2, strict, memos) { if (!areEqualArrayBuffers(val1, val2)) { return false; } - } else if (isBoxedPrimitive(val1) && !isEqualBoxedPrimitive(val1, val2)) { + } + if ((isBoxedPrimitive(val1) || isBoxedPrimitive(val2)) && + !isEqualBoxedPrimitive(val1, val2)) { return false; } return keyCheck(val1, val2, strict, memos, kNoIterator); diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index f0af085c6ab4db..87f2a5f44f7d64 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -28,8 +28,7 @@ function re(literals, ...values) { getters: true }); // Need to escape special characters. - result += str; - result += literals[i + 1]; + result += `${str}${literals[i + 1]}`; } return { code: 'ERR_ASSERTION', @@ -605,11 +604,21 @@ assert.deepStrictEqual([ 1, 2, NaN, 4 ], [ 1, 2, NaN, 4 ]); { const boxedString = new String('test'); const boxedSymbol = Object(Symbol()); + + const fakeBoxedSymbol = {}; + Object.setPrototypeOf(fakeBoxedSymbol, Symbol.prototype); + Object.defineProperty( + fakeBoxedSymbol, + Symbol.toStringTag, + { enumerable: false, value: 'Symbol' } + ); + assertNotDeepOrStrict(new Boolean(true), Object(false)); assertNotDeepOrStrict(Object(true), new Number(1)); assertNotDeepOrStrict(new Number(2), new Number(1)); assertNotDeepOrStrict(boxedSymbol, Object(Symbol())); assertNotDeepOrStrict(boxedSymbol, {}); + assertNotDeepOrStrict(boxedSymbol, fakeBoxedSymbol); assertDeepAndStrictEqual(boxedSymbol, boxedSymbol); assertDeepAndStrictEqual(Object(true), Object(true)); assertDeepAndStrictEqual(Object(2), Object(2)); @@ -618,6 +627,7 @@ assert.deepStrictEqual([ 1, 2, NaN, 4 ], [ 1, 2, NaN, 4 ]); assertNotDeepOrStrict(boxedString, Object('test')); boxedSymbol.slow = true; assertNotDeepOrStrict(boxedSymbol, {}); + assertNotDeepOrStrict(boxedSymbol, fakeBoxedSymbol); } // Minus zero