diff --git a/lib/assert.js b/lib/assert.js index cef7c16f8095e3..3e212a1c3aebbe 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -414,7 +414,6 @@ function compareBranch( } // Check for Set object equality - // TODO(aduh95): switch to `SetPrototypeIsSubsetOf` when it's available if (isSet(actual) && isSet(expected)) { if (expected.size > actual.size) { return false; // `expected` can't be a subset if it has more elements @@ -422,25 +421,18 @@ function compareBranch( if (isDeepEqual === undefined) lazyLoadComparison(); - const actualArray = ArrayFrom(actual); - const expectedArray = ArrayFrom(expected); + const actualArray = ArrayFrom(FunctionPrototypeCall(SafeSet.prototype[SymbolIterator], actual)); + const expectedIterator = FunctionPrototypeCall(SafeSet.prototype[SymbolIterator], expected); const usedIndices = new SafeSet(); - for (let expectedIdx = 0; expectedIdx < expectedArray.length; expectedIdx++) { - const expectedItem = expectedArray[expectedIdx]; - let found = false; - + expectedIteration: for (const expectedItem of expectedIterator) { for (let actualIdx = 0; actualIdx < actualArray.length; actualIdx++) { if (!usedIndices.has(actualIdx) && isDeepStrictEqual(actualArray[actualIdx], expectedItem)) { usedIndices.add(actualIdx); - found = true; - break; + continue expectedIteration; } } - - if (!found) { - return false; - } + return false; } return true;