@@ -4,7 +4,6 @@ var valueToString = require("@sinonjs/commons").valueToString;
44var className = require ( "@sinonjs/commons" ) . className ;
55var typeOf = require ( "@sinonjs/commons" ) . typeOf ;
66var arrayProto = require ( "@sinonjs/commons" ) . prototypes . array ;
7- var objectProto = require ( "@sinonjs/commons" ) . prototypes . object ;
87var mapForEach = require ( "@sinonjs/commons" ) . prototypes . map . forEach ;
98
109var getClass = require ( "./get-class" ) ;
@@ -25,22 +24,38 @@ var every = arrayProto.every;
2524var push = arrayProto . push ;
2625
2726var getTime = Date . prototype . getTime ;
28- var hasOwnProperty = objectProto . hasOwnProperty ;
2927var indexOf = arrayProto . indexOf ;
30- var keys = Object . keys ;
3128var getOwnPropertySymbols = Object . getOwnPropertySymbols ;
3229
30+ /**
31+ * We explicitly want to get props on proto chain
32+ *
33+ * Objects such as URL in the browser do not have any
34+ * enumerable keys of its own. All meaningful props
35+ * to compare are enumerable getters further up the chain
36+ * @param {object } object
37+ * @returns {Array<string> } the list of enumerable keys
38+ */
39+ function allEnumerableKeysInProtoChain ( object ) {
40+ const keys = [ ] ;
41+
42+ // eslint-disable-next-line
43+ for ( const key in object ) {
44+ keys . push ( key ) ;
45+ }
46+ return keys ;
47+ }
48+
3349/**
3450 * Deep equal comparison. Two values are "deep equal" when:
3551 *
36- * - They are equal, according to samsam.identical
37- * - They are both date objects representing the same time
38- * - They are both arrays containing elements that are all deepEqual
39- * - They are objects with the same set of properties, and each property
40- * in ``actual`` is deepEqual to the corresponding property in ``expectation``
52+ * - They are equal, according to samsam.identical
53+ * - They are both date objects representing the same time
54+ * - They are both arrays containing elements that are all deepEqual
55+ * - They are objects with the same set of properties, and each property
56+ * in ``actual`` is deepEqual to the corresponding property in ``expectation``
4157 *
4258 * Supports cyclic objects.
43- *
4459 * @alias module:samsam.deepEqual
4560 * @param {* } actual The object to examine
4661 * @param {* } expectation The object actual is expected to be equal to
@@ -129,8 +144,8 @@ function deepEqualCyclic(actual, expectation, match) {
129144
130145 var actualClass = getClass ( actualObj ) ;
131146 var expectationClass = getClass ( expectationObj ) ;
132- var actualKeys = keys ( actualObj ) ;
133- var expectationKeys = keys ( expectationObj ) ;
147+ var actualKeys = allEnumerableKeysInProtoChain ( actualObj ) ;
148+ var expectationKeys = allEnumerableKeysInProtoChain ( expectationObj ) ;
134149 var actualName = className ( actualObj ) ;
135150 var expectationName = className ( expectationObj ) ;
136151 var expectationSymbols =
@@ -231,10 +246,6 @@ function deepEqualCyclic(actual, expectation, match) {
231246 }
232247
233248 return every ( expectationKeysAndSymbols , function ( key ) {
234- if ( ! hasOwnProperty ( actualObj , key ) ) {
235- return false ;
236- }
237-
238249 var actualValue = actualObj [ key ] ;
239250 var expectationValue = expectationObj [ key ] ;
240251 var actualObject = isObject ( actualValue ) ;
0 commit comments