1 /** 2 * Copyright (c) 2024-2025 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 PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_PROMISE_REF_H 17 #define PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_PROMISE_REF_H 18 19 #include "plugins/ets/runtime/types/ets_object.h" 20 21 namespace ark::ets { 22 23 class EtsCoroutine; 24 25 namespace test { 26 class EtsPromiseTest; 27 } // namespace test 28 29 class EtsPromiseRef : public EtsObject { 30 public: 31 EtsPromiseRef() = delete; 32 ~EtsPromiseRef() = delete; 33 34 NO_COPY_SEMANTIC(EtsPromiseRef); 35 NO_MOVE_SEMANTIC(EtsPromiseRef); 36 37 PANDA_PUBLIC_API static EtsPromiseRef *Create(EtsCoroutine *etsCoroutine); 38 AsObject()39 EtsObject *AsObject() 40 { 41 return this; 42 } 43 AsObject()44 const EtsObject *AsObject() const 45 { 46 return this; 47 } 48 GetTarget(EtsCoroutine * coro)49 EtsObject *GetTarget(EtsCoroutine *coro) const 50 { 51 auto *obj = ObjectAccessor::GetObject(coro, this, MEMBER_OFFSET(EtsPromiseRef, target_)); 52 return EtsObject::FromCoreType(obj); 53 } 54 SetTarget(EtsCoroutine * coro,EtsObject * t)55 void SetTarget(EtsCoroutine *coro, EtsObject *t) 56 { 57 ObjectAccessor::SetObject(coro, this, MEMBER_OFFSET(EtsPromiseRef, target_), t->GetCoreType()); 58 } 59 60 private: 61 ObjectPointer<EtsObject> target_; 62 63 friend class test::EtsPromiseTest; 64 }; 65 66 } // namespace ark::ets 67 68 #endif // PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_PROMISE_REF_H 69