es.symbol.key-for.js 758 B

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