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

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

Issue 2334323006: Fix async/await memory leak (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | test/mjsunit/harmony/async-await-loop.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) => {
71 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue); 71 %_Call(AsyncFunctionNext, generator, sentValue);
72 // The resulting Promise is a throwaway, so it doesn't matter what it
caitp 2016/09/15 20:18:40 don't we have this same problem in the rejection c
Dan Ehrenberg 2016/09/15 20:24:21 I don't think so; we don't have the whole chaining
caitp 2016/09/15 20:32:23 Either way, I think it would still be good to add
Dan Ehrenberg 2016/09/15 20:37:58 Oh, you're actually right. It'd similarly take kee
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 UNDEFINED;
77 };
72 var onRejected = 78 var onRejected =
73 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError); 79 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError);
74 80
75 // Just forwarding the exception, so no debugEvent for throwawayCapability 81 // Just forwarding the exception, so no debugEvent for throwawayCapability
76 var throwawayCapability = NewPromiseCapability(GlobalPromise, false); 82 var throwawayCapability = NewPromiseCapability(GlobalPromise, false);
77 // The Promise will be thrown away and not handled, but it shouldn't trigger 83 // The Promise will be thrown away and not handled, but it shouldn't trigger
78 // unhandled reject events as its work is done 84 // unhandled reject events as its work is done
79 SET_PRIVATE(throwawayCapability.promise, promiseHasHandlerSymbol, true); 85 SET_PRIVATE(throwawayCapability.promise, promiseHasHandlerSymbol, true);
80 PerformPromiseThen(promise, onFulfilled, onRejected, throwawayCapability); 86 PerformPromiseThen(promise, onFulfilled, onRejected, throwawayCapability);
81 87
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return RejectPromise(promise, reason, false); 121 return RejectPromise(promise, reason, false);
116 } 122 }
117 123
118 %InstallToContext([ 124 %InstallToContext([
119 "async_function_await_caught", AsyncFunctionAwaitCaught, 125 "async_function_await_caught", AsyncFunctionAwaitCaught,
120 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, 126 "async_function_await_uncaught", AsyncFunctionAwaitUncaught,
121 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, 127 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent,
122 ]); 128 ]);
123 129
124 }) 130 })
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/async-await-loop.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698