| 1 | import getLength from './_getLength.js';
|
|---|
| 2 | import isFunction from './isFunction.js';
|
|---|
| 3 | import allKeys from './allKeys.js';
|
|---|
| 4 |
|
|---|
| 5 | // Since the regular `Object.prototype.toString` type tests don't work for
|
|---|
| 6 | // some types in IE 11, we use a fingerprinting heuristic instead, based
|
|---|
| 7 | // on the methods. It's not great, but it's the best we got.
|
|---|
| 8 | // The fingerprint method lists are defined below.
|
|---|
| 9 | export function ie11fingerprint(methods) {
|
|---|
| 10 | var length = getLength(methods);
|
|---|
| 11 | return function(obj) {
|
|---|
| 12 | if (obj == null) return false;
|
|---|
| 13 | // `Map`, `WeakMap` and `Set` have no enumerable keys.
|
|---|
| 14 | var keys = allKeys(obj);
|
|---|
| 15 | if (getLength(keys)) return false;
|
|---|
| 16 | for (var i = 0; i < length; i++) {
|
|---|
| 17 | if (!isFunction(obj[methods[i]])) return false;
|
|---|
| 18 | }
|
|---|
| 19 | // If we are testing against `WeakMap`, we need to ensure that
|
|---|
| 20 | // `obj` doesn't have a `forEach` method in order to distinguish
|
|---|
| 21 | // it from a regular `Map`.
|
|---|
| 22 | return methods !== weakMapMethods || !isFunction(obj[forEachName]);
|
|---|
| 23 | };
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | // In the interest of compact minification, we write
|
|---|
| 27 | // each string in the fingerprints only once.
|
|---|
| 28 | var forEachName = 'forEach',
|
|---|
| 29 | hasName = 'has',
|
|---|
| 30 | commonInit = ['clear', 'delete'],
|
|---|
| 31 | mapTail = ['get', hasName, 'set'];
|
|---|
| 32 |
|
|---|
| 33 | // `Map`, `WeakMap` and `Set` each have slightly different
|
|---|
| 34 | // combinations of the above sublists.
|
|---|
| 35 | export var mapMethods = commonInit.concat(forEachName, mapTail),
|
|---|
| 36 | weakMapMethods = commonInit.concat(mapTail),
|
|---|
| 37 | setMethods = ['add'].concat(commonInit, forEachName, hasName);
|
|---|