• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_OBJECT_FAST_OPERATOR_H
17 #define ECMASCRIPT_OBJECT_FAST_OPERATOR_H
18 
19 #include "ecmascript/js_handle.h"
20 #include "ecmascript/js_hclass.h"
21 #include "ecmascript/js_tagged_value.h"
22 #include "ecmascript/property_attributes.h"
23 
24 namespace panda::ecmascript {
25 using SCheckMode = JSShared::SCheckMode;
26 
27 class ObjectFastOperator final {
28 public:
29     enum class Status: uint8_t {
30         None = 0x00UL,
31         UseOwn = 0x01UL,
32         GetInternal = 0x1UL << 1,
33         DefineSemantics = 0x1UL << 2,
34     };
35 
UseOwn(Status status)36     static inline bool UseOwn(Status status)
37     {
38         return (static_cast<int32_t>(status) & static_cast<int32_t>(Status::UseOwn)) > 0;
39     }
40 
GetInternal(Status status)41     static inline bool GetInternal(Status status)
42     {
43         return (static_cast<int32_t>(status) & static_cast<int32_t>(Status::GetInternal)) > 0;
44     }
45 
DefineSemantics(Status status)46     static inline bool DefineSemantics(Status status)
47     {
48         return (static_cast<uint32_t>(status) & static_cast<int32_t>(Status::DefineSemantics)) > 0;
49     }
50 
51     static inline std::pair<JSTaggedValue, bool> HasOwnProperty(JSThread *thread,
52                                                                 JSTaggedValue receiver, JSTaggedValue key);
53 
54     template<Status status = Status::None>
55     static inline JSTaggedValue TryFastHasProperty(JSThread *thread, JSTaggedValue receiver,
56                                                    JSMutableHandle<JSTaggedValue> keyHandle);
57 
58     template<Status status = Status::None>
59     static inline JSTaggedValue TryFastGetPropertyByValue(JSThread *thread, JSTaggedValue receiver,
60                                                           JSMutableHandle<JSTaggedValue> keyHandle);
61 
62     template<Status status = Status::None>
63     static inline JSTaggedValue TryFastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
64 
65     template<Status status = Status::None>
66     static inline JSTaggedValue TryGetPropertyByNameThroughCacheAtLocal(JSThread *thread, JSTaggedValue receiver,
67                                                                         JSTaggedValue key);
68 
69     template<Status status = Status::None>
70     static inline JSTaggedValue GetPropertyByName(JSThread *thread, JSTaggedValue receiver,
71                                                   JSTaggedValue key, bool noAllocate = false,
72                                                   bool *isCallGetter = nullptr);
73 
74     template <Status status = Status::None>
75     static inline JSTaggedValue TrySetPropertyByNameThroughCacheAtLocal(JSThread *thread,
76         JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key, JSHandle<JSTaggedValue> value);
77 
78     template <Status status = Status::None>
79     static inline JSTaggedValue SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
80                                                   JSTaggedValue value, SCheckMode sCheckMode = SCheckMode::CHECK);
81 
82     static inline JSTaggedValue SetJsonPropertyByName(JSThread *thread, JSTaggedValue receiver,
83                                                       JSTaggedValue key, JSTaggedValue value);
84 
85     template <Status status = Status::None>
86     static inline JSTaggedValue GetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
87 
88     template <Status status = Status::None>
89     static inline JSTaggedValue SetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index,
90                                                    JSTaggedValue value);
91 
92     template <Status status = Status::None>
93     static inline JSTaggedValue GetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
94 
95     template <Status status = Status::None>
96     static inline JSTaggedValue SetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
97                                                    JSTaggedValue value, SCheckMode sCheckMode = SCheckMode::CHECK);
98 
99     static inline bool FastSetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
100                                               JSTaggedValue value, SCheckMode sCheckMode = SCheckMode::CHECK);
101 
102     static inline bool FastSetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index,
103                                               JSTaggedValue value);
104 
105     static inline JSTaggedValue FastGetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
106 
107     static inline JSTaggedValue FastGetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
108                                                        SCheckMode sCheckMode = SCheckMode::CHECK);
109 
110     static inline JSTaggedValue FastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
111 
112     static inline JSTaggedValue FastParseDate(const JSThread *thread, const EcmaString *str);
113 
114     static inline PropertyAttributes AddPropertyByName(JSThread *thread, JSHandle<JSObject> objHandle,
115                                                        JSHandle<JSTaggedValue> keyHandle,
116                                                        JSHandle<JSTaggedValue> valueHandle,
117                                                        PropertyAttributes attr);
118 
119     static inline JSTaggedValue CallGetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder,
120                                            JSTaggedValue value);
121 
122     static inline int64_t TryToElementsIndex(JSThread *thread, JSTaggedValue key);
123 private:
124     static inline JSTaggedValue CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value,
125                                            JSTaggedValue accessorValue);
126 
127     static inline bool ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue accessorValue,
128                                         PropertyAttributes attr);
129 
130     static inline bool IsSpecialIndexedObj(JSType jsType);
131 
132     static inline bool IsJSSharedArray(JSType jsType);
133 
134     static inline bool IsFastTypeArray(JSType jsType);
135 
136     static inline bool IsString(JSType jsType);
137 
138     static inline bool IsJSPrimitiveRef(JSType jsType);
139 
140     static inline bool IsJSProxy(JSType jsType);
141 
142     static inline bool TryStringOrSymbolToIndex(JSThread *thread, JSTaggedValue key, uint32_t *output);
143 
144     static inline JSTaggedValue FastGetTypeArrayProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder,
145                                                          JSTaggedValue key, JSType jsType);
146 
147     static inline JSTaggedValue FastSetTypeArrayProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder,
148                                                          JSTaggedValue key, JSTaggedValue value, JSType jsType);
149 
150     // non ECMA standard jsapi container
151     static inline bool IsSpecialContainer(JSType jsType);
152 
153     static inline JSTaggedValue GetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index,
154                                                      JSType jsType);
155 
156     static inline JSTaggedValue SetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index,
157                                                      JSTaggedValue value, JSType jsType);
158 
159     static inline JSTaggedValue AddPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index,
160                                                    JSTaggedValue value);
161 
162     static inline bool GetNumFromString(const char *str, int len, int *index, int *num);
163 
164     friend class FastRuntimeStub;
165 };
166 }  // namespace panda::ecmascript
167 #endif  // ECMASCRIPT_OBJECT_FAST_OPERATOR_H
168