25
25
'use strict' ;
26
26
27
27
// UTILITY
28
- const compare = process . binding ( 'buffer' ) . compare ;
29
28
const util = require ( 'util' ) ;
30
- const Buffer = require ( 'buffer' ) . Buffer ;
31
29
const pSlice = Array . prototype . slice ;
32
30
33
31
// 1. The assert module provides functions that throw
@@ -146,24 +144,12 @@ function _deepEqual(actual, expected, strict) {
146
144
// 7.1. All identical values are equivalent, as determined by ===.
147
145
if ( actual === expected ) {
148
146
return true ;
149
- } else if ( actual instanceof Buffer && expected instanceof Buffer ) {
150
- return compare ( actual , expected ) === 0 ;
151
147
152
148
// 7.2. If the expected value is a Date object, the actual value is
153
149
// equivalent if it is also a Date object that refers to the same time.
154
150
} else if ( util . isDate ( actual ) && util . isDate ( expected ) ) {
155
151
return actual . getTime ( ) === expected . getTime ( ) ;
156
152
157
- // 7.3 If the expected value is a RegExp object, the actual value is
158
- // equivalent if it is also a RegExp object with the same source and
159
- // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
160
- } else if ( util . isRegExp ( actual ) && util . isRegExp ( expected ) ) {
161
- return actual . source === expected . source &&
162
- actual . global === expected . global &&
163
- actual . multiline === expected . multiline &&
164
- actual . lastIndex === expected . lastIndex &&
165
- actual . ignoreCase === expected . ignoreCase ;
166
-
167
153
// 7.4. Other pairs that do not both pass typeof value == 'object',
168
154
// equivalence is determined by ==.
169
155
} else if ( ( actual === null || typeof actual !== 'object' ) &&
@@ -185,6 +171,10 @@ function isArguments(object) {
185
171
return Object . prototype . toString . call ( object ) == '[object Arguments]' ;
186
172
}
187
173
174
+ function isArrayOrString ( object ) {
175
+ return object instanceof Array || object instanceof String ;
176
+ }
177
+
188
178
function objEquiv ( a , b , strict ) {
189
179
if ( a === null || a === undefined || b === null || b === undefined )
190
180
return false ;
@@ -202,18 +192,26 @@ function objEquiv(a, b, strict) {
202
192
b = pSlice . call ( b ) ;
203
193
return _deepEqual ( a , b , strict ) ;
204
194
}
205
- var ka , kb , key , i ;
206
-
207
- function _getKeys ( obj ) {
208
- if ( obj instanceof Error ) {
209
- return Object . getOwnPropertyNames ( obj ) ;
195
+ var ka = Object . getOwnPropertyNames ( a ) ,
196
+ kb = Object . getOwnPropertyNames ( b ) ,
197
+ key , i ;
198
+
199
+ // when comparing String/Array to non-Strings/non-Array, ignore length prop
200
+ const aLengthIndex = ka . indexOf ( 'length' ) ;
201
+ const bLengthIndex = kb . indexOf ( 'length' ) ;
202
+ const aHasLength = ( aLengthIndex !== - 1 ) ;
203
+ const bHasLength = ( bLengthIndex !== - 1 ) ;
204
+
205
+ if ( isArrayOrString ( a ) !== isArrayOrString ( b ) ) {
206
+ if ( aHasLength !== bHasLength ) {
207
+ if ( aHasLength ) {
208
+ ka . splice ( bLengthIndex ) ;
209
+ } else {
210
+ kb . splice ( aLengthIndex ) ;
211
+ }
210
212
}
211
- return Object . keys ( obj ) ;
212
213
}
213
214
214
- ka = _getKeys ( a ) ;
215
- kb = _getKeys ( b ) ;
216
-
217
215
// having the same number of owned properties (keys incorporates
218
216
// hasOwnProperty)
219
217
if ( ka . length !== kb . length )
0 commit comments