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

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

Issue 2357423002: Improve stack traces for async functions (Closed)
Patch Set: REbase 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/inspector/v8-stack-trace-impl.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 bd754495b7f7cde6e28cbf7e4b52092889dfa92f..b733f3d9fa90b81de782ba79d17916d6101b41ea 100644
--- a/src/js/harmony-async-await.js
+++ b/src/js/harmony-async-await.js
@@ -18,21 +18,25 @@ var IsPromise;
var NewPromiseCapability;
var PerformPromiseThen;
var PromiseCreate;
+var PromiseNextMicrotaskID;
var RejectPromise;
var ResolvePromise;
utils.Import(function(from) {
AsyncFunctionNext = from.AsyncFunctionNext;
AsyncFunctionThrow = from.AsyncFunctionThrow;
- IsPromise = from.IsPromise;
GlobalPromise = from.GlobalPromise;
+ IsPromise = from.IsPromise;
NewPromiseCapability = from.NewPromiseCapability;
- PromiseCreate = from.PromiseCreate;
PerformPromiseThen = from.PerformPromiseThen;
+ PromiseCreate = from.PromiseCreate;
+ PromiseNextMicrotaskID = from.PromiseNextMicrotaskID;
RejectPromise = from.RejectPromise;
ResolvePromise = from.ResolvePromise;
});
+var promiseAsyncStackIDSymbol =
+ utils.ImportNow("promise_async_stack_id_symbol");
var promiseHandledBySymbol =
utils.ImportNow("promise_handled_by_symbol");
var promiseForwardingHandlerSymbol =
@@ -94,9 +98,7 @@ function AsyncFunctionAwait(generator, awaited, outerPromise) {
// unhandled reject events as its work is done
SET_PRIVATE(throwawayCapability.promise, promiseHasHandlerSymbol, true);
- PerformPromiseThen(promise, onFulfilled, onRejected, throwawayCapability);
-
- if (DEBUG_IS_ACTIVE && !IS_UNDEFINED(outerPromise)) {
+ if (DEBUG_IS_ACTIVE) {
if (IsPromise(awaited)) {
// Mark the reject handler callback to be a forwarding edge, rather
// than a meaningful catch handler
@@ -108,6 +110,8 @@ function AsyncFunctionAwait(generator, awaited, outerPromise) {
SET_PRIVATE(throwawayCapability.promise, promiseHandledBySymbol,
outerPromise);
}
+
+ PerformPromiseThen(promise, onFulfilled, onRejected, throwawayCapability);
}
// Called by the parser from the desugaring of 'await' when catch
@@ -122,10 +126,7 @@ function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) {
if (DEBUG_IS_ACTIVE && IsPromise(awaited)) {
SET_PRIVATE(awaited, promiseHandledHintSymbol, true);
}
- // 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);
+ AsyncFunctionAwait(generator, awaited, outerPromise);
}
// How the parser rejects promises from async/await desugaring
@@ -133,10 +134,47 @@ function RejectPromiseNoDebugEvent(promise, reason) {
return RejectPromise(promise, reason, false);
}
+function AsyncFunctionPromiseCreate() {
+ var promise = PromiseCreate();
+ if (DEBUG_IS_ACTIVE) {
+ // Push the Promise under construction in an async function on
+ // the catch prediction stack to handle exceptions thrown before
+ // the first await.
+ %DebugPushPromise(promise);
+ // Assign ID and create a recurring task to save stack for future
+ // resumptions from await.
+ var id = PromiseNextMicrotaskID();
+ SET_PRIVATE(promise, promiseAsyncStackIDSymbol, id);
+ %DebugAsyncTaskEvent({
+ type: "enqueueRecurring",
+ id: id,
+ name: "async function",
+ });
+ }
+ return promise;
+}
+
+function AsyncFunctionPromiseRelease(promise) {
+ if (DEBUG_IS_ACTIVE) {
+ // Cancel
+ var id = GET_PRIVATE(promise, promiseAsyncStackIDSymbol);
+ %DebugAsyncTaskEvent({
+ type: "cancel",
+ id: id,
+ name: "async function",
+ });
+ // Pop the Promise under construction in an async function on
+ // from catch prediction stack.
+ %DebugPopPromise();
+ }
+}
+
%InstallToContext([
"async_function_await_caught", AsyncFunctionAwaitCaught,
"async_function_await_uncaught", AsyncFunctionAwaitUncaught,
"reject_promise_no_debug_event", RejectPromiseNoDebugEvent,
+ "async_function_promise_create", AsyncFunctionPromiseCreate,
+ "async_function_promise_release", AsyncFunctionPromiseRelease,
]);
})
« no previous file with comments | « src/inspector/v8-stack-trace-impl.cc ('k') | src/js/prologue.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698