well-known-symbol.js 1.0 KB

123456789101112131415161718192021222324
  1. var global = require('../internals/global');
  2. var shared = require('../internals/shared');
  3. var hasOwn = require('../internals/has-own-property');
  4. var uid = require('../internals/uid');
  5. var NATIVE_SYMBOL = require('../internals/native-symbol');
  6. var USE_SYMBOL_AS_UID = require('../internals/use-symbol-as-uid');
  7. var WellKnownSymbolsStore = shared('wks');
  8. var Symbol = global.Symbol;
  9. var symbolFor = Symbol && Symbol['for'];
  10. var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol : Symbol && Symbol.withoutSetter || uid;
  11. module.exports = function (name) {
  12. if (!hasOwn(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) {
  13. var description = 'Symbol.' + name;
  14. if (NATIVE_SYMBOL && hasOwn(Symbol, name)) {
  15. WellKnownSymbolsStore[name] = Symbol[name];
  16. } else if (USE_SYMBOL_AS_UID && symbolFor) {
  17. WellKnownSymbolsStore[name] = symbolFor(description);
  18. } else {
  19. WellKnownSymbolsStore[name] = createWellKnownSymbol(description);
  20. }
  21. } return WellKnownSymbolsStore[name];
  22. };