No Description

_methodFingerprint.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. var _getLength = require('./_getLength.js');
  3. var isFunction = require('./isFunction.js');
  4. var allKeys = require('./allKeys.js');
  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. 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. // In the interest of compact minification, we write
  26. // each string in the fingerprints only once.
  27. var forEachName = 'forEach',
  28. hasName = 'has',
  29. commonInit = ['clear', 'delete'],
  30. mapTail = ['get', hasName, 'set'];
  31. // `Map`, `WeakMap` and `Set` each have slightly different
  32. // combinations of the above sublists.
  33. var mapMethods = commonInit.concat(forEachName, mapTail),
  34. weakMapMethods = commonInit.concat(mapTail),
  35. setMethods = ['add'].concat(commonInit, forEachName, hasName);
  36. exports.ie11fingerprint = ie11fingerprint;
  37. exports.mapMethods = mapMethods;
  38. exports.setMethods = setMethods;
  39. exports.weakMapMethods = weakMapMethods;