generate-name.js 791 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. var d = require("d");
  3. var create = Object.create, defineProperty = Object.defineProperty, objPrototype = Object.prototype;
  4. var created = create(null);
  5. module.exports = function (desc) {
  6. var postfix = 0, name, ie11BugWorkaround;
  7. while (created[desc + (postfix || "")]) ++postfix;
  8. desc += postfix || "";
  9. created[desc] = true;
  10. name = "@@" + desc;
  11. defineProperty(
  12. objPrototype,
  13. name,
  14. d.gs(null, function (value) {
  15. // For IE11 issue see:
  16. // https://connect.microsoft.com/IE/feedbackdetail/view/1928508/
  17. // ie11-broken-getters-on-dom-objects
  18. // https://github.com/medikoo/es6-symbol/issues/12
  19. if (ie11BugWorkaround) return;
  20. ie11BugWorkaround = true;
  21. defineProperty(this, name, d(value));
  22. ie11BugWorkaround = false;
  23. })
  24. );
  25. return name;
  26. };