◐ Shell
clean mode source ↗

assert,util: fix stale nested cycle memo entries · nodejs/node@dd72df0

@@ -260,6 +260,14 @@ function assertOnlyDeepEqual(a, b, err) {

260260

assert.throws(partial, err || { code: 'ERR_ASSERTION' });

261261

}

262262263+

function activateMemoizedCycleDetection() {

264+

const circA = {};

265+

circA.self = circA;

266+

const circB = {};

267+

circB.self = circB;

268+

assert.deepStrictEqual(circA, circB);

269+

}

270+263271

test('es6 Maps and Sets', () => {

264272

assertDeepAndStrictEqual(new Set(), new Set());

265273

assertDeepAndStrictEqual(new Map(), new Map());

@@ -609,6 +617,36 @@ test('GH-14441. Circular structures should be consistent', () => {

609617

}

610618

});

611619620+

test('deepStrictEqual handles shared expected array elements after cycle detection', () => {

621+

const sharedExpected = { outer: { inner: 0 } };

622+

const actualValues = [{ outer: { inner: 0 } }, { outer: { inner: 0 } }];

623+

const expectedValues = [sharedExpected, sharedExpected];

624+625+

activateMemoizedCycleDetection();

626+627+

assertDeepAndStrictEqual(actualValues[0], expectedValues[0]);

628+

assertDeepAndStrictEqual(actualValues[1], expectedValues[1]);

629+

assertDeepAndStrictEqual(actualValues, expectedValues);

630+

});

631+632+

test('deepStrictEqual handles cross-root aliases after cycle detection', () => {

633+

activateMemoizedCycleDetection();

634+635+

const nestedExpected = {};

636+

nestedExpected.loop = nestedExpected;

637+

nestedExpected.payload = { value: 1 };

638+639+

const expected = {};

640+

expected.loop = nestedExpected;

641+

expected.payload = { value: 1 };

642+643+

const actual = {};

644+

actual.loop = expected;

645+

actual.payload = { value: 1 };

646+647+

assertDeepAndStrictEqual(actual, expected);

648+

});

649+612650

// https://github.com/nodejs/node-v0.x-archive/pull/7178

613651

test('Ensure reflexivity of deepEqual with `arguments` objects.', () => {

614652

const args = (function() { return arguments; })();