refactor: fix Edge freezing issue for matcherUtils#eq
fix Microsoft Edge freezing when recursive comparing
This commit is contained in:
@@ -175,22 +175,21 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Deep compare objects.
|
||||
for (var key in a) {
|
||||
if (has(a, key)) {
|
||||
// Count the expected number of properties.
|
||||
size++;
|
||||
// Deep compare each member.
|
||||
if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters))) { break; }
|
||||
var aKeys = keys(a), size = aKeys.length, key;
|
||||
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
||||
if (keys(b).length !== size) { return false; }
|
||||
|
||||
while (size--) {
|
||||
key = aKeys[size];
|
||||
// Deep compare each member
|
||||
result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters);
|
||||
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Ensure that both objects contain the same number of properties.
|
||||
if (result) {
|
||||
for (key in b) {
|
||||
if (has(b, key) && !(size--)) { break; }
|
||||
}
|
||||
result = !size;
|
||||
}
|
||||
}
|
||||
// Remove the first object from the stack of traversed objects.
|
||||
aStack.pop();
|
||||
@@ -198,6 +197,19 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
|
||||
return result;
|
||||
|
||||
function keys(obj) {
|
||||
return Object.keys ? Object.keys(obj) :
|
||||
(function(o) {
|
||||
var keys = [];
|
||||
for (var key in o) {
|
||||
if (has(o, key)) {
|
||||
keys.push(key);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
})(obj);
|
||||
}
|
||||
|
||||
function has(obj, key) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user