runtime.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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. var runtime = (function (exports) {
  8. "use strict";
  9. var Op = Object.prototype;
  10. var hasOwn = Op.hasOwnProperty;
  11. var undefined; // More compressible than void 0.
  12. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  13. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  14. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  15. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  16. function define(obj, key, value) {
  17. Object.defineProperty(obj, key, {
  18. value: value,
  19. enumerable: true,
  20. configurable: true,
  21. writable: true
  22. });
  23. return obj[key];
  24. }
  25. try {
  26. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  27. define({}, "");
  28. } catch (err) {
  29. define = function(obj, key, value) {
  30. return obj[key] = value;
  31. };
  32. }
  33. function wrap(innerFn, outerFn, self, tryLocsList) {
  34. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  35. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  36. var generator = Object.create(protoGenerator.prototype);
  37. var context = new Context(tryLocsList || []);
  38. // The ._invoke method unifies the implementations of the .next,
  39. // .throw, and .return methods.
  40. generator._invoke = makeInvokeMethod(innerFn, self, context);
  41. return generator;
  42. }
  43. exports.wrap = wrap;
  44. // Try/catch helper to minimize deoptimizations. Returns a completion
  45. // record like context.tryEntries[i].completion. This interface could
  46. // have been (and was previously) designed to take a closure to be
  47. // invoked without arguments, but in all the cases we care about we
  48. // already have an existing method we want to call, so there's no need
  49. // to create a new function object. We can even get away with assuming
  50. // the method takes exactly one argument, since that happens to be true
  51. // in every case, so we don't have to touch the arguments object. The
  52. // only additional allocation required is the completion record, which
  53. // has a stable shape and so hopefully should be cheap to allocate.
  54. function tryCatch(fn, obj, arg) {
  55. try {
  56. return { type: "normal", arg: fn.call(obj, arg) };
  57. } catch (err) {
  58. return { type: "throw", arg: err };
  59. }
  60. }
  61. var GenStateSuspendedStart = "suspendedStart";
  62. var GenStateSuspendedYield = "suspendedYield";
  63. var GenStateExecuting = "executing";
  64. var GenStateCompleted = "completed";
  65. // Returning this object from the innerFn has the same effect as
  66. // breaking out of the dispatch switch statement.
  67. var ContinueSentinel = {};
  68. // Dummy constructor functions that we use as the .constructor and
  69. // .constructor.prototype properties for functions that return Generator
  70. // objects. For full spec compliance, you may wish to configure your
  71. // minifier not to mangle the names of these two functions.
  72. function Generator() {}
  73. function GeneratorFunction() {}
  74. function GeneratorFunctionPrototype() {}
  75. // This is a polyfill for %IteratorPrototype% for environments that
  76. // don't natively support it.
  77. var IteratorPrototype = {};
  78. define(IteratorPrototype, iteratorSymbol, function () {
  79. return this;
  80. });
  81. var getProto = Object.getPrototypeOf;
  82. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  83. if (NativeIteratorPrototype &&
  84. NativeIteratorPrototype !== Op &&
  85. hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  86. // This environment has a native %IteratorPrototype%; use it instead
  87. // of the polyfill.
  88. IteratorPrototype = NativeIteratorPrototype;
  89. }
  90. var Gp = GeneratorFunctionPrototype.prototype =
  91. Generator.prototype = Object.create(IteratorPrototype);
  92. GeneratorFunction.prototype = GeneratorFunctionPrototype;
  93. define(Gp, "constructor", GeneratorFunctionPrototype);
  94. define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
  95. GeneratorFunction.displayName = define(
  96. GeneratorFunctionPrototype,
  97. toStringTagSymbol,
  98. "GeneratorFunction"
  99. );
  100. // Helper for defining the .next, .throw, and .return methods of the
  101. // Iterator interface in terms of a single ._invoke method.
  102. function defineIteratorMethods(prototype) {
  103. ["next", "throw", "return"].forEach(function(method) {
  104. define(prototype, method, function(arg) {
  105. return this._invoke(method, arg);
  106. });
  107. });
  108. }
  109. exports.isGeneratorFunction = function(genFun) {
  110. var ctor = typeof genFun === "function" && genFun.constructor;
  111. return ctor
  112. ? ctor === GeneratorFunction ||
  113. // For the native GeneratorFunction constructor, the best we can
  114. // do is to check its .name property.
  115. (ctor.displayName || ctor.name) === "GeneratorFunction"
  116. : false;
  117. };
  118. exports.mark = function(genFun) {
  119. if (Object.setPrototypeOf) {
  120. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  121. } else {
  122. genFun.__proto__ = GeneratorFunctionPrototype;
  123. define(genFun, toStringTagSymbol, "GeneratorFunction");
  124. }
  125. genFun.prototype = Object.create(Gp);
  126. return genFun;
  127. };
  128. // Within the body of any async function, `await x` is transformed to
  129. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  130. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  131. // meant to be awaited.
  132. exports.awrap = function(arg) {
  133. return { __await: arg };
  134. };
  135. function AsyncIterator(generator, PromiseImpl) {
  136. function invoke(method, arg, resolve, reject) {
  137. var record = tryCatch(generator[method], generator, arg);
  138. if (record.type === "throw") {
  139. reject(record.arg);
  140. } else {
  141. var result = record.arg;
  142. var value = result.value;
  143. if (value &&
  144. typeof value === "object" &&
  145. hasOwn.call(value, "__await")) {
  146. return PromiseImpl.resolve(value.__await).then(function(value) {
  147. invoke("next", value, resolve, reject);
  148. }, function(err) {
  149. invoke("throw", err, resolve, reject);
  150. });
  151. }
  152. return PromiseImpl.resolve(value).then(function(unwrapped) {
  153. // When a yielded Promise is resolved, its final value becomes
  154. // the .value of the Promise<{value,done}> result for the
  155. // current iteration.
  156. result.value = unwrapped;
  157. resolve(result);
  158. }, function(error) {
  159. // If a rejected Promise was yielded, throw the rejection back
  160. // into the async generator function so it can be handled there.
  161. return invoke("throw", error, resolve, reject);
  162. });
  163. }
  164. }
  165. var previousPromise;
  166. function enqueue(method, arg) {
  167. function callInvokeWithMethodAndArg() {
  168. return new PromiseImpl(function(resolve, reject) {
  169. invoke(method, arg, resolve, reject);
  170. });
  171. }
  172. return previousPromise =
  173. // If enqueue has been called before, then we want to wait until
  174. // all previous Promises have been resolved before calling invoke,
  175. // so that results are always delivered in the correct order. If
  176. // enqueue has not been called before, then it is important to
  177. // call invoke immediately, without waiting on a callback to fire,
  178. // so that the async generator function has the opportunity to do
  179. // any necessary setup in a predictable way. This predictability
  180. // is why the Promise constructor synchronously invokes its
  181. // executor callback, and why async functions synchronously
  182. // execute code before the first await. Since we implement simple
  183. // async functions in terms of async generators, it is especially
  184. // important to get this right, even though it requires care.
  185. previousPromise ? previousPromise.then(
  186. callInvokeWithMethodAndArg,
  187. // Avoid propagating failures to Promises returned by later
  188. // invocations of the iterator.
  189. callInvokeWithMethodAndArg
  190. ) : callInvokeWithMethodAndArg();
  191. }
  192. // Define the unified helper method that is used to implement .next,
  193. // .throw, and .return (see defineIteratorMethods).
  194. this._invoke = enqueue;
  195. }
  196. defineIteratorMethods(AsyncIterator.prototype);
  197. define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  198. return this;
  199. });
  200. exports.AsyncIterator = AsyncIterator;
  201. // Note that simple async functions are implemented on top of
  202. // AsyncIterator objects; they just return a Promise for the value of
  203. // the final result produced by the iterator.
  204. exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  205. if (PromiseImpl === void 0) PromiseImpl = Promise;
  206. var iter = new AsyncIterator(
  207. wrap(innerFn, outerFn, self, tryLocsList),
  208. PromiseImpl
  209. );
  210. return exports.isGeneratorFunction(outerFn)
  211. ? iter // If outerFn is a generator, return the full iterator.
  212. : iter.next().then(function(result) {
  213. return result.done ? result.value : iter.next();
  214. });
  215. };
  216. function makeInvokeMethod(innerFn, self, context) {
  217. var state = GenStateSuspendedStart;
  218. return function invoke(method, arg) {
  219. if (state === GenStateExecuting) {
  220. throw new Error("Generator is already running");
  221. }
  222. if (state === GenStateCompleted) {
  223. if (method === "throw") {
  224. throw arg;
  225. }
  226. // Be forgiving, per 25.3.3.3.3 of the spec:
  227. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  228. return doneResult();
  229. }
  230. context.method = method;
  231. context.arg = arg;
  232. while (true) {
  233. var delegate = context.delegate;
  234. if (delegate) {
  235. var delegateResult = maybeInvokeDelegate(delegate, context);
  236. if (delegateResult) {
  237. if (delegateResult === ContinueSentinel) continue;
  238. return delegateResult;
  239. }
  240. }
  241. if (context.method === "next") {
  242. // Setting context._sent for legacy support of Babel's
  243. // function.sent implementation.
  244. context.sent = context._sent = context.arg;
  245. } else if (context.method === "throw") {
  246. if (state === GenStateSuspendedStart) {
  247. state = GenStateCompleted;
  248. throw context.arg;
  249. }
  250. context.dispatchException(context.arg);
  251. } else if (context.method === "return") {
  252. context.abrupt("return", context.arg);
  253. }
  254. state = GenStateExecuting;
  255. var record = tryCatch(innerFn, self, context);
  256. if (record.type === "normal") {
  257. // If an exception is thrown from innerFn, we leave state ===
  258. // GenStateExecuting and loop back for another invocation.
  259. state = context.done
  260. ? GenStateCompleted
  261. : GenStateSuspendedYield;
  262. if (record.arg === ContinueSentinel) {
  263. continue;
  264. }
  265. return {
  266. value: record.arg,
  267. done: context.done
  268. };
  269. } else if (record.type === "throw") {
  270. state = GenStateCompleted;
  271. // Dispatch the exception by looping back around to the
  272. // context.dispatchException(context.arg) call above.
  273. context.method = "throw";
  274. context.arg = record.arg;
  275. }
  276. }
  277. };
  278. }
  279. // Call delegate.iterator[context.method](context.arg) and handle the
  280. // result, either by returning a { value, done } result from the
  281. // delegate iterator, or by modifying context.method and context.arg,
  282. // setting context.delegate to null, and returning the ContinueSentinel.
  283. function maybeInvokeDelegate(delegate, context) {
  284. var method = delegate.iterator[context.method];
  285. if (method === undefined) {
  286. // A .throw or .return when the delegate iterator has no .throw
  287. // method always terminates the yield* loop.
  288. context.delegate = null;
  289. if (context.method === "throw") {
  290. // Note: ["return"] must be used for ES3 parsing compatibility.
  291. if (delegate.iterator["return"]) {
  292. // If the delegate iterator has a return method, give it a
  293. // chance to clean up.
  294. context.method = "return";
  295. context.arg = undefined;
  296. maybeInvokeDelegate(delegate, context);
  297. if (context.method === "throw") {
  298. // If maybeInvokeDelegate(context) changed context.method from
  299. // "return" to "throw", let that override the TypeError below.
  300. return ContinueSentinel;
  301. }
  302. }
  303. context.method = "throw";
  304. context.arg = new TypeError(
  305. "The iterator does not provide a 'throw' method");
  306. }
  307. return ContinueSentinel;
  308. }
  309. var record = tryCatch(method, delegate.iterator, context.arg);
  310. if (record.type === "throw") {
  311. context.method = "throw";
  312. context.arg = record.arg;
  313. context.delegate = null;
  314. return ContinueSentinel;
  315. }
  316. var info = record.arg;
  317. if (! info) {
  318. context.method = "throw";
  319. context.arg = new TypeError("iterator result is not an object");
  320. context.delegate = null;
  321. return ContinueSentinel;
  322. }
  323. if (info.done) {
  324. // Assign the result of the finished delegate to the temporary
  325. // variable specified by delegate.resultName (see delegateYield).
  326. context[delegate.resultName] = info.value;
  327. // Resume execution at the desired location (see delegateYield).
  328. context.next = delegate.nextLoc;
  329. // If context.method was "throw" but the delegate handled the
  330. // exception, let the outer generator proceed normally. If
  331. // context.method was "next", forget context.arg since it has been
  332. // "consumed" by the delegate iterator. If context.method was
  333. // "return", allow the original .return call to continue in the
  334. // outer generator.
  335. if (context.method !== "return") {
  336. context.method = "next";
  337. context.arg = undefined;
  338. }
  339. } else {
  340. // Re-yield the result returned by the delegate method.
  341. return info;
  342. }
  343. // The delegate iterator is finished, so forget it and continue with
  344. // the outer generator.
  345. context.delegate = null;
  346. return ContinueSentinel;
  347. }
  348. // Define Generator.prototype.{next,throw,return} in terms of the
  349. // unified ._invoke helper method.
  350. defineIteratorMethods(Gp);
  351. define(Gp, toStringTagSymbol, "Generator");
  352. // A Generator should always return itself as the iterator object when the
  353. // @@iterator function is called on it. Some browsers' implementations of the
  354. // iterator prototype chain incorrectly implement this, causing the Generator
  355. // object to not be returned from this call. This ensures that doesn't happen.
  356. // See https://github.com/facebook/regenerator/issues/274 for more details.
  357. define(Gp, iteratorSymbol, function() {
  358. return this;
  359. });
  360. define(Gp, "toString", function() {
  361. return "[object Generator]";
  362. });
  363. function pushTryEntry(locs) {
  364. var entry = { tryLoc: locs[0] };
  365. if (1 in locs) {
  366. entry.catchLoc = locs[1];
  367. }
  368. if (2 in locs) {
  369. entry.finallyLoc = locs[2];
  370. entry.afterLoc = locs[3];
  371. }
  372. this.tryEntries.push(entry);
  373. }
  374. function resetTryEntry(entry) {
  375. var record = entry.completion || {};
  376. record.type = "normal";
  377. delete record.arg;
  378. entry.completion = record;
  379. }
  380. function Context(tryLocsList) {
  381. // The root entry object (effectively a try statement without a catch
  382. // or a finally block) gives us a place to store values thrown from
  383. // locations where there is no enclosing try statement.
  384. this.tryEntries = [{ tryLoc: "root" }];
  385. tryLocsList.forEach(pushTryEntry, this);
  386. this.reset(true);
  387. }
  388. exports.keys = function(object) {
  389. var keys = [];
  390. for (var key in object) {
  391. keys.push(key);
  392. }
  393. keys.reverse();
  394. // Rather than returning an object with a next method, we keep
  395. // things simple and return the next function itself.
  396. return function next() {
  397. while (keys.length) {
  398. var key = keys.pop();
  399. if (key in object) {
  400. next.value = key;
  401. next.done = false;
  402. return next;
  403. }
  404. }
  405. // To avoid creating an additional object, we just hang the .value
  406. // and .done properties off the next function object itself. This
  407. // also ensures that the minifier will not anonymize the function.
  408. next.done = true;
  409. return next;
  410. };
  411. };
  412. function values(iterable) {
  413. if (iterable) {
  414. var iteratorMethod = iterable[iteratorSymbol];
  415. if (iteratorMethod) {
  416. return iteratorMethod.call(iterable);
  417. }
  418. if (typeof iterable.next === "function") {
  419. return iterable;
  420. }
  421. if (!isNaN(iterable.length)) {
  422. var i = -1, next = function next() {
  423. while (++i < iterable.length) {
  424. if (hasOwn.call(iterable, i)) {
  425. next.value = iterable[i];
  426. next.done = false;
  427. return next;
  428. }
  429. }
  430. next.value = undefined;
  431. next.done = true;
  432. return next;
  433. };
  434. return next.next = next;
  435. }
  436. }
  437. // Return an iterator with no values.
  438. return { next: doneResult };
  439. }
  440. exports.values = values;
  441. function doneResult() {
  442. return { value: undefined, done: true };
  443. }
  444. Context.prototype = {
  445. constructor: Context,
  446. reset: function(skipTempReset) {
  447. this.prev = 0;
  448. this.next = 0;
  449. // Resetting context._sent for legacy support of Babel's
  450. // function.sent implementation.
  451. this.sent = this._sent = undefined;
  452. this.done = false;
  453. this.delegate = null;
  454. this.method = "next";
  455. this.arg = undefined;
  456. this.tryEntries.forEach(resetTryEntry);
  457. if (!skipTempReset) {
  458. for (var name in this) {
  459. // Not sure about the optimal order of these conditions:
  460. if (name.charAt(0) === "t" &&
  461. hasOwn.call(this, name) &&
  462. !isNaN(+name.slice(1))) {
  463. this[name] = undefined;
  464. }
  465. }
  466. }
  467. },
  468. stop: function() {
  469. this.done = true;
  470. var rootEntry = this.tryEntries[0];
  471. var rootRecord = rootEntry.completion;
  472. if (rootRecord.type === "throw") {
  473. throw rootRecord.arg;
  474. }
  475. return this.rval;
  476. },
  477. dispatchException: function(exception) {
  478. if (this.done) {
  479. throw exception;
  480. }
  481. var context = this;
  482. function handle(loc, caught) {
  483. record.type = "throw";
  484. record.arg = exception;
  485. context.next = loc;
  486. if (caught) {
  487. // If the dispatched exception was caught by a catch block,
  488. // then let that catch block handle the exception normally.
  489. context.method = "next";
  490. context.arg = undefined;
  491. }
  492. return !! caught;
  493. }
  494. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  495. var entry = this.tryEntries[i];
  496. var record = entry.completion;
  497. if (entry.tryLoc === "root") {
  498. // Exception thrown outside of any try block that could handle
  499. // it, so set the completion value of the entire function to
  500. // throw the exception.
  501. return handle("end");
  502. }
  503. if (entry.tryLoc <= this.prev) {
  504. var hasCatch = hasOwn.call(entry, "catchLoc");
  505. var hasFinally = hasOwn.call(entry, "finallyLoc");
  506. if (hasCatch && hasFinally) {
  507. if (this.prev < entry.catchLoc) {
  508. return handle(entry.catchLoc, true);
  509. } else if (this.prev < entry.finallyLoc) {
  510. return handle(entry.finallyLoc);
  511. }
  512. } else if (hasCatch) {
  513. if (this.prev < entry.catchLoc) {
  514. return handle(entry.catchLoc, true);
  515. }
  516. } else if (hasFinally) {
  517. if (this.prev < entry.finallyLoc) {
  518. return handle(entry.finallyLoc);
  519. }
  520. } else {
  521. throw new Error("try statement without catch or finally");
  522. }
  523. }
  524. }
  525. },
  526. abrupt: function(type, arg) {
  527. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  528. var entry = this.tryEntries[i];
  529. if (entry.tryLoc <= this.prev &&
  530. hasOwn.call(entry, "finallyLoc") &&
  531. this.prev < entry.finallyLoc) {
  532. var finallyEntry = entry;
  533. break;
  534. }
  535. }
  536. if (finallyEntry &&
  537. (type === "break" ||
  538. type === "continue") &&
  539. finallyEntry.tryLoc <= arg &&
  540. arg <= finallyEntry.finallyLoc) {
  541. // Ignore the finally entry if control is not jumping to a
  542. // location outside the try/catch block.
  543. finallyEntry = null;
  544. }
  545. var record = finallyEntry ? finallyEntry.completion : {};
  546. record.type = type;
  547. record.arg = arg;
  548. if (finallyEntry) {
  549. this.method = "next";
  550. this.next = finallyEntry.finallyLoc;
  551. return ContinueSentinel;
  552. }
  553. return this.complete(record);
  554. },
  555. complete: function(record, afterLoc) {
  556. if (record.type === "throw") {
  557. throw record.arg;
  558. }
  559. if (record.type === "break" ||
  560. record.type === "continue") {
  561. this.next = record.arg;
  562. } else if (record.type === "return") {
  563. this.rval = this.arg = record.arg;
  564. this.method = "return";
  565. this.next = "end";
  566. } else if (record.type === "normal" && afterLoc) {
  567. this.next = afterLoc;
  568. }
  569. return ContinueSentinel;
  570. },
  571. finish: function(finallyLoc) {
  572. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  573. var entry = this.tryEntries[i];
  574. if (entry.finallyLoc === finallyLoc) {
  575. this.complete(entry.completion, entry.afterLoc);
  576. resetTryEntry(entry);
  577. return ContinueSentinel;
  578. }
  579. }
  580. },
  581. "catch": function(tryLoc) {
  582. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  583. var entry = this.tryEntries[i];
  584. if (entry.tryLoc === tryLoc) {
  585. var record = entry.completion;
  586. if (record.type === "throw") {
  587. var thrown = record.arg;
  588. resetTryEntry(entry);
  589. }
  590. return thrown;
  591. }
  592. }
  593. // The context.catch method must only be called with a location
  594. // argument that corresponds to a known catch block.
  595. throw new Error("illegal catch attempt");
  596. },
  597. delegateYield: function(iterable, resultName, nextLoc) {
  598. this.delegate = {
  599. iterator: values(iterable),
  600. resultName: resultName,
  601. nextLoc: nextLoc
  602. };
  603. if (this.method === "next") {
  604. // Deliberately forget the last sent value so that we don't
  605. // accidentally pass it on to the delegate.
  606. this.arg = undefined;
  607. }
  608. return ContinueSentinel;
  609. }
  610. };
  611. // Regardless of whether this script is executing as a CommonJS module
  612. // or not, return the runtime object so that we can declare the variable
  613. // regeneratorRuntime in the outer scope, which allows this module to be
  614. // injected easily by `bin/regenerator --include-runtime script.js`.
  615. return exports;
  616. }(
  617. // If this script is executing as a CommonJS module, use module.exports
  618. // as the regeneratorRuntime namespace. Otherwise create a new empty
  619. // object. Either way, the resulting object will be used to initialize
  620. // the regeneratorRuntime variable at the top of this file.
  621. typeof module === "object" ? module.exports : {}
  622. ));
  623. try {
  624. regeneratorRuntime = runtime;
  625. } catch (accidentalStrictMode) {
  626. // This module should not be running in strict mode, so the above
  627. // assignment should always work unless something is misconfigured. Just
  628. // in case runtime.js accidentally runs in strict mode, in modern engines
  629. // we can explicitly access globalThis. In older engines we can escape
  630. // strict mode using a global Function call. This could conceivably fail
  631. // if a Content Security Policy forbids using Function, but in that case
  632. // the proper solution is to fix the accidental strict mode problem. If
  633. // you've misconfigured your bundler to force strict mode and applied a
  634. // CSP to forbid Function, and you're not willing to fix either of those
  635. // problems, please detail your unique predicament in a GitHub issue.
  636. if (typeof globalThis === "object") {
  637. globalThis.regeneratorRuntime = runtime;
  638. } else {
  639. Function("r", "regeneratorRuntime = r")(runtime);
  640. }
  641. }