regenerator-runtime
Advanced tools
Comparing version 0.10.2 to 0.10.3
@@ -5,3 +5,3 @@ { | ||
"description": "Runtime for Regenerator-compiled generator and async functions.", | ||
"version": "0.10.2", | ||
"version": "0.10.3", | ||
"main": "runtime-module.js", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
150
runtime.js
@@ -273,67 +273,7 @@ /** | ||
if (delegate) { | ||
if (context.method === "return" || | ||
(context.method === "throw" && | ||
delegate.iterator[context.method] === undefined)) { | ||
// A return or throw (when the delegate iterator has no throw | ||
// method) always terminates the yield* loop. | ||
context.delegate = null; | ||
// If the delegate iterator has a return method, give it a | ||
// chance to clean up. | ||
var returnMethod = delegate.iterator["return"]; | ||
if (returnMethod) { | ||
var record = tryCatch( | ||
returnMethod, | ||
delegate.iterator, | ||
context.arg | ||
); | ||
if (record.type === "throw") { | ||
// If the return method threw an exception, let that | ||
// exception prevail over the original return or throw. | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
continue; | ||
} | ||
} | ||
if (context.method === "return") { | ||
// Continue with the outer return, now that the delegate | ||
// iterator has been terminated. | ||
continue; | ||
} | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
var record = tryCatch( | ||
delegate.iterator[context.method], | ||
delegate.iterator, | ||
context.arg | ||
); | ||
if (record.type === "throw") { | ||
context.delegate = null; | ||
// Like returning generator.throw(uncaught), but without the | ||
// overhead of an extra function call. | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
continue; | ||
} | ||
// Delegate generator ran and handled its own exceptions so | ||
// regardless of what the method was, we continue as if it is | ||
// "next" with an undefined arg. | ||
context.method = "next"; | ||
context.arg = undefined; | ||
var info = record.arg; | ||
if (info.done) { | ||
context[delegate.resultName] = info.value; | ||
context.next = delegate.nextLoc; | ||
} else { | ||
state = GenStateSuspendedYield; | ||
return info; | ||
} | ||
context.delegate = null; | ||
} | ||
@@ -388,2 +328,84 @@ | ||
// Call delegate.iterator[context.method](context.arg) and handle the | ||
// result, either by returning a { value, done } result from the | ||
// delegate iterator, or by modifying context.method and context.arg, | ||
// setting context.delegate to null, and returning the ContinueSentinel. | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (method === undefined) { | ||
// A .throw or .return when the delegate iterator has no .throw | ||
// method always terminates the yield* loop. | ||
context.delegate = null; | ||
if (context.method === "throw") { | ||
if (delegate.iterator.return) { | ||
// If the delegate iterator has a return method, give it a | ||
// chance to clean up. | ||
context.method = "return"; | ||
context.arg = undefined; | ||
maybeInvokeDelegate(delegate, context); | ||
if (context.method === "throw") { | ||
// If maybeInvokeDelegate(context) changed context.method from | ||
// "return" to "throw", let that override the TypeError below. | ||
return ContinueSentinel; | ||
} | ||
} | ||
context.method = "throw"; | ||
context.arg = new TypeError( | ||
"The iterator does not provide a 'throw' method"); | ||
} | ||
return ContinueSentinel; | ||
} | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if (record.type === "throw") { | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
var info = record.arg; | ||
if (! info) { | ||
context.method = "throw"; | ||
context.arg = new TypeError("iterator result is not an object"); | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
if (info.done) { | ||
// Assign the result of the finished delegate to the temporary | ||
// variable specified by delegate.resultName (see delegateYield). | ||
context[delegate.resultName] = info.value; | ||
// Resume execution at the desired location (see delegateYield). | ||
context.next = delegate.nextLoc; | ||
// If context.method was "throw" but the delegate handled the | ||
// exception, let the outer generator proceed normally. If | ||
// context.method was "next", forget context.arg since it has been | ||
// "consumed" by the delegate iterator. If context.method was | ||
// "return", allow the original .return call to continue in the | ||
// outer generator. | ||
if (context.method !== "return") { | ||
context.method = "next"; | ||
context.arg = undefined; | ||
} | ||
} else { | ||
// Re-yield the result returned by the delegate method. | ||
return info; | ||
} | ||
// The delegate iterator is finished, so forget it and continue with | ||
// the outer generator. | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
// Define Generator.prototype.{next,throw,return} in terms of the | ||
@@ -390,0 +412,0 @@ // unified ._invoke helper method. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26111
643