runtime-module.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Copyright (c) 2014-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. // This method of obtaining a reference to the global object needs to be
  8. // kept identical to the way it is obtained in runtime.js
  9. var g = (function() { return this })() || Function("return this")();
  10. // Use `getOwnPropertyNames` because not all browsers support calling
  11. // `hasOwnProperty` on the global `self` object in a worker. See #183.
  12. var hadRuntime = g.regeneratorRuntime &&
  13. Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime") >= 0;
  14. // Save the old regeneratorRuntime in case it needs to be restored later.
  15. var oldRuntime = hadRuntime && g.regeneratorRuntime;
  16. // Force reevalutation of runtime.js.
  17. g.regeneratorRuntime = undefined;
  18. module.exports = require("./runtime");
  19. if (hadRuntime) {
  20. // Restore the original runtime.
  21. g.regeneratorRuntime = oldRuntime;
  22. } else {
  23. // Remove the global property added by runtime.js.
  24. try {
  25. delete g.regeneratorRuntime;
  26. } catch(e) {
  27. g.regeneratorRuntime = undefined;
  28. }
  29. }