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