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