diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 5b29ccf561c..0e58ea2cb4e 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -120,6 +120,9 @@ function strictDeepEqual(val1, val2, memos) { const val1Value = val1.valueOf(); // Note: Boxed string keys are going to be compared again by Object.keys if (val1Value !== val1) { + if (typeof val2.valueOf !== 'function') { + return false; + } if (!innerDeepEqual(val1Value, val2.valueOf(), true)) return false; // Fast path for boxed primitives diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index b335f95a511..08491421f62 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -890,3 +890,10 @@ assert.deepStrictEqual(obj1, obj2); ); util.inspect.defaultOptions = tmp; } + +// Basic valueOf check. +{ + const a = new String(1); + a.valueOf = undefined; + assertNotDeepOrStrict(a, new String(1)); +}