• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_INTERPRETER_FAST_RUNTIME_STUB_H
17 #define ECMASCRIPT_INTERPRETER_FAST_RUNTIME_STUB_H
18 
19 #include <memory>
20 #include "ecmascript/frames.h"
21 #include "ecmascript/js_tagged_value.h"
22 
23 namespace panda::ecmascript {
24 class GlobalEnv;
25 class PropertyAttributes;
26 
27 class FastRuntimeStub {
28 public:
29     /* -------------- Common API Begin, Don't change those interface!!! ----------------- */
30     static inline JSTaggedValue FastAdd(JSTaggedValue left, JSTaggedValue right);
31     static inline JSTaggedValue FastSub(JSTaggedValue left, JSTaggedValue right);
32     static inline JSTaggedValue FastMul(JSTaggedValue left, JSTaggedValue right);
33     static inline JSTaggedValue FastDiv(JSTaggedValue left, JSTaggedValue right);
34     static inline JSTaggedValue FastMod(JSTaggedValue left, JSTaggedValue right);
35     static inline JSTaggedValue FastEqual(JSTaggedValue left, JSTaggedValue right);
36     static inline JSTaggedValue FastTypeOf(JSThread *thread, JSTaggedValue obj);
37     static inline bool FastStrictEqual(JSTaggedValue left, JSTaggedValue right);
38     static inline JSTaggedValue NewLexicalEnvDyn(JSThread *thread, ObjectFactory *factory, uint16_t numVars);
39     static inline JSTaggedValue GetGlobalOwnProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
40     /* -------------- Special API For Multi-Language VM Begin ----------------- */
41     static inline bool IsSpecialIndexedObjForGet(JSTaggedValue obj);
42     static inline bool IsSpecialIndexedObjForSet(JSTaggedValue obj);
43     static inline JSTaggedValue GetElement(JSTaggedValue receiver, uint32_t index);
44     static inline JSTaggedValue GetElementWithArray(JSTaggedValue receiver, uint32_t index);
45     static inline bool SetElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value,
46                                   bool mayThrow);
47     static inline bool SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
48                                          JSTaggedValue value, bool mayThrow);
49     static inline bool SetGlobalOwnProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
50                                             JSTaggedValue value, bool mayThrow);
51 
52     // set property that is not accessor and is writable
53     static inline void SetOwnPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
54                                             JSTaggedValue value);
55     // set element that is not accessor and is writable
56     static inline bool SetOwnElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value);
57     static inline bool FastSetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, JSTaggedValue value,
58                                        bool mayThrow);
59     static inline JSTaggedValue FastGetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
60     static inline JSTaggedValue FindOwnProperty(JSThread *thread, JSObject *obj, TaggedArray *properties,
61                                                 JSTaggedValue key, PropertyAttributes *attr, uint32_t *indexOrEntry);
62     static inline JSTaggedValue FindOwnElement(TaggedArray *elements, uint32_t index, bool isDict,
63                                                PropertyAttributes *attr, uint32_t *indexOrEntry);
64     static inline JSTaggedValue FindOwnProperty(JSThread *thread, JSObject *obj, JSTaggedValue key);
65 
66     static inline JSTaggedValue FindOwnElement(JSObject *obj, uint32_t index);
67 
68     static inline JSTaggedValue HasOwnProperty(JSThread *thread, JSObject *obj, JSTaggedValue key);
69     /* -------------- Special API For Multi-Language VM End ----------------- */
70     /* -------------- Common API End, Don't change those interface!!! ----------------- */
71 
72     template<bool UseOwn = false>
73     static inline JSTaggedValue GetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
74     template<bool UseOwn = false>
75     static inline JSTaggedValue GetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
76     template<bool UseOwn = false>
77     static inline JSTaggedValue GetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
78     template<bool UseOwn = false>
79     static inline JSTaggedValue SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
80                                                   JSTaggedValue value);
81     template<bool UseOwn = false>
82     static inline JSTaggedValue SetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
83                                                    JSTaggedValue value);
84     template<bool UseOwn = false>
85     static inline JSTaggedValue SetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index,
86                                                    JSTaggedValue value);
87 
88     static inline bool FastSetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
89                                               JSTaggedValue value);
90     static inline bool FastSetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index,
91                                               JSTaggedValue value);
92     static inline JSTaggedValue FastGetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
93     static inline JSTaggedValue FastGetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
94     template<bool UseHole = false>
95     static inline JSTaggedValue FastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
96     static inline PropertyAttributes AddPropertyByName(JSThread *thread, JSHandle<JSObject> objHandle,
97                                                        JSHandle<JSTaggedValue> keyHandle,
98                                                        JSHandle<JSTaggedValue> valueHandle,
99                                                        PropertyAttributes attr);
100 
101     static inline JSTaggedValue NewThisObject(JSThread *thread, JSTaggedValue ctor, JSTaggedValue newTarget,
102                                               InterpretedFrame* state);
103 
104 private:
105     friend class ICRuntimeStub;
106     static inline bool IsSpecialIndexedObj(JSType jsType);
107     static inline bool IsSpecialReceiverObj(JSType jsType);
108     static inline int32_t TryToElementsIndex(JSTaggedValue key);
109     static inline JSTaggedValue CallGetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder,
110                                            JSTaggedValue value);
111     static inline JSTaggedValue CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value,
112                                            JSTaggedValue accessorValue);
113     static inline bool ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue accessorValue,
114                                         PropertyAttributes attr);
115     static inline JSTaggedValue AddPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index,
116                                                    JSTaggedValue value);
117 
118     // non ECMA standard jsapi container
119     static inline bool IsSpecialContainer(JSType jsType);
120     static inline JSTaggedValue GetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index,
121                                                      JSType jsType);
122     static inline JSTaggedValue SetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index,
123                                                      JSTaggedValue value, JSType jsType);
124 };
125 }  // namespace panda::ecmascript
126 
127 #endif  // ECMASCRIPT_INTERPRETER_OBJECT_OPERATOR_INL_H
128