Index: src/js/harmony-async-await.js |
diff --git a/src/js/harmony-async-await.js b/src/js/harmony-async-await.js |
index 203ca88f12201df3fe3a013bed3bc2f8bb61b006..6b6fce7742313d9b656cbfc1c848761cc41562c3 100644 |
--- a/src/js/harmony-async-await.js |
+++ b/src/js/harmony-async-await.js |
@@ -11,51 +11,88 @@ |
// ------------------------------------------------------------------- |
// Imports |
+var InternalArray = utils.InternalArray; |
var AsyncFunctionNext; |
var AsyncFunctionThrow; |
var GlobalPromise; |
+var IsPromise; |
var NewPromiseCapability; |
var PerformPromiseThen; |
-var PromiseCastResolved; |
+var PromiseCreate; |
var RejectPromise; |
+var ResolvePromise; |
utils.Import(function(from) { |
AsyncFunctionNext = from.AsyncFunctionNext; |
AsyncFunctionThrow = from.AsyncFunctionThrow; |
+ IsPromise = from.IsPromise; |
GlobalPromise = from.GlobalPromise; |
NewPromiseCapability = from.NewPromiseCapability; |
- PromiseCastResolved = from.PromiseCastResolved; |
+ PromiseCreate = from.PromiseCreate; |
PerformPromiseThen = from.PerformPromiseThen; |
RejectPromise = from.RejectPromise; |
+ ResolvePromise = from.ResolvePromise; |
}); |
+var promiseAwaitHandlerSymbol = utils.ImportNow("promise_await_handler_symbol"); |
+var promiseHandledHintSymbol = |
+ utils.ImportNow("promise_handled_hint_symbol"); |
+ |
// ------------------------------------------------------------------- |
-function AsyncFunctionAwait(generator, value) { |
- // Promise.resolve(value).then( |
+function PromiseCastResolved(value) { |
+ if (IsPromise(value)) { |
+ return value; |
+ } else { |
+ var promise = PromiseCreate(); |
+ ResolvePromise(promise, value); |
+ return promise; |
+ } |
+} |
+ |
+function AsyncFunctionAwait(generator, awaited, mark) { |
+ // Promise.resolve(awaited).then( |
// value => AsyncFunctionNext(value), |
// error => AsyncFunctionThrow(error) |
// ); |
- var promise = PromiseCastResolved(value); |
+ var promise = PromiseCastResolved(awaited); |
var onFulfilled = |
(sentValue) => %_Call(AsyncFunctionNext, generator, sentValue); |
var onRejected = |
(sentError) => %_Call(AsyncFunctionThrow, generator, sentError); |
- // false debugEvent to avoid redundant ExceptionEvents |
- var throwawayCapability = NewPromiseCapability(GlobalPromise, false); |
+ 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 throwawayCapability = NewPromiseCapability(GlobalPromise); |
return PerformPromiseThen(promise, onFulfilled, onRejected, |
throwawayCapability); |
} |
+function AsyncFunctionAwaitUncaught(generator, awaited) { |
+ // TODO(littledan): Install a dependency edge from awaited to outerPromise |
+ return AsyncFunctionAwait(generator, awaited, true); |
+} |
+ |
+function AsyncFunctionAwaitCaught(generator, awaited) { |
+ if (DEBUG_IS_ACTIVE && IsPromise(awaited)) { |
+ SET_PRIVATE(awaited, promiseHandledHintSymbol, true); |
+ } |
+ return AsyncFunctionAwait(generator, awaited, false); |
+} |
+ |
// How the parser rejects promises from async/await desugaring |
function RejectPromiseNoDebugEvent(promise, reason) { |
return RejectPromise(promise, reason, false); |
} |
%InstallToContext([ |
- "async_function_await", AsyncFunctionAwait, |
+ "async_function_await_caught", AsyncFunctionAwaitCaught, |
+ "async_function_await_uncaught", AsyncFunctionAwaitUncaught, |
"reject_promise_no_debug_event", RejectPromiseNoDebugEvent, |
]); |