1 /* 2 * Copyright (c) 2021 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_tagged_value.h" 21 #include "js_function.h" 22 23 namespace panda::ecmascript { 24 class JSAsyncAwaitStatusFunction : public JSFunction { 25 public: 26 CAST_CHECK(JSAsyncAwaitStatusFunction, IsJSAsyncAwaitStatusFunction); 27 28 static JSHandle<JSTaggedValue> AsyncFunctionAwaitFulfilled(JSThread *thread, 29 const JSHandle<JSAsyncAwaitStatusFunction> &func, 30 const JSHandle<JSTaggedValue> &value); 31 32 static JSHandle<JSTaggedValue> AsyncFunctionAwaitRejected(JSThread *thread, 33 const JSHandle<JSAsyncAwaitStatusFunction> &func, 34 const JSHandle<JSTaggedValue> &reason); 35 36 static constexpr size_t ASYNC_CONTEXT_OFFSET = JSFunction::SIZE; 37 ACCESSORS(AsyncContext, ASYNC_CONTEXT_OFFSET, SIZE); 38 39 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunction, ASYNC_CONTEXT_OFFSET, SIZE) 40 41 DECL_DUMP() 42 }; 43 44 class JSAsyncFunction : public JSFunction { 45 public: Cast(ObjectHeader * object)46 static JSAsyncFunction *Cast(ObjectHeader *object) 47 { 48 ASSERT(JSTaggedValue(object).IsJSAsyncFunction()); 49 return static_cast<JSAsyncFunction *>(object); 50 } 51 52 static void AsyncFunctionAwait(JSThread *thread, const JSHandle<JSAsyncFuncObject> &asyncFuncObj, 53 const JSHandle<JSTaggedValue> &value); 54 static constexpr size_t SIZE = JSFunction::SIZE; 55 56 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunction, SIZE, SIZE) 57 58 DECL_DUMP() 59 }; 60 } // namespace panda::ecmascript 61 62 #endif // ECMASCRIPT_JS_ASYNC_FUNCTION_H 63