es.symbol.for.js 905 B

12345678910111213141516171819202122
  1. var $ = require('../internals/export');
  2. var getBuiltIn = require('../internals/get-built-in');
  3. var hasOwn = require('../internals/has-own-property');
  4. var toString = require('../internals/to-string');
  5. var shared = require('../internals/shared');
  6. var NATIVE_SYMBOL_REGISTRY = require('../internals/symbol-registry-detection');
  7. var StringToSymbolRegistry = shared('string-to-symbol-registry');
  8. var SymbolToStringRegistry = shared('symbol-to-string-registry');
  9. // `Symbol.for` method
  10. // https://tc39.es/ecma262/#sec-symbol.for
  11. $({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {
  12. 'for': function (key) {
  13. var string = toString(key);
  14. if (hasOwn(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];
  15. var symbol = getBuiltIn('Symbol')(string);
  16. StringToSymbolRegistry[string] = symbol;
  17. SymbolToStringRegistry[symbol] = string;
  18. return symbol;
  19. }
  20. });