runtime.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /**
  2. * Copyright (c) 2014, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * https://raw.github.com/facebook/regenerator/master/LICENSE file. An
  7. * additional grant of patent rights can be found in the PATENTS file in
  8. * the same directory.
  9. */
  10. !(function(global) {
  11. "use strict";
  12. var Op = Object.prototype;
  13. var hasOwn = Op.hasOwnProperty;
  14. var undefined; // More compressible than void 0.
  15. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  16. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  17. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  18. var inModule = typeof module === "object";
  19. var runtime = global.regeneratorRuntime;
  20. if (runtime) {
  21. if (inModule) {
  22. // If regeneratorRuntime is defined globally and we're in a module,
  23. // make the exports object identical to regeneratorRuntime.
  24. module.exports = runtime;
  25. }
  26. // Don't bother evaluating the rest of this file if the runtime was
  27. // already defined globally.
  28. return;
  29. }
  30. // Define the runtime globally (as expected by generated code) as either
  31. // module.exports (if we're in a module) or a new, empty object.
  32. runtime = global.regeneratorRuntime = inModule ? module.exports : {};
  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. runtime.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. 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 = Gp.constructor = GeneratorFunctionPrototype;
  93. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  94. GeneratorFunctionPrototype[toStringTagSymbol] =
  95. GeneratorFunction.displayName = "GeneratorFunction";
  96. // Helper for defining the .next, .throw, and .return methods of the
  97. // Iterator interface in terms of a single ._invoke method.
  98. function defineIteratorMethods(prototype) {
  99. ["next", "throw", "return"].forEach(function(method) {
  100. prototype[method] = function(arg) {
  101. return this._invoke(method, arg);
  102. };
  103. });
  104. }
  105. runtime.isGeneratorFunction = function(genFun) {
  106. var ctor = typeof genFun === "function" && genFun.constructor;
  107. return ctor
  108. ? ctor === GeneratorFunction ||
  109. // For the native GeneratorFunction constructor, the best we can
  110. // do is to check its .name property.
  111. (ctor.displayName || ctor.name) === "GeneratorFunction"
  112. : false;
  113. };
  114. runtime.mark = function(genFun) {
  115. if (Object.setPrototypeOf) {
  116. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  117. } else {
  118. genFun.__proto__ = GeneratorFunctionPrototype;
  119. if (!(toStringTagSymbol in genFun)) {
  120. genFun[toStringTagSymbol] = "GeneratorFunction";
  121. }
  122. }
  123. genFun.prototype = Object.create(Gp);
  124. return genFun;
  125. };
  126. // Within the body of any async function, `await x` is transformed to
  127. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  128. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  129. // meant to be awaited.
  130. runtime.awrap = function(arg) {
  131. return { __await: arg };
  132. };
  133. function AsyncIterator(generator) {
  134. function invoke(method, arg, resolve, reject) {
  135. var record = tryCatch(generator[method], generator, arg);
  136. if (record.type === "throw") {
  137. reject(record.arg);
  138. } else {
  139. var result = record.arg;
  140. var value = result.value;
  141. if (value &&
  142. typeof value === "object" &&
  143. hasOwn.call(value, "__await")) {
  144. return Promise.resolve(value.__await).then(function(value) {
  145. invoke("next", value, resolve, reject);
  146. }, function(err) {
  147. invoke("throw", err, resolve, reject);
  148. });
  149. }
  150. return Promise.resolve(value).then(function(unwrapped) {
  151. // When a yielded Promise is resolved, its final value becomes
  152. // the .value of the Promise<{value,done}> result for the
  153. // current iteration. If the Promise is rejected, however, the
  154. // result for this iteration will be rejected with the same
  155. // reason. Note that rejections of yielded Promises are not
  156. // thrown back into the generator function, as is the case
  157. // when an awaited Promise is rejected. This difference in
  158. // behavior between yield and await is important, because it
  159. // allows the consumer to decide what to do with the yielded
  160. // rejection (swallow it and continue, manually .throw it back
  161. // into the generator, abandon iteration, whatever). With
  162. // await, by contrast, there is no opportunity to examine the
  163. // rejection reason outside the generator function, so the
  164. // only option is to throw it from the await expression, and
  165. // let the generator function handle the exception.
  166. result.value = unwrapped;
  167. resolve(result);
  168. }, reject);
  169. }
  170. }
  171. if (typeof process === "object" && process.domain) {
  172. invoke = process.domain.bind(invoke);
  173. }
  174. var previousPromise;
  175. function enqueue(method, arg) {
  176. function callInvokeWithMethodAndArg() {
  177. return new Promise(function(resolve, reject) {
  178. invoke(method, arg, resolve, reject);
  179. });
  180. }
  181. return previousPromise =
  182. // If enqueue has been called before, then we want to wait until
  183. // all previous Promises have been resolved before calling invoke,
  184. // so that results are always delivered in the correct order. If
  185. // enqueue has not been called before, then it is important to
  186. // call invoke immediately, without waiting on a callback to fire,
  187. // so that the async generator function has the opportunity to do
  188. // any necessary setup in a predictable way. This predictability
  189. // is why the Promise constructor synchronously invokes its
  190. // executor callback, and why async functions synchronously
  191. // execute code before the first await. Since we implement simple
  192. // async functions in terms of async generators, it is especially
  193. // important to get this right, even though it requires care.
  194. previousPromise ? previousPromise.then(
  195. callInvokeWithMethodAndArg,
  196. // Avoid propagating failures to Promises returned by later
  197. // invocations of the iterator.
  198. callInvokeWithMethodAndArg
  199. ) : callInvokeWithMethodAndArg();
  200. }
  201. // Define the unified helper method that is used to implement .next,
  202. // .throw, and .return (see defineIteratorMethods).
  203. this._invoke = enqueue;
  204. }
  205. defineIteratorMethods(AsyncIterator.prototype);
  206. runtime.AsyncIterator = AsyncIterator;
  207. // Note that simple async functions are implemented on top of
  208. // AsyncIterator objects; they just return a Promise for the value of
  209. // the final result produced by the iterator.
  210. runtime.async = function(innerFn, outerFn, self, tryLocsList) {
  211. var iter = new AsyncIterator(
  212. wrap(innerFn, outerFn, self, tryLocsList)
  213. );
  214. return runtime.isGeneratorFunction(outerFn)
  215. ? iter // If outerFn is a generator, return the full iterator.
  216. : iter.next().then(function(result) {
  217. return result.done ? result.value : iter.next();
  218. });
  219. };
  220. function makeInvokeMethod(innerFn, self, context) {
  221. var state = GenStateSuspendedStart;
  222. return function invoke(method, arg) {
  223. if (state === GenStateExecuting) {
  224. throw new Error("Generator is already running");
  225. }
  226. if (state === GenStateCompleted) {
  227. if (method === "throw") {
  228. throw arg;
  229. }
  230. // Be forgiving, per 25.3.3.3.3 of the spec:
  231. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  232. return doneResult();
  233. }
  234. context.method = method;
  235. context.arg = arg;
  236. while (true) {
  237. var delegate = context.delegate;
  238. if (delegate) {
  239. var delegateResult = maybeInvokeDelegate(delegate, context);
  240. if (delegateResult) {
  241. if (delegateResult === ContinueSentinel) continue;
  242. return delegateResult;
  243. }
  244. }
  245. if (context.method === "next") {
  246. // Setting context._sent for legacy support of Babel's
  247. // function.sent implementation.
  248. context.sent = context._sent = context.arg;
  249. } else if (context.method === "throw") {
  250. if (state === GenStateSuspendedStart) {
  251. state = GenStateCompleted;
  252. throw context.arg;
  253. }
  254. context.dispatchException(context.arg);
  255. } else if (context.method === "return") {
  256. context.abrupt("return", context.arg);
  257. }
  258. state = GenStateExecuting;
  259. var record = tryCatch(innerFn, self, context);
  260. if (record.type === "normal") {
  261. // If an exception is thrown from innerFn, we leave state ===
  262. // GenStateExecuting and loop back for another invocation.
  263. state = context.done
  264. ? GenStateCompleted
  265. : GenStateSuspendedYield;
  266. if (record.arg === ContinueSentinel) {
  267. continue;
  268. }
  269. return {
  270. value: record.arg,
  271. done: context.done
  272. };
  273. } else if (record.type === "throw") {
  274. state = GenStateCompleted;
  275. // Dispatch the exception by looping back around to the
  276. // context.dispatchException(context.arg) call above.
  277. context.method = "throw";
  278. context.arg = record.arg;
  279. }
  280. }
  281. };
  282. }
  283. // Call delegate.iterator[context.method](context.arg) and handle the
  284. // result, either by returning a { value, done } result from the
  285. // delegate iterator, or by modifying context.method and context.arg,
  286. // setting context.delegate to null, and returning the ContinueSentinel.
  287. function maybeInvokeDelegate(delegate, context) {
  288. var method = delegate.iterator[context.method];
  289. if (method === undefined) {
  290. // A .throw or .return when the delegate iterator has no .throw
  291. // method always terminates the yield* loop.
  292. context.delegate = null;
  293. if (context.method === "throw") {
  294. if (delegate.iterator.return) {
  295. // If the delegate iterator has a return method, give it a
  296. // chance to clean up.
  297. context.method = "return";
  298. context.arg = undefined;
  299. maybeInvokeDelegate(delegate, context);
  300. if (context.method === "throw") {
  301. // If maybeInvokeDelegate(context) changed context.method from
  302. // "return" to "throw", let that override the TypeError below.
  303. return ContinueSentinel;
  304. }
  305. }
  306. context.method = "throw";
  307. context.arg = new TypeError(
  308. "The iterator does not provide a 'throw' method");
  309. }
  310. return ContinueSentinel;
  311. }
  312. var record = tryCatch(method, delegate.iterator, context.arg);
  313. if (record.type === "throw") {
  314. context.method = "throw";
  315. context.arg = record.arg;
  316. context.delegate = null;
  317. return ContinueSentinel;
  318. }
  319. var info = record.arg;
  320. if (! info) {
  321. context.method = "throw";
  322. context.arg = new TypeError("iterator result is not an object");
  323. context.delegate = null;
  324. return ContinueSentinel;
  325. }
  326. if (info.done) {
  327. // Assign the result of the finished delegate to the temporary
  328. // variable specified by delegate.resultName (see delegateYield).
  329. context[delegate.resultName] = info.value;
  330. // Resume execution at the desired location (see delegateYield).
  331. context.next = delegate.nextLoc;
  332. // If context.method was "throw" but the delegate handled the
  333. // exception, let the outer generator proceed normally. If
  334. // context.method was "next", forget context.arg since it has been
  335. // "consumed" by the delegate iterator. If context.method was
  336. // "return", allow the original .return call to continue in the
  337. // outer generator.
  338. if (context.method !== "return") {
  339. context.method = "next";
  340. context.arg = undefined;
  341. }
  342. } else {
  343. // Re-yield the result returned by the delegate method.
  344. return info;
  345. }
  346. // The delegate iterator is finished, so forget it and continue with
  347. // the outer generator.
  348. context.delegate = null;
  349. return ContinueSentinel;
  350. }
  351. // Define Generator.prototype.{next,throw,return} in terms of the
  352. // unified ._invoke helper method.
  353. defineIteratorMethods(Gp);
  354. Gp[toStringTagSymbol] = "Generator";
  355. Gp.toString = function() {
  356. return "[object Generator]";
  357. };
  358. function pushTryEntry(locs) {
  359. var entry = { tryLoc: locs[0] };
  360. if (1 in locs) {
  361. entry.catchLoc = locs[1];
  362. }
  363. if (2 in locs) {
  364. entry.finallyLoc = locs[2];
  365. entry.afterLoc = locs[3];
  366. }
  367. this.tryEntries.push(entry);
  368. }
  369. function resetTryEntry(entry) {
  370. var record = entry.completion || {};
  371. record.type = "normal";
  372. delete record.arg;
  373. entry.completion = record;
  374. }
  375. function Context(tryLocsList) {
  376. // The root entry object (effectively a try statement without a catch
  377. // or a finally block) gives us a place to store values thrown from
  378. // locations where there is no enclosing try statement.
  379. this.tryEntries = [{ tryLoc: "root" }];
  380. tryLocsList.forEach(pushTryEntry, this);
  381. this.reset(true);
  382. }
  383. runtime.keys = function(object) {
  384. var keys = [];
  385. for (var key in object) {
  386. keys.push(key);
  387. }
  388. keys.reverse();
  389. // Rather than returning an object with a next method, we keep
  390. // things simple and return the next function itself.
  391. return function next() {
  392. while (keys.length) {
  393. var key = keys.pop();
  394. if (key in object) {
  395. next.value = key;
  396. next.done = false;
  397. return next;
  398. }
  399. }
  400. // To avoid creating an additional object, we just hang the .value
  401. // and .done properties off the next function object itself. This
  402. // also ensures that the minifier will not anonymize the function.
  403. next.done = true;
  404. return next;
  405. };
  406. };
  407. function values(iterable) {
  408. if (iterable) {
  409. var iteratorMethod = iterable[iteratorSymbol];
  410. if (iteratorMethod) {
  411. return iteratorMethod.call(iterable);
  412. }
  413. if (typeof iterable.next === "function") {
  414. return iterable;
  415. }
  416. if (!isNaN(iterable.length)) {
  417. var i = -1, next = function next() {
  418. while (++i < iterable.length) {
  419. if (hasOwn.call(iterable, i)) {
  420. next.value = iterable[i];
  421. next.done = false;
  422. return next;
  423. }
  424. }
  425. next.value = undefined;
  426. next.done = true;
  427. return next;
  428. };
  429. return next.next = next;
  430. }
  431. }
  432. // Return an iterator with no values.
  433. return { next: doneResult };
  434. }
  435. runtime.values = values;
  436. function doneResult() {
  437. return { value: undefined, done: true };
  438. }
  439. Context.prototype = {
  440. constructor: Context,
  441. reset: function(skipTempReset) {
  442. this.prev = 0;
  443. this.next = 0;
  444. // Resetting context._sent for legacy support of Babel's
  445. // function.sent implementation.
  446. this.sent = this._sent = undefined;
  447. this.done = false;
  448. this.delegate = null;
  449. this.method = "next";
  450. this.arg = undefined;
  451. this.tryEntries.forEach(resetTryEntry);
  452. if (!skipTempReset) {
  453. for (var name in this) {
  454. // Not sure about the optimal order of these conditions:
  455. if (name.charAt(0) === "t" &&
  456. hasOwn.call(this, name) &&
  457. !isNaN(+name.slice(1))) {
  458. this[name] = undefined;
  459. }
  460. }
  461. }
  462. },
  463. stop: function() {
  464. this.done = true;
  465. var rootEntry = this.tryEntries[0];
  466. var rootRecord = rootEntry.completion;
  467. if (rootRecord.type === "throw") {
  468. throw rootRecord.arg;
  469. }
  470. return this.rval;
  471. },
  472. dispatchException: function(exception) {
  473. if (this.done) {
  474. throw exception;
  475. }
  476. var context = this;
  477. function handle(loc, caught) {
  478. record.type = "throw";
  479. record.arg = exception;
  480. context.next = loc;
  481. if (caught) {
  482. // If the dispatched exception was caught by a catch block,
  483. // then let that catch block handle the exception normally.
  484. context.method = "next";
  485. context.arg = undefined;
  486. }
  487. return !! caught;
  488. }
  489. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  490. var entry = this.tryEntries[i];
  491. var record = entry.completion;
  492. if (entry.tryLoc === "root") {
  493. // Exception thrown outside of any try block that could handle
  494. // it, so set the completion value of the entire function to
  495. // throw the exception.
  496. return handle("end");
  497. }
  498. if (entry.tryLoc <= this.prev) {
  499. var hasCatch = hasOwn.call(entry, "catchLoc");
  500. var hasFinally = hasOwn.call(entry, "finallyLoc");
  501. if (hasCatch && hasFinally) {
  502. if (this.prev < entry.catchLoc) {
  503. return handle(entry.catchLoc, true);
  504. } else if (this.prev < entry.finallyLoc) {
  505. return handle(entry.finallyLoc);
  506. }
  507. } else if (hasCatch) {
  508. if (this.prev < entry.catchLoc) {
  509. return handle(entry.catchLoc, true);
  510. }
  511. } else if (hasFinally) {
  512. if (this.prev < entry.finallyLoc) {
  513. return handle(entry.finallyLoc);
  514. }
  515. } else {
  516. throw new Error("try statement without catch or finally");
  517. }
  518. }
  519. }
  520. },
  521. abrupt: function(type, arg) {
  522. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  523. var entry = this.tryEntries[i];
  524. if (entry.tryLoc <= this.prev &&
  525. hasOwn.call(entry, "finallyLoc") &&
  526. this.prev < entry.finallyLoc) {
  527. var finallyEntry = entry;
  528. break;
  529. }
  530. }
  531. if (finallyEntry &&
  532. (type === "break" ||
  533. type === "continue") &&
  534. finallyEntry.tryLoc <= arg &&
  535. arg <= finallyEntry.finallyLoc) {
  536. // Ignore the finally entry if control is not jumping to a
  537. // location outside the try/catch block.
  538. finallyEntry = null;
  539. }
  540. var record = finallyEntry ? finallyEntry.completion : {};
  541. record.type = type;
  542. record.arg = arg;
  543. if (finallyEntry) {
  544. this.method = "next";
  545. this.next = finallyEntry.finallyLoc;
  546. return ContinueSentinel;
  547. }
  548. return this.complete(record);
  549. },
  550. complete: function(record, afterLoc) {
  551. if (record.type === "throw") {
  552. throw record.arg;
  553. }
  554. if (record.type === "break" ||
  555. record.type === "continue") {
  556. this.next = record.arg;
  557. } else if (record.type === "return") {
  558. this.rval = this.arg = record.arg;
  559. this.method = "return";
  560. this.next = "end";
  561. } else if (record.type === "normal" && afterLoc) {
  562. this.next = afterLoc;
  563. }
  564. return ContinueSentinel;
  565. },
  566. finish: function(finallyLoc) {
  567. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  568. var entry = this.tryEntries[i];
  569. if (entry.finallyLoc === finallyLoc) {
  570. this.complete(entry.completion, entry.afterLoc);
  571. resetTryEntry(entry);
  572. return ContinueSentinel;
  573. }
  574. }
  575. },
  576. "catch": function(tryLoc) {
  577. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  578. var entry = this.tryEntries[i];
  579. if (entry.tryLoc === tryLoc) {
  580. var record = entry.completion;
  581. if (record.type === "throw") {
  582. var thrown = record.arg;
  583. resetTryEntry(entry);
  584. }
  585. return thrown;
  586. }
  587. }
  588. // The context.catch method must only be called with a location
  589. // argument that corresponds to a known catch block.
  590. throw new Error("illegal catch attempt");
  591. },
  592. delegateYield: function(iterable, resultName, nextLoc) {
  593. this.delegate = {
  594. iterator: values(iterable),
  595. resultName: resultName,
  596. nextLoc: nextLoc
  597. };
  598. if (this.method === "next") {
  599. // Deliberately forget the last sent value so that we don't
  600. // accidentally pass it on to the delegate.
  601. this.arg = undefined;
  602. }
  603. return ContinueSentinel;
  604. }
  605. };
  606. })(
  607. // Among the various tricks for obtaining a reference to the global
  608. // object, this seems to be the most reliable technique that does not
  609. // use indirect eval (which violates Content Security Policy).
  610. typeof global === "object" ? global :
  611. typeof window === "object" ? window :
  612. typeof self === "object" ? self : this
  613. );