You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

726 lines
24 KiB

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