symbol-registry.js 556 B

1234567891011121314151617181920212223
  1. "use strict";
  2. var d = require("d")
  3. , validateSymbol = require("../../../validate-symbol");
  4. var registry = Object.create(null);
  5. module.exports = function (SymbolPolyfill) {
  6. return Object.defineProperties(SymbolPolyfill, {
  7. for: d(function (key) {
  8. if (registry[key]) return registry[key];
  9. return (registry[key] = SymbolPolyfill(String(key)));
  10. }),
  11. keyFor: d(function (symbol) {
  12. var key;
  13. validateSymbol(symbol);
  14. for (key in registry) {
  15. if (registry[key] === symbol) return key;
  16. }
  17. return undefined;
  18. })
  19. });
  20. };