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

Side by Side Diff: src/js/harmony-async-await.js

Issue 2334323006: Fix async/await memory leak (Closed)
Patch Set: Also do for catch, and fix another test 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // The 'awaited' parameter is the value; the generator stands in 60 // The 'awaited' parameter is the value; the generator stands in
61 // for the asyncContext, and .promise is the larger promise under 61 // for the asyncContext, and .promise is the larger promise under
62 // construction by the enclosing async function. 62 // construction by the enclosing async function.
63 function AsyncFunctionAwait(generator, awaited, outerPromise) { 63 function AsyncFunctionAwait(generator, awaited, outerPromise) {
64 // Promise.resolve(awaited).then( 64 // Promise.resolve(awaited).then(
65 // value => AsyncFunctionNext(value), 65 // value => AsyncFunctionNext(value),
66 // error => AsyncFunctionThrow(error) 66 // error => AsyncFunctionThrow(error)
67 // ); 67 // );
68 var promise = PromiseCastResolved(awaited); 68 var promise = PromiseCastResolved(awaited);
69 69
70 var onFulfilled = 70 var onFulfilled = (sentValue) => {
adamk 2016/09/15 22:43:20 Nit: no need for parens while you're changing this
Dan Ehrenberg 2016/09/16 00:36:01 Done
71 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue); 71 %_Call(AsyncFunctionNext, generator, sentValue);
72 var onRejected = 72 // The resulting Promise is a throwaway, so it doesn't matter what it
73 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError); 73 // resolves to. What is important is that we don't end up keeping the
74 // whole chain of intermediate Promises alive by returning the value
75 // of AsyncFunctionNext, as that would create a memory leak.
76 return;
77 };
78 var onRejected = (sentError) => {
adamk 2016/09/15 22:43:20 ditto
Dan Ehrenberg 2016/09/16 00:36:00 Done
79 %_Call(AsyncFunctionThrow, generator, sentError);
80 // Similarly, returning the huge Promise here would cause a long
81 // resolution chain to find what the exception to throw is, and
82 // create a similar memory leak, and it does not matter what
83 // sort of rejection this intermediate Promise becomes.
84 return;
85 }
74 86
75 // Just forwarding the exception, so no debugEvent for throwawayCapability 87 // Just forwarding the exception, so no debugEvent for throwawayCapability
76 var throwawayCapability = NewPromiseCapability(GlobalPromise, false); 88 var throwawayCapability = NewPromiseCapability(GlobalPromise, false);
77 // The Promise will be thrown away and not handled, but it shouldn't trigger 89 // The Promise will be thrown away and not handled, but it shouldn't trigger
78 // unhandled reject events as its work is done 90 // unhandled reject events as its work is done
79 SET_PRIVATE(throwawayCapability.promise, promiseHasHandlerSymbol, true); 91 SET_PRIVATE(throwawayCapability.promise, promiseHasHandlerSymbol, true);
80 PerformPromiseThen(promise, onFulfilled, onRejected, throwawayCapability); 92 PerformPromiseThen(promise, onFulfilled, onRejected, throwawayCapability);
81 93
82 if (DEBUG_IS_ACTIVE && !IS_UNDEFINED(outerPromise)) { 94 if (DEBUG_IS_ACTIVE && !IS_UNDEFINED(outerPromise)) {
83 if (IsPromise(awaited)) { 95 if (IsPromise(awaited)) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return RejectPromise(promise, reason, false); 127 return RejectPromise(promise, reason, false);
116 } 128 }
117 129
118 %InstallToContext([ 130 %InstallToContext([
119 "async_function_await_caught", AsyncFunctionAwaitCaught, 131 "async_function_await_caught", AsyncFunctionAwaitCaught,
120 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, 132 "async_function_await_uncaught", AsyncFunctionAwaitUncaught,
121 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, 133 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent,
122 ]); 134 ]);
123 135
124 }) 136 })
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/async-await-loop.js » ('j') | test/mjsunit/harmony/debug-async-function-async-task-event.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698