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

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

Issue 2233923003: Desugar async/await to create the resulting Promise upfront (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: format 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 | « src/full-codegen/full-codegen.cc ('k') | src/js/prologue.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
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var AsyncFunctionNext; 14 var AsyncFunctionNext;
15 var AsyncFunctionThrow; 15 var AsyncFunctionThrow;
16 var GlobalPromise; 16 var GlobalPromise;
17 var NewPromiseCapability; 17 var NewPromiseCapability;
18 var PerformPromiseThen; 18 var PerformPromiseThen;
19 var PromiseCastResolved; 19 var PromiseCastResolved;
20 var RejectPromise;
20 21
21 utils.Import(function(from) { 22 utils.Import(function(from) {
22 AsyncFunctionNext = from.AsyncFunctionNext; 23 AsyncFunctionNext = from.AsyncFunctionNext;
23 AsyncFunctionThrow = from.AsyncFunctionThrow; 24 AsyncFunctionThrow = from.AsyncFunctionThrow;
24 GlobalPromise = from.GlobalPromise; 25 GlobalPromise = from.GlobalPromise;
25 NewPromiseCapability = from.NewPromiseCapability; 26 NewPromiseCapability = from.NewPromiseCapability;
26 PromiseCastResolved = from.PromiseCastResolved; 27 PromiseCastResolved = from.PromiseCastResolved;
27 PerformPromiseThen = from.PerformPromiseThen; 28 PerformPromiseThen = from.PerformPromiseThen;
29 RejectPromise = from.RejectPromise;
28 }); 30 });
29 31
30 // ------------------------------------------------------------------- 32 // -------------------------------------------------------------------
31 33
32 function AsyncFunctionAwait(generator, value) { 34 function AsyncFunctionAwait(generator, value) {
33 // Promise.resolve(value).then( 35 // Promise.resolve(value).then(
34 // value => AsyncFunctionNext(value), 36 // value => AsyncFunctionNext(value),
35 // error => AsyncFunctionThrow(error) 37 // error => AsyncFunctionThrow(error)
36 // ); 38 // );
37 var promise = PromiseCastResolved(value); 39 var promise = PromiseCastResolved(value);
38 40
39 var onFulfilled = 41 var onFulfilled =
40 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue); 42 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue);
41 var onRejected = 43 var onRejected =
42 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError); 44 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError);
43 45
44 // false debugEvent to avoid redundant ExceptionEvents 46 // false debugEvent to avoid redundant ExceptionEvents
45 var throwawayCapability = NewPromiseCapability(GlobalPromise, false); 47 var throwawayCapability = NewPromiseCapability(GlobalPromise, false);
46 return PerformPromiseThen(promise, onFulfilled, onRejected, 48 return PerformPromiseThen(promise, onFulfilled, onRejected,
47 throwawayCapability); 49 throwawayCapability);
48 } 50 }
49 51
50 %InstallToContext([ "async_function_await", AsyncFunctionAwait ]); 52 // How the parser rejects promises from async/await desugaring
53 function RejectPromiseNoDebugEvent(promise, reason) {
54 return RejectPromise(promise, reason, false);
55 }
56
57 %InstallToContext([
58 "async_function_await", AsyncFunctionAwait,
59 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent,
60 ]);
51 61
52 }) 62 })
OLDNEW
« no previous file with comments | « src/full-codegen/full-codegen.cc ('k') | src/js/prologue.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698