1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_JS_ASYNC_FUNCTION_H 17 #define ECMASCRIPT_JS_ASYNC_FUNCTION_H 18 19 #include "ecmascript/ecma_macros.h" 20 #include "ecmascript/js_generator_object.h" 21 #include "ecmascript/js_tagged_value.h" 22 #include "ecmascript/js_function.h" 23 24 namespace panda::ecmascript { 25 class JSAsyncAwaitStatusFunction : public JSFunction { 26 public: 27 CAST_CHECK(JSAsyncAwaitStatusFunction, IsJSAsyncAwaitStatusFunction); 28 29 static JSHandle<JSTaggedValue> AsyncFunctionAwaitFulfilled(JSThread *thread, 30 const JSHandle<JSAsyncAwaitStatusFunction> &func, 31 const JSHandle<JSTaggedValue> &value); 32 33 static JSHandle<JSTaggedValue> AsyncFunctionAwaitRejected(JSThread *thread, 34 const JSHandle<JSAsyncAwaitStatusFunction> &func, 35 const JSHandle<JSTaggedValue> &reason); 36 37 static constexpr size_t ASYNC_CONTEXT_OFFSET = JSFunction::SIZE; 38 ACCESSORS(AsyncContext, ASYNC_CONTEXT_OFFSET, SIZE); 39 40 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunction, ASYNC_CONTEXT_OFFSET, SIZE) 41 42 DECL_DUMP() 43 }; 44 45 class JSAsyncFunction : public JSFunction { 46 public: Cast(TaggedObject * object)47 static JSAsyncFunction *Cast(TaggedObject *object) 48 { 49 ASSERT(JSTaggedValue(object).IsJSAsyncFunction()); 50 return static_cast<JSAsyncFunction *>(object); 51 } 52 53 static void AsyncFunctionAwait(JSThread *thread, const JSHandle<JSTaggedValue> &asyncFuncObj, 54 const JSHandle<JSTaggedValue> &value); 55 static void AsyncFunctionAwait(JSThread *thread, const JSHandle<JSAsyncFuncObject> &asyncFuncObj, 56 const JSHandle<JSTaggedValue> &value); 57 static constexpr size_t SIZE = JSFunction::SIZE; 58 59 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunction, SIZE, SIZE) 60 61 DECL_DUMP() 62 }; 63 } // namespace panda::ecmascript 64 65 #endif // ECMASCRIPT_JS_ASYNC_FUNCTION_H 66