Skip to content

Commit

Permalink
fix: use a FakeMap to support IE10 (#60)
Browse files Browse the repository at this point in the history
* fix: use a FakeMap to support IE10

* fix lint

* fix lint
  • Loading branch information
keithamus authored Nov 7, 2022
1 parent 3747fa8 commit edd9314
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,31 @@ try {
nodeInspect = false
}

const constructorMap = new WeakMap()
function FakeMap() {
// eslint-disable-next-line prefer-template
this.key = 'chai/loupe__' + Math.random() + Date.now()
}
FakeMap.prototype = {
// eslint-disable-next-line object-shorthand
get: function get(key) {
return key[this.key]
},
// eslint-disable-next-line object-shorthand
has: function has(key) {
return this.key in key
},
// eslint-disable-next-line object-shorthand
set: function set(key, value) {
if (Object.isExtensible(key)) {
Object.defineProperty(key, this.key, {
// eslint-disable-next-line object-shorthand
value: value,
configurable: true,
})
}
},
}
const constructorMap = new (typeof WeakMap === 'function' ? WeakMap : FakeMap)()
const stringTagMap = {}
const baseTypesMap = {
undefined: (value, options) => options.stylize('undefined', 'undefined'),
Expand Down Expand Up @@ -178,7 +202,7 @@ export function registerConstructor(constructor, inspector) {
if (constructorMap.has(constructor)) {
return false
}
constructorMap.add(constructor, inspector)
constructorMap.set(constructor, inspector)
return true
}

Expand Down

0 comments on commit edd9314

Please sign in to comment.