Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Unified Diff: src/js/harmony-async-await.js

Issue 2276243002: Mark await expressions as caught or uncaught (Closed)
Patch Set: Revert "Tests for caught exception" Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/isolate.cc ('k') | src/js/prologue.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..4109b77fb54174366cdae648b0dae7fc0c5b02af 100644
--- a/src/js/harmony-async-await.js
+++ b/src/js/harmony-async-await.js
@@ -14,48 +14,97 @@
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;
+ }
+}
+
+// ES#abstract-ops-async-function-await
+// AsyncFunctionAwait ( value )
+// Shared logic for the core of await. The parser desugars
+// await awaited
+// into
+// yield AsyncFunctionAwait{Caught,Uncaught}(.generator, awaited)
+// The 'awaited' parameter is the value; the generator stands in
+// for the asyncContext, and mark is metadata for debugging
+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
+ 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);
+ }
+
+ // Just forwarding the exception, so no debugEvent for throwawayCapability
var throwawayCapability = NewPromiseCapability(GlobalPromise, false);
return PerformPromiseThen(promise, onFulfilled, onRejected,
throwawayCapability);
}
+// 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);
+}
+
+// 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) {
+ 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,
]);
« no previous file with comments | « src/isolate.cc ('k') | src/js/prologue.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698