Chromium Code Reviews| Index: src/js/harmony-async-await.js |
| diff --git a/src/js/harmony-async-await.js b/src/js/harmony-async-await.js |
| index 4109b77fb54174366cdae648b0dae7fc0c5b02af..6bf4410e3daa8bd305b36894daa419c5e7258b40 100644 |
| --- a/src/js/harmony-async-await.js |
| +++ b/src/js/harmony-async-await.js |
| @@ -54,10 +54,11 @@ function PromiseCastResolved(value) { |
| // Shared logic for the core of await. The parser desugars |
| // await awaited |
| // into |
| -// yield AsyncFunctionAwait{Caught,Uncaught}(.generator, awaited) |
| +// yield AsyncFunctionAwait{Caught,Uncaught}(.generator, awaited, .promise) |
| // The 'awaited' parameter is the value; the generator stands in |
| -// for the asyncContext, and mark is metadata for debugging |
| -function AsyncFunctionAwait(generator, awaited, mark) { |
| +// for the asyncContext, and .promise is the larger promise under |
| +// construction by the enclosing async function. |
| +function AsyncFunctionAwait(generator, awaited, outerPromise) { |
| // Promise.resolve(awaited).then( |
| // value => AsyncFunctionNext(value), |
| // error => AsyncFunctionThrow(error) |
| @@ -69,32 +70,44 @@ function AsyncFunctionAwait(generator, awaited, mark) { |
| var onRejected = |
| (sentError) => %_Call(AsyncFunctionThrow, generator, sentError); |
| - if (mark && DEBUG_IS_ACTIVE && IsPromise(awaited)) { |
| - // Mark the reject handler callback such that it does not influence |
| - // catch prediction. |
| - SET_PRIVATE(onRejected, promiseAwaitHandlerSymbol, true); |
| + var debug_is_active = DEBUG_IS_ACTIVE; |
| + |
| + if (!IS_UNDEFINED(outerPromise) && debug_is_active && IsPromise(awaited)) { |
| + // Mark the reject handler callback to continue recursing to outerPromise |
| + SET_PRIVATE(onRejected, promiseAwaitHandlerSymbol, outerPromise); |
| } |
| // Just forwarding the exception, so no debugEvent for throwawayCapability |
| var throwawayCapability = NewPromiseCapability(GlobalPromise, false); |
| - return PerformPromiseThen(promise, onFulfilled, onRejected, |
| + PerformPromiseThen(promise, onFulfilled, onRejected, |
| throwawayCapability); |
|
jgruber
2016/09/12 13:22:00
Nit: needs formatting.
Dan Ehrenberg
2016/09/12 22:49:25
Moved to one line
|
| + |
| + if (debug_is_active) { |
|
jgruber
2016/09/12 13:22:00
Should this also check for !IS_UNDEFINED(outerProm
Dan Ehrenberg
2016/09/12 22:51:23
Added the IS_UNDEFINED check and merged the blocks
|
| + // Mark the dependency to outerPromise in case the throwaway Promise is |
| + // found on the Promise stack |
| + SET_PRIVATE(throwawayCapability.promise, promiseAwaitHandlerSymbol, |
| + outerPromise); |
| + } |
| } |
| // Called by the parser from the desugaring of 'await' when catch |
| // prediction indicates no locally surrounding catch block |
| -function AsyncFunctionAwaitUncaught(generator, awaited) { |
| - // TODO(littledan): Install a dependency edge from awaited to outerPromise |
| - return AsyncFunctionAwait(generator, awaited, true); |
| +function AsyncFunctionAwaitUncaught(generator, awaited, outerPromise) { |
| + AsyncFunctionAwait(generator, awaited, outerPromise); |
| + return outerPromise; |
| } |
| // Called by the parser from the desugaring of 'await' when catch |
| // prediction indicates that there is a locally surrounding catch block |
| -function AsyncFunctionAwaitCaught(generator, awaited) { |
| +function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) { |
| if (DEBUG_IS_ACTIVE && IsPromise(awaited)) { |
| SET_PRIVATE(awaited, promiseHandledHintSymbol, true); |
| } |
| - return AsyncFunctionAwait(generator, awaited, false); |
| + // Pass undefined for the outer Promise to not waste time setting up |
| + // or following the dependency chain when this Promise is already marked |
| + // as handled |
| + AsyncFunctionAwait(generator, awaited, UNDEFINED); |
| + return outerPromise; |
| } |
| // How the parser rejects promises from async/await desugaring |