Bug 505940 - Unnecessarily uploading records on first sync

Remove short-circuit logic of comparing number of keys for deepEquals and iterate through each key on both objects to make sure both have the same value.
This commit is contained in:
Edward Lee 2009-07-22 23:49:15 -07:00
Родитель 3f02ff2536
Коммит 188e9c9a17
2 изменённых файлов: 30 добавлений и 6 удалений

Просмотреть файл

@ -301,14 +301,25 @@ let Utils = {
if (a === b)
return true;
// Grab the keys from both sides
let [A, B] = [[i for (i in a)], [i for (i in b)]];
// Don't bother doing any more if they aren't objects with same # keys
if (typeof a != "object" || typeof b != "object" || A.length != B.length)
// If they weren't equal, they must be objects to be different
if (typeof a != "object" || typeof b != "object")
return false;
// Check if both sides have the same keys and same value for the key
return A.every(function(A) B.some(function(B) A == B && eq(a[A], b[B])));
// But null objects won't have properties to compare
if (a === null || b === null)
return false;
// Make sure all of a's keys have a matching value in b
for (let k in a)
if (!eq(a[k], b[k]))
return false;
// Do the same for b's keys but skip those that we already checked
for (let k in b)
if (!(k in a) && !eq(a[k], b[k]))
return false;
return true;
},
deepCopy: function Weave_deepCopy(thing, noSort) {

Просмотреть файл

@ -39,4 +39,17 @@ function run_test() {
_("Actual matches:", numMatch);
do_check_eq(numMatch, expect);
});
_("Make sure adding undefined properties doesn't affect equalness");
let a = {};
let b = { a: undefined };
do_check_true(Utils.deepEquals(a, b));
a.b = 5;
do_check_false(Utils.deepEquals(a, b));
b.b = 5;
do_check_true(Utils.deepEquals(a, b));
a.c = undefined;
do_check_true(Utils.deepEquals(a, b));
b.d = undefined;
do_check_true(Utils.deepEquals(a, b));
}