Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert.deepEqual: fix bug with faked boxed primitives #29029

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down