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 3 // found in the LICENSE file. 4 5 #ifndef V8_BUILTINS_BUILTINS_ASYNC_GEN_H_ 6 #define V8_BUILTINS_BUILTINS_ASYNC_GEN_H_ 7 8 #include "src/builtins/builtins-promise-gen.h" 9 10 namespace v8 { 11 namespace internal { 12 13 class AsyncBuiltinsAssembler : public PromiseBuiltinsAssembler { 14 public: AsyncBuiltinsAssembler(compiler::CodeAssemblerState * state)15 explicit AsyncBuiltinsAssembler(compiler::CodeAssemblerState* state) 16 : PromiseBuiltinsAssembler(state) {} 17 18 protected: 19 typedef std::function<void(Node*)> ContextInitializer; 20 21 // Perform steps to resume generator after `value` is resolved. 22 // `on_reject_context_index` is an index into the Native Context, which should 23 // point to a SharedFunctioninfo instance used to create the closure. The 24 // value following the reject index should be a similar value for the resolve 25 // closure. Returns the Promise-wrapped `value`. 26 Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise, 27 int context_length, 28 const ContextInitializer& init_closure_context, 29 Node* on_resolve_context_index, Node* on_reject_context_index, 30 Node* is_predicted_as_caught); 31 Node* AwaitOptimized(Node* context, Node* generator, Node* value, 32 Node* outer_promise, int context_length, 33 const ContextInitializer& init_closure_context, 34 Node* on_resolve_context_index, 35 Node* on_reject_context_index, 36 Node* is_predicted_as_caught); Await(Node * context,Node * generator,Node * value,Node * outer_promise,int context_length,const ContextInitializer & init_closure_context,int on_resolve_context_index,int on_reject_context_index,Node * is_predicted_as_caught)37 Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise, 38 int context_length, 39 const ContextInitializer& init_closure_context, 40 int on_resolve_context_index, int on_reject_context_index, 41 Node* is_predicted_as_caught) { 42 return Await(context, generator, value, outer_promise, context_length, 43 init_closure_context, IntPtrConstant(on_resolve_context_index), 44 IntPtrConstant(on_reject_context_index), 45 is_predicted_as_caught); 46 } AwaitOptimized(Node * context,Node * generator,Node * value,Node * outer_promise,int context_length,const ContextInitializer & init_closure_context,int on_resolve_context_index,int on_reject_context_index,Node * is_predicted_as_caught)47 Node* AwaitOptimized(Node* context, Node* generator, Node* value, 48 Node* outer_promise, int context_length, 49 const ContextInitializer& init_closure_context, 50 int on_resolve_context_index, 51 int on_reject_context_index, 52 Node* is_predicted_as_caught) { 53 return AwaitOptimized( 54 context, generator, value, outer_promise, context_length, 55 init_closure_context, IntPtrConstant(on_resolve_context_index), 56 IntPtrConstant(on_reject_context_index), is_predicted_as_caught); 57 } Await(Node * context,Node * generator,Node * value,Node * outer_promise,int context_length,const ContextInitializer & init_closure_context,int on_resolve_context_index,int on_reject_context_index,bool is_predicted_as_caught)58 Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise, 59 int context_length, 60 const ContextInitializer& init_closure_context, 61 int on_resolve_context_index, int on_reject_context_index, 62 bool is_predicted_as_caught) { 63 return Await(context, generator, value, outer_promise, context_length, 64 init_closure_context, on_resolve_context_index, 65 on_reject_context_index, 66 BooleanConstant(is_predicted_as_caught)); 67 } AwaitOptimized(Node * context,Node * generator,Node * value,Node * outer_promise,int context_length,const ContextInitializer & init_closure_context,int on_resolve_context_index,int on_reject_context_index,bool is_predicted_as_caught)68 Node* AwaitOptimized(Node* context, Node* generator, Node* value, 69 Node* outer_promise, int context_length, 70 const ContextInitializer& init_closure_context, 71 int on_resolve_context_index, 72 int on_reject_context_index, 73 bool is_predicted_as_caught) { 74 return AwaitOptimized(context, generator, value, outer_promise, 75 context_length, init_closure_context, 76 on_resolve_context_index, on_reject_context_index, 77 BooleanConstant(is_predicted_as_caught)); 78 } 79 80 // Return a new built-in function object as defined in 81 // Async Iterator Value Unwrap Functions 82 Node* CreateUnwrapClosure(Node* const native_context, Node* const done); 83 84 private: 85 void InitializeNativeClosure(Node* context, Node* native_context, 86 Node* function, Node* context_index); 87 Node* AllocateAsyncIteratorValueUnwrapContext(Node* native_context, 88 Node* done); 89 }; 90 91 } // namespace internal 92 } // namespace v8 93 94 #endif // V8_BUILTINS_BUILTINS_ASYNC_GEN_H_ 95