es.symbol.key-for.js 737 B

1234567891011121314151617
  1. var $ = require('../internals/export');
  2. var hasOwn = require('../internals/has-own-property');
  3. var isSymbol = require('../internals/is-symbol');
  4. var tryToString = require('../internals/try-to-string');
  5. var shared = require('../internals/shared');
  6. var NATIVE_SYMBOL_REGISTRY = require('../internals/native-symbol-registry');
  7. var SymbolToStringRegistry = shared('symbol-to-string-registry');
  8. // `Symbol.keyFor` method
  9. // https://tc39.es/ecma262/#sec-symbol.keyfor
  10. $({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {
  11. keyFor: function keyFor(sym) {
  12. if (!isSymbol(sym)) throw TypeError(tryToString(sym) + ' is not a symbol');
  13. if (hasOwn(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];
  14. }
  15. });