1 /* 2 * Copyright (c) 2022-2023 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_ELEMENT_ACCESSOR_H 17 #define ECMASCRIPT_ELEMENT_ACCESSOR_H 18 19 #include "ecmascript/js_hclass.h" 20 #include "ecmascript/js_tagged_value.h" 21 #include "ecmascript/tagged_array.h" 22 23 namespace panda { 24 namespace ecmascript { 25 // ElementAccessor intends to replace all .GetElements and share the common following methods. 26 class ElementAccessor { 27 public: 28 static JSTaggedValue Get(JSHandle<JSObject> receiver, uint32_t idx); 29 static JSTaggedValue Get(JSObject *receiver, uint32_t idx); 30 31 template<typename T> 32 static void Set(const JSThread *thread, JSHandle<JSObject> receiver, uint32_t idx, const JSHandle<T> &value, 33 bool needTransition, ElementsKind extraKind = ElementsKind::NONE); 34 35 template <bool needBarrier = true> 36 static void Set(const JSThread *thread, JSHandle<JSObject> receiver, uint32_t idx, const JSTaggedValue &value, 37 bool needTransition, ElementsKind extraKind = ElementsKind::NONE); 38 39 static bool IsDictionaryMode(JSHandle<JSObject> receiver); 40 static bool IsDictionaryMode(JSObject *receiver); 41 42 static uint32_t GetElementsLength(JSHandle<JSObject> receiver); 43 static uint32_t GetElementsLength(JSObject *receiver); 44 45 static JSTaggedValue GetTaggedValueWithElementsKind(JSTaggedType rawValue, ElementsKind kind); 46 static JSTaggedType ConvertTaggedValueWithElementsKind(JSTaggedValue rawValue, ElementsKind kind); 47 private: 48 }; 49 } // namespace ecmascript 50 } // namespace panda 51 #endif // ECMASCRIPT_ELEMENT_ACCESSOR_H 52 53