| Rubin Xu | 7bc1b61 | 2021-02-16 09:38:50 +0000 | [diff] [blame^] | 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: |
| 15 | explicit AsyncBuiltinsAssembler(compiler::CodeAssemblerState* state) |
| 16 | : PromiseBuiltinsAssembler(state) {} |
| 17 | |
| 18 | protected: |
| 19 | // Perform steps to resume generator after `value` is resolved. |
| 20 | // `on_reject` is the SharedFunctioninfo instance used to create the reject |
| 21 | // closure. `on_resolve` is the SharedFunctioninfo instance used to create the |
| 22 | // resolve closure. Returns the Promise-wrapped `value`. |
| 23 | TNode<Object> Await(TNode<Context> context, |
| 24 | TNode<JSGeneratorObject> generator, TNode<Object> value, |
| 25 | TNode<JSPromise> outer_promise, |
| 26 | TNode<SharedFunctionInfo> on_resolve_sfi, |
| 27 | TNode<SharedFunctionInfo> on_reject_sfi, |
| 28 | TNode<Oddball> is_predicted_as_caught); |
| 29 | TNode<Object> Await(TNode<Context> context, |
| 30 | TNode<JSGeneratorObject> generator, TNode<Object> value, |
| 31 | TNode<JSPromise> outer_promise, |
| 32 | TNode<SharedFunctionInfo> on_resolve_sfi, |
| 33 | TNode<SharedFunctionInfo> on_reject_sfi, |
| 34 | bool is_predicted_as_caught) { |
| 35 | return Await(context, generator, value, outer_promise, on_resolve_sfi, |
| 36 | on_reject_sfi, BooleanConstant(is_predicted_as_caught)); |
| 37 | } |
| 38 | |
| 39 | // Return a new built-in function object as defined in |
| 40 | // Async Iterator Value Unwrap Functions |
| 41 | TNode<JSFunction> CreateUnwrapClosure(TNode<NativeContext> native_context, |
| 42 | TNode<Oddball> done); |
| 43 | |
| 44 | private: |
| 45 | void InitializeNativeClosure(TNode<Context> context, |
| 46 | TNode<NativeContext> native_context, |
| 47 | TNode<HeapObject> function, |
| 48 | TNode<SharedFunctionInfo> shared_info); |
| 49 | TNode<Context> AllocateAsyncIteratorValueUnwrapContext( |
| 50 | TNode<NativeContext> native_context, TNode<Oddball> done); |
| 51 | |
| 52 | TNode<Object> AwaitOld(TNode<Context> context, |
| 53 | TNode<JSGeneratorObject> generator, |
| 54 | TNode<Object> value, TNode<JSPromise> outer_promise, |
| 55 | TNode<SharedFunctionInfo> on_resolve_sfi, |
| 56 | TNode<SharedFunctionInfo> on_reject_sfi, |
| 57 | TNode<Oddball> is_predicted_as_caught); |
| 58 | TNode<Object> AwaitOptimized(TNode<Context> context, |
| 59 | TNode<JSGeneratorObject> generator, |
| 60 | TNode<JSPromise> promise, |
| 61 | TNode<JSPromise> outer_promise, |
| 62 | TNode<SharedFunctionInfo> on_resolve_sfi, |
| 63 | TNode<SharedFunctionInfo> on_reject_sfi, |
| 64 | TNode<Oddball> is_predicted_as_caught); |
| 65 | }; |
| 66 | |
| 67 | } // namespace internal |
| 68 | } // namespace v8 |
| 69 | |
| 70 | #endif // V8_BUILTINS_BUILTINS_ASYNC_GEN_H_ |