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

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

Issue 2334323006: Fix async/await memory leak (Closed)
Patch Set: Rebase on master, and changes for review 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 | src/parsing/parser.cc » ('j') | src/parsing/parser.cc » ('J')
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // yield AsyncFunctionAwait{Caught,Uncaught}(.generator, awaited) 57 // yield AsyncFunctionAwait{Caught,Uncaught}(.generator, awaited)
58 // The 'awaited' parameter is the value; the generator stands in 58 // The 'awaited' parameter is the value; the generator stands in
59 // for the asyncContext, and mark is metadata for debugging 59 // for the asyncContext, and mark is metadata for debugging
60 function AsyncFunctionAwait(generator, awaited, mark) { 60 function AsyncFunctionAwait(generator, awaited, mark) {
61 // Promise.resolve(awaited).then( 61 // Promise.resolve(awaited).then(
62 // value => AsyncFunctionNext(value), 62 // value => AsyncFunctionNext(value),
63 // error => AsyncFunctionThrow(error) 63 // error => AsyncFunctionThrow(error)
64 // ); 64 // );
65 var promise = PromiseCastResolved(awaited); 65 var promise = PromiseCastResolved(awaited);
66 66
67 var onFulfilled = 67 var onFulfilled = sentValue => {
68 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue); 68 %_Call(AsyncFunctionNext, generator, sentValue);
69 var onRejected = 69 // The resulting Promise is a throwaway, so it doesn't matter what it
70 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError); 70 // resolves to. What is important is that we don't end up keeping the
71 // whole chain of intermediate Promises alive by returning the value
72 // of AsyncFunctionNext, as that would create a memory leak.
73 return;
74 };
75 var onRejected = sentError => {
76 %_Call(AsyncFunctionThrow, generator, sentError);
77 // Similarly, returning the huge Promise here would cause a long
78 // resolution chain to find what the exception to throw is, and
79 // create a similar memory leak, and it does not matter what
80 // sort of rejection this intermediate Promise becomes.
81 return;
82 }
71 83
72 if (mark && DEBUG_IS_ACTIVE && IsPromise(awaited)) { 84 if (mark && DEBUG_IS_ACTIVE && IsPromise(awaited)) {
73 // Mark the reject handler callback such that it does not influence 85 // Mark the reject handler callback such that it does not influence
74 // catch prediction. 86 // catch prediction.
75 SET_PRIVATE(onRejected, promiseAwaitHandlerSymbol, true); 87 SET_PRIVATE(onRejected, promiseAwaitHandlerSymbol, true);
76 } 88 }
77 89
78 // Just forwarding the exception, so no debugEvent for throwawayCapability 90 // Just forwarding the exception, so no debugEvent for throwawayCapability
79 var throwawayCapability = NewPromiseCapability(GlobalPromise, false); 91 var throwawayCapability = NewPromiseCapability(GlobalPromise, false);
80 return PerformPromiseThen(promise, onFulfilled, onRejected, 92 return PerformPromiseThen(promise, onFulfilled, onRejected,
(...skipping 21 matching lines...) Expand all
102 return RejectPromise(promise, reason, false); 114 return RejectPromise(promise, reason, false);
103 } 115 }
104 116
105 %InstallToContext([ 117 %InstallToContext([
106 "async_function_await_caught", AsyncFunctionAwaitCaught, 118 "async_function_await_caught", AsyncFunctionAwaitCaught,
107 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, 119 "async_function_await_uncaught", AsyncFunctionAwaitUncaught,
108 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, 120 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent,
109 ]); 121 ]);
110 122
111 }) 123 })
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | src/parsing/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698