Test comparison of objects from different frames

This commit is contained in:
Ben Christel
2016-07-19 14:31:58 -07:00
parent 7f7dda7a2c
commit a0bce8031e
2 changed files with 28 additions and 2 deletions

View File

@@ -178,8 +178,8 @@ getJasmineRequireObj().matchersUtil = function(j$) {
// Objects with different constructors are not equivalent, but `Object`s
// or `Array`s from different frames are.
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(isFunction(aCtor) && aCtor instanceof aCtor &&
isFunction(bCtor) && bCtor instanceof bCtor)) {
if (aCtor !== bCtor && !(isObjectConstructor(aCtor) &&
isObjectConstructor(bCtor))) {
return false;
}
}
@@ -239,5 +239,13 @@ getJasmineRequireObj().matchersUtil = function(j$) {
function isFunction(obj) {
return typeof obj === 'function';
}
function isObjectConstructor(ctor) {
// aCtor instanceof aCtor is true for the Object and Function
// constructors (since a constructor is-a Function and a function is-a
// Object). We don't just compare ctor === Object because the constructor
// might come from a different frame with different globals.
return isFunction(ctor) && ctor instanceof ctor;
}
}
};