util,assert: fix boxed primitives bug
Currently the comparison could throw an error in case a boxed primitive has no valueOf function on one side of the assert call. PR-URL: https://github.com/nodejs/node/pull/22243 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: George Adams <george.adams@uk.ibm.com>
This commit is contained in:
parent
0aae34f52e
commit
c7ca199c38
@ -120,6 +120,9 @@ function strictDeepEqual(val1, val2, memos) {
|
|||||||
const val1Value = val1.valueOf();
|
const val1Value = val1.valueOf();
|
||||||
// Note: Boxed string keys are going to be compared again by Object.keys
|
// Note: Boxed string keys are going to be compared again by Object.keys
|
||||||
if (val1Value !== val1) {
|
if (val1Value !== val1) {
|
||||||
|
if (typeof val2.valueOf !== 'function') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!innerDeepEqual(val1Value, val2.valueOf(), true))
|
if (!innerDeepEqual(val1Value, val2.valueOf(), true))
|
||||||
return false;
|
return false;
|
||||||
// Fast path for boxed primitives
|
// Fast path for boxed primitives
|
||||||
|
@ -890,3 +890,10 @@ assert.deepStrictEqual(obj1, obj2);
|
|||||||
);
|
);
|
||||||
util.inspect.defaultOptions = tmp;
|
util.inspect.defaultOptions = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Basic valueOf check.
|
||||||
|
{
|
||||||
|
const a = new String(1);
|
||||||
|
a.valueOf = undefined;
|
||||||
|
assertNotDeepOrStrict(a, new String(1));
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user