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 PUBLIC_API Get(const JSThread *thread, JSHandle<JSObject> receiver, uint32_t idx); 29 static JSTaggedValue Get(const JSThread *thread, JSObject *receiver, uint32_t idx); 30 static JSTaggedValue PUBLIC_API FastGet(const JSThread *thread, JSHandle<TaggedArray> elements, uint32_t idx, 31 ElementsKind kind); 32 33 template<typename T> 34 static void Set(const JSThread *thread, JSHandle<JSObject> receiver, uint32_t idx, const JSHandle<T> &value, 35 bool needTransition, ElementsKind extraKind = ElementsKind::NONE); 36 37 template<typename T> 38 static void FastSet(const JSThread *thread, JSHandle<TaggedArray> elements, uint32_t idx, 39 const JSHandle<T> &value, ElementsKind kind); 40 static bool IsDictionaryMode(const JSThread *thread, JSHandle<JSObject> receiver); 41 static bool IsDictionaryMode(const JSThread *thread, JSObject *receiver); 42 static uint32_t GetElementsLength(const JSThread *thread, JSHandle<JSObject> receiver); 43 static uint32_t GetElementsLength(const JSThread *thread, JSObject *receiver); 44 45 static JSTaggedValue GetTaggedValueWithElementsKind(JSTaggedType rawValue, ElementsKind kind); 46 47 static void CopyJSArrayObject(const JSThread *thread, JSHandle<JSObject>srcObj, JSHandle<JSObject>dstObj, 48 uint32_t effectiveLength); 49 static void CopyJSArrayToTaggedArray(const JSThread *thread, JSHandle<JSObject>srcObj, 50 JSHandle<TaggedArray>dstElements, uint32_t effectiveLength); 51 static JSTaggedType PUBLIC_API ConvertTaggedValueWithElementsKind(JSTaggedValue rawValue, ElementsKind kind); 52 private: 53 }; 54 } // namespace ecmascript 55 } // namespace panda 56 #endif // ECMASCRIPT_ELEMENT_ACCESSOR_H 57 58