1 /* 2 * Copyright (c) 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 COMMON_INTERFACES_OBJECTS_BASE_OBJECT_ACCESSOR_H 17 #define COMMON_INTERFACES_OBJECTS_BASE_OBJECT_ACCESSOR_H 18 19 #include "objects/base_object.h" 20 #include "objects/base_type.h" 21 #include "thread/thread_holder.h" 22 23 namespace common { 24 // The interface will be implemented in the dynamic runtime to provide the ability to access properties of 1.0 objects. 25 class DynamicObjectAccessorInterface { 26 public: 27 // HasProperty is used to check if the dynamic object has a property with the given name. 28 virtual bool HasProperty(ThreadHolder *thread, const BaseObject *obj, const char *name) const = 0; 29 30 // GetProperty is used to get the value of a property from a dynamic object with the given name. 31 virtual JSTaggedValue GetProperty(ThreadHolder *thread, const BaseObject *obj, const char *name) const = 0; 32 33 // SetProperty is used to set the value of a property in a dynamic object with the given name. 34 virtual bool SetProperty(ThreadHolder *thread, BaseObject *obj, const char *name, JSTaggedValue value) = 0; 35 36 // HasElementByIdx is used to check if the dynamic object has an element with the given index. 37 virtual bool HasElementByIdx(ThreadHolder *thread, const BaseObject *obj, const uint32_t index) const = 0; 38 39 // GetElementByIdx is used to get the value of an element from a dynamic object with the given index. 40 virtual JSTaggedValue GetElementByIdx(ThreadHolder *thread, const BaseObject *obj, const uint32_t index) const = 0; 41 42 // SetElementByIdx is used to set the value of an element in a dynamic object with the given index. 43 virtual bool SetElementByIdx(ThreadHolder *thread, BaseObject *obj, const uint32_t index, JSTaggedValue value) = 0; 44 }; 45 46 // The interface will be implemented in the static runtime to provide the ability to access 47 // properties of static objects. 48 class StaticObjectAccessorInterface { 49 public: 50 // HasProperty is used to check if the static object has a property with the given name. 51 virtual bool HasProperty(ThreadHolder *thread, const BaseObject *obj, const char *name) = 0; 52 53 // GetProperty is used to get the value of a property from a static object with the given name. 54 virtual BoxedValue GetProperty(ThreadHolder *thread, const BaseObject *obj, const char *name) = 0; 55 56 // SetProperty is used to set the value of a property in a static object with the given name. 57 virtual bool SetProperty(ThreadHolder *thread, BaseObject *obj, const char *name, BoxedValue value) = 0; 58 59 // HasElementByIdx is used to check if the static object has an element with the given index. 60 virtual bool HasElementByIdx(ThreadHolder *thread, const BaseObject *obj, const uint32_t index) = 0; 61 62 // GetElementByIdx is used to get the value of an element from a static object with the given index. 63 virtual BoxedValue GetElementByIdx(ThreadHolder *thread, const BaseObject *obj, const uint32_t index) = 0; 64 65 // SetElementByIdx is used to set the value of an element in a static object with the given index. 66 virtual bool SetElementByIdx(ThreadHolder *thread, BaseObject *obj, uint32_t index, const BoxedValue value) = 0; 67 }; 68 } // namespace common 69 #endif // COMMON_INTERFACES_BASE_OBJECT_ACCESSOR_H