UNPKG

1.01 kBJavaScriptView Raw
1// This method of obtaining a reference to the global object needs to be
2// kept identical to the way it is obtained in runtime.js
3var g =
4 typeof global === "object" ? global :
5 typeof window === "object" ? window :
6 typeof self === "object" ? self : this;
7
8// Use `getOwnPropertyNames` because not all browsers support calling
9// `hasOwnProperty` on the global `self` object in a worker. See #183.
10var hadRuntime = g.regeneratorRuntime &&
11 Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime") >= 0;
12
13// Save the old regeneratorRuntime in case it needs to be restored later.
14var oldRuntime = hadRuntime && g.regeneratorRuntime;
15
16// Force reevalutation of runtime.js.
17g.regeneratorRuntime = undefined;
18
19module.exports = require("./runtime");
20
21if (hadRuntime) {
22 // Restore the original runtime.
23 g.regeneratorRuntime = oldRuntime;
24} else {
25 // Remove the global property added by runtime.js.
26 try {
27 delete g.regeneratorRuntime;
28 } catch(e) {
29 g.regeneratorRuntime = undefined;
30 }
31}