11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Confirm functionality of `util.isDeepStrictEqual()`.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cirequire('../common');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst util = require('util');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciclass MyDate extends Date {
111cb0ef41Sopenharmony_ci  constructor(...args) {
121cb0ef41Sopenharmony_ci    super(...args);
131cb0ef41Sopenharmony_ci    this[0] = '1';
141cb0ef41Sopenharmony_ci  }
151cb0ef41Sopenharmony_ci}
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciclass MyRegExp extends RegExp {
181cb0ef41Sopenharmony_ci  constructor(...args) {
191cb0ef41Sopenharmony_ci    super(...args);
201cb0ef41Sopenharmony_ci    this[0] = '1';
211cb0ef41Sopenharmony_ci  }
221cb0ef41Sopenharmony_ci}
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci{
251cb0ef41Sopenharmony_ci  const arr = new Uint8Array([120, 121, 122, 10]);
261cb0ef41Sopenharmony_ci  const buf = Buffer.from(arr);
271cb0ef41Sopenharmony_ci  // They have different [[Prototype]]
281cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(arr, buf), false);
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  const buf2 = Buffer.from(arr);
311cb0ef41Sopenharmony_ci  buf2.prop = 1;
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(buf2, buf), false);
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  const arr2 = new Uint8Array([120, 121, 122, 10]);
361cb0ef41Sopenharmony_ci  arr2.prop = 5;
371cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(arr, arr2), false);
381cb0ef41Sopenharmony_ci}
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci{
411cb0ef41Sopenharmony_ci  const date = new Date('2016');
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  const date2 = new MyDate('2016');
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  // deepStrictEqual checks own properties
461cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(date, date2), false);
471cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(date2, date), false);
481cb0ef41Sopenharmony_ci}
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci{
511cb0ef41Sopenharmony_ci  const re1 = new RegExp('test');
521cb0ef41Sopenharmony_ci  const re2 = new MyRegExp('test');
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci  // deepStrictEqual checks all properties
551cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(re1, re2), false);
561cb0ef41Sopenharmony_ci}
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci{
591cb0ef41Sopenharmony_ci  // For these cases, deepStrictEqual should throw.
601cb0ef41Sopenharmony_ci  const similar = new Set([
611cb0ef41Sopenharmony_ci    { 0: '1' },  // Object
621cb0ef41Sopenharmony_ci    { 0: 1 },  // Object
631cb0ef41Sopenharmony_ci    new String('1'),  // Object
641cb0ef41Sopenharmony_ci    ['1'],  // Array
651cb0ef41Sopenharmony_ci    [1],  // Array
661cb0ef41Sopenharmony_ci    new MyDate('2016'), // Date with this[0] = '1'
671cb0ef41Sopenharmony_ci    new MyRegExp('test'),  // RegExp with this[0] = '1'
681cb0ef41Sopenharmony_ci    new Int8Array([1]), // Int8Array
691cb0ef41Sopenharmony_ci    new Uint8Array([1]), // Uint8Array
701cb0ef41Sopenharmony_ci    new Int16Array([1]), // Int16Array
711cb0ef41Sopenharmony_ci    new Uint16Array([1]), // Uint16Array
721cb0ef41Sopenharmony_ci    new Int32Array([1]), // Int32Array
731cb0ef41Sopenharmony_ci    new Uint32Array([1]), // Uint32Array
741cb0ef41Sopenharmony_ci    Buffer.from([1]), // Buffer
751cb0ef41Sopenharmony_ci  ]);
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci  for (const a of similar) {
781cb0ef41Sopenharmony_ci    for (const b of similar) {
791cb0ef41Sopenharmony_ci      if (a !== b) {
801cb0ef41Sopenharmony_ci        assert.strictEqual(util.isDeepStrictEqual(a, b), false);
811cb0ef41Sopenharmony_ci      }
821cb0ef41Sopenharmony_ci    }
831cb0ef41Sopenharmony_ci  }
841cb0ef41Sopenharmony_ci}
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_cifunction utilIsDeepStrict(a, b) {
871cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(a, b), true);
881cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(b, a), true);
891cb0ef41Sopenharmony_ci}
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_cifunction notUtilIsDeepStrict(a, b) {
921cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(a, b), false);
931cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(b, a), false);
941cb0ef41Sopenharmony_ci}
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci// es6 Maps and Sets
971cb0ef41Sopenharmony_ciutilIsDeepStrict(new Set(), new Set());
981cb0ef41Sopenharmony_ciutilIsDeepStrict(new Map(), new Map());
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ciutilIsDeepStrict(new Set([1, 2, 3]), new Set([1, 2, 3]));
1011cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Set([1, 2, 3]), new Set([1, 2, 3, 4]));
1021cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Set([1, 2, 3, 4]), new Set([1, 2, 3]));
1031cb0ef41Sopenharmony_ciutilIsDeepStrict(new Set(['1', '2', '3']), new Set(['1', '2', '3']));
1041cb0ef41Sopenharmony_ciutilIsDeepStrict(new Set([[1, 2], [3, 4]]), new Set([[3, 4], [1, 2]]));
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci{
1071cb0ef41Sopenharmony_ci  const a = [ 1, 2 ];
1081cb0ef41Sopenharmony_ci  const b = [ 3, 4 ];
1091cb0ef41Sopenharmony_ci  const c = [ 1, 2 ];
1101cb0ef41Sopenharmony_ci  const d = [ 3, 4 ];
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci  utilIsDeepStrict(
1131cb0ef41Sopenharmony_ci    { a: a, b: b, s: new Set([a, b]) },
1141cb0ef41Sopenharmony_ci    { a: c, b: d, s: new Set([d, c]) }
1151cb0ef41Sopenharmony_ci  );
1161cb0ef41Sopenharmony_ci}
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ciutilIsDeepStrict(new Map([[1, 1], [2, 2]]), new Map([[1, 1], [2, 2]]));
1191cb0ef41Sopenharmony_ciutilIsDeepStrict(new Map([[1, 1], [2, 2]]), new Map([[2, 2], [1, 1]]));
1201cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Map([[1, 1], [2, 2]]), new Map([[1, 2], [2, 1]]));
1211cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1221cb0ef41Sopenharmony_ci  new Map([[[1], 1], [{}, 2]]),
1231cb0ef41Sopenharmony_ci  new Map([[[1], 2], [{}, 1]])
1241cb0ef41Sopenharmony_ci);
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Set([1]), [1]);
1271cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Set(), []);
1281cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Set(), {});
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Map([['a', 1]]), { a: 1 });
1311cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Map(), []);
1321cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Map(), {});
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Set(['1']), new Set([1]));
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Map([['1', 'a']]), new Map([[1, 'a']]));
1371cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Map([['a', '1']]), new Map([['a', 1]]));
1381cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Map([['a', '1']]), new Map([['a', 2]]));
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ciutilIsDeepStrict(new Set([{}]), new Set([{}]));
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ci// Ref: https://github.com/nodejs/node/issues/13347
1431cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1441cb0ef41Sopenharmony_ci  new Set([{ a: 1 }, { a: 1 }]),
1451cb0ef41Sopenharmony_ci  new Set([{ a: 1 }, { a: 2 }])
1461cb0ef41Sopenharmony_ci);
1471cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1481cb0ef41Sopenharmony_ci  new Set([{ a: 1 }, { a: 1 }, { a: 2 }]),
1491cb0ef41Sopenharmony_ci  new Set([{ a: 1 }, { a: 2 }, { a: 2 }])
1501cb0ef41Sopenharmony_ci);
1511cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1521cb0ef41Sopenharmony_ci  new Map([[{ x: 1 }, 5], [{ x: 1 }, 5]]),
1531cb0ef41Sopenharmony_ci  new Map([[{ x: 1 }, 5], [{ x: 2 }, 5]])
1541cb0ef41Sopenharmony_ci);
1551cb0ef41Sopenharmony_ci
1561cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Set([3, '3']), new Set([3, 4]));
1571cb0ef41Sopenharmony_cinotUtilIsDeepStrict(new Map([[3, 0], ['3', 0]]), new Map([[3, 0], [4, 0]]));
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1601cb0ef41Sopenharmony_ci  new Set([{ a: 1 }, { a: 1 }, { a: 2 }]),
1611cb0ef41Sopenharmony_ci  new Set([{ a: 1 }, { a: 2 }, { a: 2 }])
1621cb0ef41Sopenharmony_ci);
1631cb0ef41Sopenharmony_ci
1641cb0ef41Sopenharmony_ci// Mixed primitive and object keys
1651cb0ef41Sopenharmony_ciutilIsDeepStrict(
1661cb0ef41Sopenharmony_ci  new Map([[1, 'a'], [{}, 'a']]),
1671cb0ef41Sopenharmony_ci  new Map([[1, 'a'], [{}, 'a']])
1681cb0ef41Sopenharmony_ci);
1691cb0ef41Sopenharmony_ciutilIsDeepStrict(
1701cb0ef41Sopenharmony_ci  new Set([1, 'a', [{}, 'a']]),
1711cb0ef41Sopenharmony_ci  new Set([1, 'a', [{}, 'a']])
1721cb0ef41Sopenharmony_ci);
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_ci// This is an awful case, where a map contains multiple equivalent keys:
1751cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1761cb0ef41Sopenharmony_ci  new Map([[1, 'a'], ['1', 'b']]),
1771cb0ef41Sopenharmony_ci  new Map([['1', 'a'], [true, 'b']])
1781cb0ef41Sopenharmony_ci);
1791cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1801cb0ef41Sopenharmony_ci  new Set(['a']),
1811cb0ef41Sopenharmony_ci  new Set(['b'])
1821cb0ef41Sopenharmony_ci);
1831cb0ef41Sopenharmony_ciutilIsDeepStrict(
1841cb0ef41Sopenharmony_ci  new Map([[{}, 'a'], [{}, 'b']]),
1851cb0ef41Sopenharmony_ci  new Map([[{}, 'b'], [{}, 'a']])
1861cb0ef41Sopenharmony_ci);
1871cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1881cb0ef41Sopenharmony_ci  new Map([[true, 'a'], ['1', 'b'], [1, 'a']]),
1891cb0ef41Sopenharmony_ci  new Map([['1', 'a'], [1, 'b'], [true, 'a']])
1901cb0ef41Sopenharmony_ci);
1911cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1921cb0ef41Sopenharmony_ci  new Map([[true, 'a'], ['1', 'b'], [1, 'c']]),
1931cb0ef41Sopenharmony_ci  new Map([['1', 'a'], [1, 'b'], [true, 'a']])
1941cb0ef41Sopenharmony_ci);
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ci// Similar object keys
1971cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
1981cb0ef41Sopenharmony_ci  new Set([{}, {}]),
1991cb0ef41Sopenharmony_ci  new Set([{}, 1])
2001cb0ef41Sopenharmony_ci);
2011cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
2021cb0ef41Sopenharmony_ci  new Set([[{}, 1], [{}, 1]]),
2031cb0ef41Sopenharmony_ci  new Set([[{}, 1], [1, 1]])
2041cb0ef41Sopenharmony_ci);
2051cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
2061cb0ef41Sopenharmony_ci  new Map([[{}, 1], [{}, 1]]),
2071cb0ef41Sopenharmony_ci  new Map([[{}, 1], [1, 1]])
2081cb0ef41Sopenharmony_ci);
2091cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
2101cb0ef41Sopenharmony_ci  new Map([[{}, 1], [true, 1]]),
2111cb0ef41Sopenharmony_ci  new Map([[{}, 1], [1, 1]])
2121cb0ef41Sopenharmony_ci);
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci// Similar primitive key / values
2151cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
2161cb0ef41Sopenharmony_ci  new Set([1, true, false]),
2171cb0ef41Sopenharmony_ci  new Set(['1', 0, '0'])
2181cb0ef41Sopenharmony_ci);
2191cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
2201cb0ef41Sopenharmony_ci  new Map([[1, 5], [true, 5], [false, 5]]),
2211cb0ef41Sopenharmony_ci  new Map([['1', 5], [0, 5], ['0', 5]])
2221cb0ef41Sopenharmony_ci);
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_ci// Undefined value in Map
2251cb0ef41Sopenharmony_ciutilIsDeepStrict(
2261cb0ef41Sopenharmony_ci  new Map([[1, undefined]]),
2271cb0ef41Sopenharmony_ci  new Map([[1, undefined]])
2281cb0ef41Sopenharmony_ci);
2291cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
2301cb0ef41Sopenharmony_ci  new Map([[1, null]]),
2311cb0ef41Sopenharmony_ci  new Map([['1', undefined]])
2321cb0ef41Sopenharmony_ci);
2331cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
2341cb0ef41Sopenharmony_ci  new Map([[1, undefined]]),
2351cb0ef41Sopenharmony_ci  new Map([[2, undefined]])
2361cb0ef41Sopenharmony_ci);
2371cb0ef41Sopenharmony_ci
2381cb0ef41Sopenharmony_ci// null as key
2391cb0ef41Sopenharmony_ciutilIsDeepStrict(
2401cb0ef41Sopenharmony_ci  new Map([[null, 3]]),
2411cb0ef41Sopenharmony_ci  new Map([[null, 3]])
2421cb0ef41Sopenharmony_ci);
2431cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
2441cb0ef41Sopenharmony_ci  new Map([[null, undefined]]),
2451cb0ef41Sopenharmony_ci  new Map([[undefined, null]])
2461cb0ef41Sopenharmony_ci);
2471cb0ef41Sopenharmony_cinotUtilIsDeepStrict(
2481cb0ef41Sopenharmony_ci  new Set([null]),
2491cb0ef41Sopenharmony_ci  new Set([undefined])
2501cb0ef41Sopenharmony_ci);
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ci// GH-6416. Make sure circular refs don't throw.
2531cb0ef41Sopenharmony_ci{
2541cb0ef41Sopenharmony_ci  const b = {};
2551cb0ef41Sopenharmony_ci  b.b = b;
2561cb0ef41Sopenharmony_ci  const c = {};
2571cb0ef41Sopenharmony_ci  c.b = c;
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci  utilIsDeepStrict(b, c);
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_ci  const d = {};
2621cb0ef41Sopenharmony_ci  d.a = 1;
2631cb0ef41Sopenharmony_ci  d.b = d;
2641cb0ef41Sopenharmony_ci  const e = {};
2651cb0ef41Sopenharmony_ci  e.a = 1;
2661cb0ef41Sopenharmony_ci  e.b = {};
2671cb0ef41Sopenharmony_ci
2681cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(d, e);
2691cb0ef41Sopenharmony_ci}
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_ci// GH-14441. Circular structures should be consistent
2721cb0ef41Sopenharmony_ci{
2731cb0ef41Sopenharmony_ci  const a = {};
2741cb0ef41Sopenharmony_ci  const b = {};
2751cb0ef41Sopenharmony_ci  a.a = a;
2761cb0ef41Sopenharmony_ci  b.a = {};
2771cb0ef41Sopenharmony_ci  b.a.a = a;
2781cb0ef41Sopenharmony_ci  utilIsDeepStrict(a, b);
2791cb0ef41Sopenharmony_ci}
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ci{
2821cb0ef41Sopenharmony_ci  const a = new Set();
2831cb0ef41Sopenharmony_ci  const b = new Set();
2841cb0ef41Sopenharmony_ci  const c = new Set();
2851cb0ef41Sopenharmony_ci  a.add(a);
2861cb0ef41Sopenharmony_ci  b.add(b);
2871cb0ef41Sopenharmony_ci  c.add(a);
2881cb0ef41Sopenharmony_ci  utilIsDeepStrict(b, c);
2891cb0ef41Sopenharmony_ci}
2901cb0ef41Sopenharmony_ci
2911cb0ef41Sopenharmony_ci// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
2921cb0ef41Sopenharmony_ci{
2931cb0ef41Sopenharmony_ci  const args = (function() { return arguments; })();
2941cb0ef41Sopenharmony_ci  notUtilIsDeepStrict([], args);
2951cb0ef41Sopenharmony_ci}
2961cb0ef41Sopenharmony_ci
2971cb0ef41Sopenharmony_ci// More checking that arguments objects are handled correctly
2981cb0ef41Sopenharmony_ci{
2991cb0ef41Sopenharmony_ci  // eslint-disable-next-line func-style
3001cb0ef41Sopenharmony_ci  const returnArguments = function() { return arguments; };
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci  const someArgs = returnArguments('a');
3031cb0ef41Sopenharmony_ci  const sameArgs = returnArguments('a');
3041cb0ef41Sopenharmony_ci  const diffArgs = returnArguments('b');
3051cb0ef41Sopenharmony_ci
3061cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(someArgs, ['a']);
3071cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(someArgs, { '0': 'a' });
3081cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(someArgs, diffArgs);
3091cb0ef41Sopenharmony_ci  utilIsDeepStrict(someArgs, sameArgs);
3101cb0ef41Sopenharmony_ci}
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci{
3131cb0ef41Sopenharmony_ci  const values = [
3141cb0ef41Sopenharmony_ci    123,
3151cb0ef41Sopenharmony_ci    Infinity,
3161cb0ef41Sopenharmony_ci    0,
3171cb0ef41Sopenharmony_ci    null,
3181cb0ef41Sopenharmony_ci    undefined,
3191cb0ef41Sopenharmony_ci    false,
3201cb0ef41Sopenharmony_ci    true,
3211cb0ef41Sopenharmony_ci    {},
3221cb0ef41Sopenharmony_ci    [],
3231cb0ef41Sopenharmony_ci    () => {},
3241cb0ef41Sopenharmony_ci  ];
3251cb0ef41Sopenharmony_ci  utilIsDeepStrict(new Set(values), new Set(values));
3261cb0ef41Sopenharmony_ci  utilIsDeepStrict(new Set(values), new Set(values.reverse()));
3271cb0ef41Sopenharmony_ci
3281cb0ef41Sopenharmony_ci  const mapValues = values.map((v) => [v, { a: 5 }]);
3291cb0ef41Sopenharmony_ci  utilIsDeepStrict(new Map(mapValues), new Map(mapValues));
3301cb0ef41Sopenharmony_ci  utilIsDeepStrict(new Map(mapValues), new Map(mapValues.reverse()));
3311cb0ef41Sopenharmony_ci}
3321cb0ef41Sopenharmony_ci
3331cb0ef41Sopenharmony_ci{
3341cb0ef41Sopenharmony_ci  const s1 = new Set();
3351cb0ef41Sopenharmony_ci  const s2 = new Set();
3361cb0ef41Sopenharmony_ci  s1.add(1);
3371cb0ef41Sopenharmony_ci  s1.add(2);
3381cb0ef41Sopenharmony_ci  s2.add(2);
3391cb0ef41Sopenharmony_ci  s2.add(1);
3401cb0ef41Sopenharmony_ci  utilIsDeepStrict(s1, s2);
3411cb0ef41Sopenharmony_ci}
3421cb0ef41Sopenharmony_ci
3431cb0ef41Sopenharmony_ci{
3441cb0ef41Sopenharmony_ci  const m1 = new Map();
3451cb0ef41Sopenharmony_ci  const m2 = new Map();
3461cb0ef41Sopenharmony_ci  const obj = { a: 5, b: 6 };
3471cb0ef41Sopenharmony_ci  m1.set(1, obj);
3481cb0ef41Sopenharmony_ci  m1.set(2, 'hi');
3491cb0ef41Sopenharmony_ci  m1.set(3, [1, 2, 3]);
3501cb0ef41Sopenharmony_ci
3511cb0ef41Sopenharmony_ci  m2.set(2, 'hi'); // different order
3521cb0ef41Sopenharmony_ci  m2.set(1, obj);
3531cb0ef41Sopenharmony_ci  m2.set(3, [1, 2, 3]); // Deep equal, but not reference equal.
3541cb0ef41Sopenharmony_ci
3551cb0ef41Sopenharmony_ci  utilIsDeepStrict(m1, m2);
3561cb0ef41Sopenharmony_ci}
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_ci{
3591cb0ef41Sopenharmony_ci  const m1 = new Map();
3601cb0ef41Sopenharmony_ci  const m2 = new Map();
3611cb0ef41Sopenharmony_ci
3621cb0ef41Sopenharmony_ci  // m1 contains itself.
3631cb0ef41Sopenharmony_ci  m1.set(1, m1);
3641cb0ef41Sopenharmony_ci  m2.set(1, new Map());
3651cb0ef41Sopenharmony_ci
3661cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(m1, m2);
3671cb0ef41Sopenharmony_ci}
3681cb0ef41Sopenharmony_ci
3691cb0ef41Sopenharmony_ci{
3701cb0ef41Sopenharmony_ci  const map1 = new Map([[1, 1]]);
3711cb0ef41Sopenharmony_ci  const map2 = new Map([[1, '1']]);
3721cb0ef41Sopenharmony_ci  assert.strictEqual(util.isDeepStrictEqual(map1, map2), false);
3731cb0ef41Sopenharmony_ci}
3741cb0ef41Sopenharmony_ci
3751cb0ef41Sopenharmony_ci{
3761cb0ef41Sopenharmony_ci  // Two equivalent sets / maps with different key/values applied shouldn't be
3771cb0ef41Sopenharmony_ci  // the same. This is a terrible idea to do in practice, but deepEqual should
3781cb0ef41Sopenharmony_ci  // still check for it.
3791cb0ef41Sopenharmony_ci  const s1 = new Set();
3801cb0ef41Sopenharmony_ci  const s2 = new Set();
3811cb0ef41Sopenharmony_ci  s1.x = 5;
3821cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(s1, s2);
3831cb0ef41Sopenharmony_ci
3841cb0ef41Sopenharmony_ci  const m1 = new Map();
3851cb0ef41Sopenharmony_ci  const m2 = new Map();
3861cb0ef41Sopenharmony_ci  m1.x = 5;
3871cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(m1, m2);
3881cb0ef41Sopenharmony_ci}
3891cb0ef41Sopenharmony_ci
3901cb0ef41Sopenharmony_ci{
3911cb0ef41Sopenharmony_ci  // Circular references.
3921cb0ef41Sopenharmony_ci  const s1 = new Set();
3931cb0ef41Sopenharmony_ci  s1.add(s1);
3941cb0ef41Sopenharmony_ci  const s2 = new Set();
3951cb0ef41Sopenharmony_ci  s2.add(s2);
3961cb0ef41Sopenharmony_ci  utilIsDeepStrict(s1, s2);
3971cb0ef41Sopenharmony_ci
3981cb0ef41Sopenharmony_ci  const m1 = new Map();
3991cb0ef41Sopenharmony_ci  m1.set(2, m1);
4001cb0ef41Sopenharmony_ci  const m2 = new Map();
4011cb0ef41Sopenharmony_ci  m2.set(2, m2);
4021cb0ef41Sopenharmony_ci  utilIsDeepStrict(m1, m2);
4031cb0ef41Sopenharmony_ci
4041cb0ef41Sopenharmony_ci  const m3 = new Map();
4051cb0ef41Sopenharmony_ci  m3.set(m3, 2);
4061cb0ef41Sopenharmony_ci  const m4 = new Map();
4071cb0ef41Sopenharmony_ci  m4.set(m4, 2);
4081cb0ef41Sopenharmony_ci  utilIsDeepStrict(m3, m4);
4091cb0ef41Sopenharmony_ci}
4101cb0ef41Sopenharmony_ci
4111cb0ef41Sopenharmony_ci// Handle sparse arrays
4121cb0ef41Sopenharmony_ci/* eslint-disable no-sparse-arrays */
4131cb0ef41Sopenharmony_ciutilIsDeepStrict([1, , , 3], [1, , , 3]);
4141cb0ef41Sopenharmony_cinotUtilIsDeepStrict([1, , , 3], [1, , , 3, , , ]);
4151cb0ef41Sopenharmony_ci/* eslint-enable no-sparse-arrays */
4161cb0ef41Sopenharmony_ci
4171cb0ef41Sopenharmony_ci// Handle different error messages
4181cb0ef41Sopenharmony_ci{
4191cb0ef41Sopenharmony_ci  const err1 = new Error('foo1');
4201cb0ef41Sopenharmony_ci  const err2 = new Error('foo2');
4211cb0ef41Sopenharmony_ci  const err3 = new TypeError('foo1');
4221cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(err1, err2, assert.AssertionError);
4231cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(err1, err3, assert.AssertionError);
4241cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(err1, {}, assert.AssertionError);
4251cb0ef41Sopenharmony_ci}
4261cb0ef41Sopenharmony_ci
4271cb0ef41Sopenharmony_ci// Handle NaN
4281cb0ef41Sopenharmony_ciassert.strictEqual(util.isDeepStrictEqual(NaN, NaN), true);
4291cb0ef41Sopenharmony_ciassert.strictEqual(util.isDeepStrictEqual({ a: NaN }, { a: NaN }), true);
4301cb0ef41Sopenharmony_ciassert.strictEqual(
4311cb0ef41Sopenharmony_ci  util.isDeepStrictEqual([ 1, 2, NaN, 4 ], [ 1, 2, NaN, 4 ]),
4321cb0ef41Sopenharmony_ci  true
4331cb0ef41Sopenharmony_ci);
4341cb0ef41Sopenharmony_ci
4351cb0ef41Sopenharmony_ci// Handle boxed primitives
4361cb0ef41Sopenharmony_ci{
4371cb0ef41Sopenharmony_ci  const boxedString = new String('test');
4381cb0ef41Sopenharmony_ci  const boxedSymbol = Object(Symbol());
4391cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(new Boolean(true), Object(false));
4401cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(Object(true), new Number(1));
4411cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(new Number(2), new Number(1));
4421cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(boxedSymbol, Object(Symbol()));
4431cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(boxedSymbol, {});
4441cb0ef41Sopenharmony_ci  utilIsDeepStrict(boxedSymbol, boxedSymbol);
4451cb0ef41Sopenharmony_ci  utilIsDeepStrict(Object(true), Object(true));
4461cb0ef41Sopenharmony_ci  utilIsDeepStrict(Object(2), Object(2));
4471cb0ef41Sopenharmony_ci  utilIsDeepStrict(boxedString, Object('test'));
4481cb0ef41Sopenharmony_ci  boxedString.slow = true;
4491cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(boxedString, Object('test'));
4501cb0ef41Sopenharmony_ci  boxedSymbol.slow = true;
4511cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(boxedSymbol, {});
4521cb0ef41Sopenharmony_ci  utilIsDeepStrict(Object(BigInt(1)), Object(BigInt(1)));
4531cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(Object(BigInt(1)), Object(BigInt(2)));
4541cb0ef41Sopenharmony_ci
4551cb0ef41Sopenharmony_ci  const booleanish = new Boolean(true);
4561cb0ef41Sopenharmony_ci  Object.defineProperty(booleanish, Symbol.toStringTag, { value: 'String' });
4571cb0ef41Sopenharmony_ci  Object.setPrototypeOf(booleanish, String.prototype);
4581cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(booleanish, new String('true'));
4591cb0ef41Sopenharmony_ci
4601cb0ef41Sopenharmony_ci  const numberish = new Number(42);
4611cb0ef41Sopenharmony_ci  Object.defineProperty(numberish, Symbol.toStringTag, { value: 'String' });
4621cb0ef41Sopenharmony_ci  Object.setPrototypeOf(numberish, String.prototype);
4631cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(numberish, new String('42'));
4641cb0ef41Sopenharmony_ci
4651cb0ef41Sopenharmony_ci  const stringish = new String('0');
4661cb0ef41Sopenharmony_ci  Object.defineProperty(stringish, Symbol.toStringTag, { value: 'Number' });
4671cb0ef41Sopenharmony_ci  Object.setPrototypeOf(stringish, Number.prototype);
4681cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(stringish, new Number(0));
4691cb0ef41Sopenharmony_ci
4701cb0ef41Sopenharmony_ci  const bigintish = new Object(BigInt(42));
4711cb0ef41Sopenharmony_ci  Object.defineProperty(bigintish, Symbol.toStringTag, { value: 'String' });
4721cb0ef41Sopenharmony_ci  Object.setPrototypeOf(bigintish, String.prototype);
4731cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(bigintish, new String('42'));
4741cb0ef41Sopenharmony_ci
4751cb0ef41Sopenharmony_ci  const symbolish = new Object(Symbol('fhqwhgads'));
4761cb0ef41Sopenharmony_ci  Object.defineProperty(symbolish, Symbol.toStringTag, { value: 'String' });
4771cb0ef41Sopenharmony_ci  Object.setPrototypeOf(symbolish, String.prototype);
4781cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(symbolish, new String('fhqwhgads'));
4791cb0ef41Sopenharmony_ci}
4801cb0ef41Sopenharmony_ci
4811cb0ef41Sopenharmony_ci// Minus zero
4821cb0ef41Sopenharmony_cinotUtilIsDeepStrict(0, -0);
4831cb0ef41Sopenharmony_ciutilIsDeepStrict(-0, -0);
4841cb0ef41Sopenharmony_ci
4851cb0ef41Sopenharmony_ci// Handle symbols (enumerable only)
4861cb0ef41Sopenharmony_ci{
4871cb0ef41Sopenharmony_ci  const symbol1 = Symbol();
4881cb0ef41Sopenharmony_ci  const obj1 = { [symbol1]: 1 };
4891cb0ef41Sopenharmony_ci  const obj2 = { [symbol1]: 1 };
4901cb0ef41Sopenharmony_ci  const obj3 = { [Symbol()]: 1 };
4911cb0ef41Sopenharmony_ci  const obj4 = { };
4921cb0ef41Sopenharmony_ci  // Add a non enumerable symbol as well. It is going to be ignored!
4931cb0ef41Sopenharmony_ci  Object.defineProperty(obj2, Symbol(), { value: 1 });
4941cb0ef41Sopenharmony_ci  Object.defineProperty(obj4, symbol1, { value: 1 });
4951cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(obj1, obj3);
4961cb0ef41Sopenharmony_ci  utilIsDeepStrict(obj1, obj2);
4971cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(obj1, obj4);
4981cb0ef41Sopenharmony_ci  // TypedArrays have a fast path. Test for this as well.
4991cb0ef41Sopenharmony_ci  const a = new Uint8Array(4);
5001cb0ef41Sopenharmony_ci  const b = new Uint8Array(4);
5011cb0ef41Sopenharmony_ci  a[symbol1] = true;
5021cb0ef41Sopenharmony_ci  b[symbol1] = false;
5031cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(a, b);
5041cb0ef41Sopenharmony_ci  b[symbol1] = true;
5051cb0ef41Sopenharmony_ci  utilIsDeepStrict(a, b);
5061cb0ef41Sopenharmony_ci  // The same as TypedArrays is valid for boxed primitives
5071cb0ef41Sopenharmony_ci  const boxedStringA = new String('test');
5081cb0ef41Sopenharmony_ci  const boxedStringB = new String('test');
5091cb0ef41Sopenharmony_ci  boxedStringA[symbol1] = true;
5101cb0ef41Sopenharmony_ci  notUtilIsDeepStrict(boxedStringA, boxedStringB);
5111cb0ef41Sopenharmony_ci  boxedStringA[symbol1] = true;
5121cb0ef41Sopenharmony_ci  utilIsDeepStrict(a, b);
5131cb0ef41Sopenharmony_ci}
514