Helper to perform cached object comparison
(self: object, that: object)
| 229 | |
| 230 | /** Helper to perform cached object comparison */ |
| 231 | function compareObjects(self: object, that: object): boolean { |
| 232 | if (Hash.hash(self) !== Hash.hash(that)) { |
| 233 | return false |
| 234 | } else if (self instanceof Date) { |
| 235 | if (!(that instanceof Date)) return false |
| 236 | const selfTime = self.getTime() |
| 237 | const thatTime = that.getTime() |
| 238 | return selfTime === thatTime || (Number.isNaN(selfTime) && Number.isNaN(thatTime)) |
| 239 | } else if (self instanceof RegExp) { |
| 240 | if (!(that instanceof RegExp)) return false |
| 241 | return self.toString() === that.toString() |
| 242 | } |
| 243 | const selfIsEqual = isEqual(self) |
| 244 | const thatIsEqual = isEqual(that) |
| 245 | if (selfIsEqual !== thatIsEqual) return false |
| 246 | const bothEquals = selfIsEqual && thatIsEqual |
| 247 | if (typeof self === "function" && !bothEquals) { |
| 248 | return false |
| 249 | } |
| 250 | return withVisitedTracking(self, that, () => { |
| 251 | if (bothEquals) { |
| 252 | return (self as any)[symbol](that) |
| 253 | } else if (Array.isArray(self)) { |
| 254 | if (!Array.isArray(that) || self.length !== that.length) { |
| 255 | return false |
| 256 | } |
| 257 | return compareArrays(self, that) |
| 258 | } else if (ArrayBuffer.isView(self)) { |
| 259 | const selfIsDataView = self instanceof DataView |
| 260 | if ( |
| 261 | !ArrayBuffer.isView(that) || |
| 262 | self.byteLength !== that.byteLength || |
| 263 | selfIsDataView !== (that instanceof DataView) |
| 264 | ) { |
| 265 | return false |
| 266 | } |
| 267 | if (selfIsDataView) { |
| 268 | const thatDataView = that as DataView |
| 269 | return compareTypedArrays( |
| 270 | new Uint8Array(self.buffer, self.byteOffset, self.byteLength), |
| 271 | new Uint8Array(thatDataView.buffer, thatDataView.byteOffset, thatDataView.byteLength) |
| 272 | ) |
| 273 | } |
| 274 | return compareTypedArrays(self as Uint8Array, that as Uint8Array) |
| 275 | } else if (self instanceof Map) { |
| 276 | if (!(that instanceof Map) || self.size !== that.size) { |
| 277 | return false |
| 278 | } |
| 279 | return compareMaps(self, that) |
| 280 | } else if (self instanceof Set) { |
| 281 | if (!(that instanceof Set) || self.size !== that.size) { |
| 282 | return false |
| 283 | } |
| 284 | return compareSets(self, that) |
| 285 | } |
| 286 | return compareRecords(self as any, that as any) |
| 287 | }) |
| 288 | } |
nothing calls this directly
no test coverage detected