es.symbol.for.js 919 B

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