blob: c6705efe36d027134dc4cbf09003d27e107fe0d4 [file] [log] [blame]
Ben Murdochc5610432016-08-08 18:44:38 +01001// 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
3// found in the LICENSE file.
4
5(function(global, utils, extrasUtils) {
6
7"use strict";
8
9%CheckIsBootstrapping();
10
11// -------------------------------------------------------------------
12// Imports
13
14var AsyncFunctionNext;
15var AsyncFunctionThrow;
16var PromiseReject;
17var PromiseResolve;
18var PromiseThen;
19
20utils.Import(function(from) {
21 AsyncFunctionNext = from.AsyncFunctionNext;
22 AsyncFunctionThrow = from.AsyncFunctionThrow;
23 PromiseReject = from.PromiseCreateRejected;
24 PromiseResolve = from.PromiseCreateResolved;
25 PromiseThen = from.PromiseThen;
26});
27
28// -------------------------------------------------------------------
29
30function AsyncFunctionAwait(generator, value) {
31 return %_Call(
32 PromiseThen, PromiseResolve(value),
33 function(sentValue) {
34 return %_Call(AsyncFunctionNext, generator, sentValue);
35 },
36 function(sentError) {
37 return %_Call(AsyncFunctionThrow, generator, sentError);
38 });
39}
40
41%InstallToContext([ "async_function_await", AsyncFunctionAwait ]);
42
43})