lib0 1.0.0-rc.26 → 1.0.0-rc.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/function.js +9 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib0",
3
- "version": "1.0.0-rc.26",
3
+ "version": "1.0.0-rc.27",
4
4
  "description": "isomorphic utility functions",
5
5
  "sideEffects": false,
6
6
  "type": "module",
package/src/function.js CHANGED
@@ -61,8 +61,6 @@ export const equalityStrict = (a, b) => a === b
61
61
  */
62
62
  export const equalityFlat = (a, b) => a === b || (a != null && b != null && a.constructor === b.constructor && ((array.isArray(a) && array.equalFlat(a, /** @type {Array<T>} */ (b))) || (typeof a === 'object' && object.equalFlat(a, b))))
63
63
 
64
- /* c8 ignore start */
65
-
66
64
  /**
67
65
  * @param {any} a
68
66
  * @param {any} b
@@ -72,13 +70,20 @@ export const equalityDeep = (a, b) => {
72
70
  if (a === b) {
73
71
  return true
74
72
  }
75
- if (a == null || b == null || (a.constructor !== b.constructor && (a.constructor || Object) !== (b.constructor || Object))) {
73
+ if (a == null || b == null) {
74
+ return false
75
+ }
76
+ // read the constructor off the prototype, not the object — a plain object may declare an own
77
+ // property named "constructor" (e.g. `{ constructor: 4 }`)
78
+ const aC = Object.getPrototypeOf(a)?.constructor
79
+ const bC = Object.getPrototypeOf(b)?.constructor
80
+ if (aC !== bC && (aC || Object) !== (bC || Object)) {
76
81
  return false
77
82
  }
78
83
  if (a[equalityTrait.EqualityTraitSymbol] != null) {
79
84
  return a[equalityTrait.EqualityTraitSymbol](b)
80
85
  }
81
- switch (a.constructor) {
86
+ switch (aC) {
82
87
  case ArrayBuffer:
83
88
  a = new Uint8Array(a)
84
89
  b = new Uint8Array(b)
@@ -152,7 +157,6 @@ export const equalityDeep = (a, b) => {
152
157
  */
153
158
  // @ts-ignore
154
159
  export const isOneOf = (value, options) => options.includes(value)
155
- /* c8 ignore stop */
156
160
 
157
161
  export const isArray = array.isArray
158
162