symbol-constructor-detection.js 939 B

12345678910111213141516171819
  1. 'use strict';
  2. /* eslint-disable es/no-symbol -- required for testing */
  3. var V8_VERSION = require('../internals/engine-v8-version');
  4. var fails = require('../internals/fails');
  5. var global = require('../internals/global');
  6. var $String = global.String;
  7. // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
  8. module.exports = !!Object.getOwnPropertySymbols && !fails(function () {
  9. var symbol = Symbol('symbol detection');
  10. // Chrome 38 Symbol has incorrect toString conversion
  11. // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
  12. // nb: Do not call `String` directly to avoid this being optimized out to `symbol+''` which will,
  13. // of course, fail.
  14. return !$String(symbol) || !(Object(symbol) instanceof Symbol) ||
  15. // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
  16. !Symbol.sham && V8_VERSION && V8_VERSION < 41;
  17. });