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 PANDA_PLUGINS_ETS_ERROR_OPTIONS_H 17 #define PANDA_PLUGINS_ETS_ERROR_OPTIONS_H 18 19 #include "plugins/ets/runtime/types/ets_object.h" 20 #include "plugins/ets/runtime/types/ets_string.h" 21 #include "types/ets_primitives.h" 22 #include "types/ets_typeapi.h" 23 24 namespace ark::ets { 25 26 class EtsCoroutine; 27 28 class EtsErrorOptions : public ObjectHeader { 29 public: 30 EtsErrorOptions() = delete; 31 ~EtsErrorOptions() = delete; 32 33 NO_COPY_SEMANTIC(EtsErrorOptions); 34 NO_MOVE_SEMANTIC(EtsErrorOptions); 35 AsObject()36 EtsObject *AsObject() 37 { 38 return EtsObject::FromCoreType(this); 39 } 40 AsObject()41 const EtsObject *AsObject() const 42 { 43 return EtsObject::FromCoreType(this); 44 } 45 FromEtsObject(EtsObject * field)46 static EtsErrorOptions *FromEtsObject(EtsObject *field) 47 { 48 return reinterpret_cast<EtsErrorOptions *>(field); 49 } 50 SetCause(EtsObject * cause)51 inline void SetCause(EtsObject *cause) 52 { 53 if (cause != nullptr) { 54 ObjectAccessor::SetObject(this, MEMBER_OFFSET(EtsErrorOptions, cause_), cause->GetCoreType()); 55 } else { 56 ObjectAccessor::SetObject(this, MEMBER_OFFSET(EtsErrorOptions, cause_), nullptr); 57 } 58 } 59 Create(EtsCoroutine * etsCoroutine)60 inline static EtsErrorOptions *Create(EtsCoroutine *etsCoroutine) 61 { 62 EtsClass *klass = etsCoroutine->GetPandaVM()->GetClassLinker()->GetClass( 63 panda_file_items::class_descriptors::ERROR_OPTIONS.data()); 64 EtsObject *etsObject = EtsObject::Create(etsCoroutine, klass); 65 return reinterpret_cast<EtsErrorOptions *>(etsObject); 66 } 67 68 private: 69 ObjectPointer<EtsObject> cause_; 70 }; 71 72 } // namespace ark::ets 73 74 #endif // PANDA_PLUGINS_ETS_ERROR_OPTIONS_H 75