Skip to content

Commit

Permalink
Merge pull request #21 from meeber/fix-circular
Browse files Browse the repository at this point in the history
fix: treat circular objects and sets as equal
  • Loading branch information
keithamus authored Oct 18, 2016
2 parents 617b392 + b26ec76 commit 841f6f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ function extensiveDeepEqual(leftHandOperand, rightHandOperand, options) {
}

// Temporarily set the operands in the memoize object to prevent blowing the stack
memoizeSet(leftHandOperand, rightHandOperand, options.memoize, false);
memoizeSet(rightHandOperand, leftHandOperand, options.memoize, false);
memoizeSet(leftHandOperand, rightHandOperand, options.memoize, true);
memoizeSet(rightHandOperand, leftHandOperand, options.memoize, true);

var result = extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options);
memoizeSet(leftHandOperand, rightHandOperand, options.memoize, result);
Expand Down
6 changes: 3 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ describe('Generic', function () {
assert(eql({ foo: 'bar' }, { bar: 'baz' }) === false, 'eql({ foo: "bar" }, { foo: "baz" }) === false');
});

it('returns false with recursive objects of differing values', function () {
it('returns true with circular objects', function () {
var objectA = { foo: 1 };
var objectB = { foo: 1 };
objectA.bar = objectB;
objectB.bar = objectA;
assert(eql(objectA, objectB) === false,
'eql({ foo: 1, bar: -> }, { foo: 1, bar: <- }) === false');
assert(eql(objectA, objectB) === true,
'eql({ foo: 1, bar: -> }, { foo: 1, bar: <- }) === true');
});

});
Expand Down
4 changes: 2 additions & 2 deletions test/new-ecmascript-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ describe('ES2015 Specific', function () {
assert(eql(setA, setB) === false, 'eql(Set { "a", "b", "c" }, Set { "d", "e", "f" }) === false');
});

it('returns false for Sets with different circular references', function () {
it('returns true for circular Sets', function () {
var setA = new Set();
var setB = new Set();
setA.add(setB);
setB.add(setA);
assert(eql(setA, setB) === false, 'eql(Set { -> }, Set { <- }) === false');
assert(eql(setA, setB) === true, 'eql(Set { -> }, Set { <- }) === true');
});

});
Expand Down

0 comments on commit 841f6f5

Please sign in to comment.