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