builtins-async-gen.h 2.85 KB
Newer Older
1 2 3 4
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_BUILTINS_BUILTINS_ASYNC_GEN_H_
#define V8_BUILTINS_BUILTINS_ASYNC_GEN_H_
7

8
#include "src/builtins/builtins-promise-gen.h"
9 10 11 12 13 14

namespace v8 {
namespace internal {

class AsyncBuiltinsAssembler : public PromiseBuiltinsAssembler {
 public:
15
  explicit AsyncBuiltinsAssembler(compiler::CodeAssemblerState* state)
16 17 18
      : PromiseBuiltinsAssembler(state) {}

 protected:
19 20 21 22 23 24 25 26 27 28 29
  // Perform steps to resume generator after `value` is resolved.
  // `on_reject_context_index` is an index into the Native Context, which should
  // point to a SharedFunctioninfo instance used to create the closure. The
  // value following the reject index should be a similar value for the resolve
  // closure. Returns the Promise-wrapped `value`.
  Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise,
              Node* on_resolve_context_index, Node* on_reject_context_index,
              Node* is_predicted_as_caught);
  Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise,
              int on_resolve_context_index, int on_reject_context_index,
              Node* is_predicted_as_caught) {
30 31
    return Await(context, generator, value, outer_promise,
                 IntPtrConstant(on_resolve_context_index),
32 33 34 35 36 37
                 IntPtrConstant(on_reject_context_index),
                 is_predicted_as_caught);
  }
  Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise,
              int on_resolve_context_index, int on_reject_context_index,
              bool is_predicted_as_caught) {
38 39
    return Await(context, generator, value, outer_promise,
                 on_resolve_context_index, on_reject_context_index,
40 41
                 BooleanConstant(is_predicted_as_caught));
  }
42 43 44 45 46 47

  // Return a new built-in function object as defined in
  // Async Iterator Value Unwrap Functions
  Node* CreateUnwrapClosure(Node* const native_context, Node* const done);

 private:
48 49
  void InitializeNativeClosure(Node* context, Node* native_context,
                               Node* function, Node* context_index);
50 51
  Node* AllocateAsyncIteratorValueUnwrapContext(Node* native_context,
                                                Node* done);
52 53 54 55 56 57 58 59

  Node* AwaitOld(Node* context, Node* generator, Node* value,
                 Node* outer_promise, Node* on_resolve_context_index,
                 Node* on_reject_context_index, Node* is_predicted_as_caught);
  Node* AwaitOptimized(Node* context, Node* generator, Node* value,
                       Node* outer_promise, Node* on_resolve_context_index,
                       Node* on_reject_context_index,
                       Node* is_predicted_as_caught);
60 61 62 63 64
};

}  // namespace internal
}  // namespace v8

65
#endif  // V8_BUILTINS_BUILTINS_ASYNC_GEN_H_