Skip to content

Commit edd9314

Browse files
authored
fix: use a FakeMap to support IE10 (#60)
* fix: use a FakeMap to support IE10 * fix lint * fix lint
1 parent 3747fa8 commit edd9314

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

index.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,31 @@ try {
3535
nodeInspect = false
3636
}
3737

38-
const constructorMap = new WeakMap()
38+
function FakeMap() {
39+
// eslint-disable-next-line prefer-template
40+
this.key = 'chai/loupe__' + Math.random() + Date.now()
41+
}
42+
FakeMap.prototype = {
43+
// eslint-disable-next-line object-shorthand
44+
get: function get(key) {
45+
return key[this.key]
46+
},
47+
// eslint-disable-next-line object-shorthand
48+
has: function has(key) {
49+
return this.key in key
50+
},
51+
// eslint-disable-next-line object-shorthand
52+
set: function set(key, value) {
53+
if (Object.isExtensible(key)) {
54+
Object.defineProperty(key, this.key, {
55+
// eslint-disable-next-line object-shorthand
56+
value: value,
57+
configurable: true,
58+
})
59+
}
60+
},
61+
}
62+
const constructorMap = new (typeof WeakMap === 'function' ? WeakMap : FakeMap)()
3963
const stringTagMap = {}
4064
const baseTypesMap = {
4165
undefined: (value, options) => options.stylize('undefined', 'undefined'),
@@ -178,7 +202,7 @@ export function registerConstructor(constructor, inspector) {
178202
if (constructorMap.has(constructor)) {
179203
return false
180204
}
181-
constructorMap.add(constructor, inspector)
205+
constructorMap.set(constructor, inspector)
182206
return true
183207
}
184208

0 commit comments

Comments
 (0)