• 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_SLOW_RUNTIME_STUB_H
17 #define ECMASCRIPT_INTERPRETER_SLOW_RUNTIME_STUB_H
18 
19 #include "ecmascript/jspandafile/program_object.h"
20 #include "ecmascript/js_tagged_value.h"
21 #include "ecmascript/js_thread.h"
22 
23 namespace panda::ecmascript {
24 class GlobalEnv;
25 class JSArray;
26 
27 class SlowRuntimeStub {
28 public:
29     static JSTaggedValue CallSpread(JSThread *thread, JSTaggedValue func, JSTaggedValue obj, JSTaggedValue array);
30     static JSTaggedValue Neg(JSThread *thread, JSTaggedValue value);
31     static JSTaggedValue AsyncFunctionEnter(JSThread *thread);
32     static JSTaggedValue ToNumber(JSThread *thread, JSTaggedValue value);
33     static JSTaggedValue ToNumeric(JSThread *thread, JSTaggedValue value);
34     static JSTaggedValue Not(JSThread *thread, JSTaggedValue value);
35     static JSTaggedValue Inc(JSThread *thread, JSTaggedValue value);
36     static JSTaggedValue Dec(JSThread *thread, JSTaggedValue value);
37     static void Throw(JSThread *thread, JSTaggedValue value);
38     static JSTaggedValue GetPropIterator(JSThread *thread, JSTaggedValue value);
39     static void ThrowConstAssignment(JSThread *thread, JSTaggedValue value);
40     static JSTaggedValue Add2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
41     static JSTaggedValue Sub2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
42     static JSTaggedValue Mul2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
43     static JSTaggedValue Div2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
44     static JSTaggedValue Mod2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
45     static JSTaggedValue Eq(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
46     static JSTaggedValue NotEq(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
47     static JSTaggedValue Less(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
48     static JSTaggedValue LessEq(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
49     static JSTaggedValue Greater(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
50     static JSTaggedValue GreaterEq(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
51     static JSTaggedValue Shl2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
52     static JSTaggedValue Shr2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
53     static JSTaggedValue Ashr2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
54     static JSTaggedValue And2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
55     static JSTaggedValue Or2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
56     static JSTaggedValue Xor2(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
57 
58     static JSTaggedValue ToJSTaggedValueWithInt32(JSThread *thread, JSTaggedValue value);
59     static JSTaggedValue ToJSTaggedValueWithUint32(JSThread *thread, JSTaggedValue value);
60 
61     static JSTaggedValue DelObjProp(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop);
62     static JSTaggedValue NewObjRange(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget,
63                                         uint16_t firstArgIdx, uint16_t length);
64     static JSTaggedValue CreateObjectWithExcludedKeys(JSThread *thread, uint16_t numKeys, JSTaggedValue objVal,
65                                                       uint16_t firstArgRegIdx);
66     static JSTaggedValue Exp(JSThread *thread, JSTaggedValue base, JSTaggedValue exponent);
67     static JSTaggedValue IsIn(JSThread *thread, JSTaggedValue prop, JSTaggedValue obj);
68     static JSTaggedValue Instanceof(JSThread *thread, JSTaggedValue obj, JSTaggedValue target);
69     static JSTaggedValue InstanceofByHandler(JSThread *thread, JSTaggedValue target, JSTaggedValue object,
70                                              JSTaggedValue instOfHandler);
71 
72     static JSTaggedValue NewLexicalEnv(JSThread *thread, uint16_t numVars);
73     static JSTaggedValue NewLexicalEnvWithName(JSThread *thread, uint16_t numVars, uint16_t scopeId);
74     static JSTaggedValue CreateIterResultObj(JSThread *thread, JSTaggedValue value, JSTaggedValue flag);
75 
76     static JSTaggedValue CreateGeneratorObj(JSThread *thread, JSTaggedValue genFunc);
77     static JSTaggedValue SuspendGenerator(JSThread *thread, JSTaggedValue genObj, JSTaggedValue value);
78     static void SetGeneratorState(JSThread *thread, JSTaggedValue genObj, int32_t index);
79     static JSTaggedValue AsyncFunctionAwaitUncaught(JSThread *thread, JSTaggedValue asyncFuncObj, JSTaggedValue value);
80     static JSTaggedValue AsyncFunctionResolveOrReject(JSThread *thread, JSTaggedValue asyncFuncObj, JSTaggedValue value,
81                                                       bool is_resolve);
82 
83     static JSTaggedValue NewObjApply(JSThread *thread, JSTaggedValue func, JSTaggedValue array);
84     static void ThrowUndefinedIfHole(JSThread *thread, JSTaggedValue obj);
85     static void ThrowIfNotObject(JSThread *thread);
86     static void ThrowThrowNotExists(JSThread *thread);
87     static void ThrowPatternNonCoercible(JSThread *thread);
88     static JSTaggedValue ThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index, JSTaggedValue thisValue);
89     static void ThrowDeleteSuperProperty(JSThread *thread);
90 
91     static JSTaggedValue StOwnByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value);
92     static JSTaggedValue StOwnByNameWithNameSet(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop,
93                                                 JSTaggedValue value);
94     static JSTaggedValue StOwnByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, JSTaggedValue value);
95     static JSTaggedValue StOwnByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue value);
96     static JSTaggedValue StOwnByValueWithNameSet(JSThread *thread, JSTaggedValue obj, JSTaggedValue key,
97                                                  JSTaggedValue value);
98     static JSTaggedValue CreateEmptyArray(JSThread *thread, ObjectFactory *factory, JSHandle<GlobalEnv> globalEnv);
99     static JSTaggedValue CreateEmptyObject(JSThread *thread, ObjectFactory *factory, JSHandle<GlobalEnv> globalEnv);
100     static JSTaggedValue CreateObjectWithBuffer(JSThread *thread, ObjectFactory *factory, JSObject *literal);
101     static JSTaggedValue CreateObjectHavingMethod(JSThread *thread, ObjectFactory *factory, JSObject *literal,
102                                                   JSTaggedValue env);
103     static JSTaggedValue SetObjectWithProto(JSThread *thread, JSTaggedValue proto, JSTaggedValue obj);
104     static JSTaggedValue CreateArrayWithBuffer(JSThread *thread, ObjectFactory *factory, JSArray *literal);
105 
106     static JSTaggedValue GetTemplateObject(JSThread *thread, JSTaggedValue literal);
107     static JSTaggedValue GetNextPropName(JSThread *thread, JSTaggedValue iter);
108     static JSTaggedValue CopyDataProperties(JSThread *thread, JSTaggedValue dst, JSTaggedValue src);
109 
110     static JSTaggedValue GetUnmapedArgs(JSThread *thread, JSTaggedType *sp, uint32_t actualNumArgs, uint32_t startIdx);
111     static JSTaggedValue CopyRestArgs(JSThread *thread, JSTaggedType *sp, uint32_t restNumArgs, uint32_t startIdx);
112     static JSTaggedValue GetIterator(JSThread *thread, JSTaggedValue obj);
113     static JSTaggedValue GetAsyncIterator(JSThread *thread, JSTaggedValue obj);
114     static JSTaggedValue IterNext(JSThread *thread, JSTaggedValue iter);
115     static JSTaggedValue CloseIterator(JSThread *thread, JSTaggedValue iter);
116     static void StModuleVar(JSThread *thread, JSTaggedValue key, JSTaggedValue value);
117     static JSTaggedValue LdModuleVar(JSThread *thread, JSTaggedValue key, bool inner);
118     static void StModuleVar(JSThread *thread, int32_t index, JSTaggedValue value);
119     static JSTaggedValue LdLocalModuleVar(JSThread *thread, int32_t index);
120     static JSTaggedValue LdExternalModuleVar(JSThread *thread, int32_t index);
121     static JSTaggedValue CreateRegExpWithLiteral(JSThread *thread, JSTaggedValue pattern, uint8_t flags);
122     static JSTaggedValue GetIteratorNext(JSThread *thread, JSTaggedValue obj, JSTaggedValue method);
123 
124     static JSTaggedValue DefineGetterSetterByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop,
125                                                    JSTaggedValue getter, JSTaggedValue setter, bool flag);
126 
127     static JSTaggedValue LdObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, bool callGetter,
128                                       JSTaggedValue receiver);
129     static JSTaggedValue StObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, JSTaggedValue value);
130     static JSTaggedValue LdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter,
131                                      JSTaggedValue receiver);
132     static JSTaggedValue StObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value);
133     static JSTaggedValue LdObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter,
134                                       JSTaggedValue receiver);
135     static JSTaggedValue StObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value);
136     static JSTaggedValue TryLdGlobalByNameFromGlobalProto(JSThread *thread, JSTaggedValue global, JSTaggedValue prop);
137     static JSTaggedValue TryStGlobalByName(JSThread *thread, JSTaggedValue prop);
138     static JSTaggedValue LdGlobalVarFromGlobalProto(JSThread *thread, JSTaggedValue global, JSTaggedValue prop);
139     static JSTaggedValue StGlobalVar(JSThread *thread, JSTaggedValue prop, JSTaggedValue value);
140     static JSTaggedValue StGlobalRecord(JSThread *thread, JSTaggedValue prop, JSTaggedValue value, bool isConst);
141     static JSTaggedValue LdGlobalRecord(JSThread *thread, JSTaggedValue key);
142     static JSTaggedValue TryUpdateGlobalRecord(JSThread *thread, JSTaggedValue prop, JSTaggedValue value);
143     static JSTaggedValue StArraySpread(JSThread *thread, JSTaggedValue dst, JSTaggedValue index, JSTaggedValue src);
144 
145     static JSTaggedValue DefineFunc(JSThread *thread, JSTaggedValue constPool, uint16_t methodId,
146                                     JSTaggedValue module, uint16_t length, JSTaggedValue envHandle,
147                                     JSTaggedValue homeObject);
148     static JSTaggedValue GetSuperConstructor(JSThread *thread, JSTaggedValue ctor);
149     static JSTaggedValue SuperCall(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget, uint16_t firstVRegIdx,
150                                    uint16_t length);
151     static JSTaggedValue SuperCallSpread(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget,
152                                          JSTaggedValue array);
153     static JSTaggedValue DynamicImport(JSThread *thread, JSTaggedValue specifier, JSTaggedValue func);
154     static JSTaggedValue DefineMethod(JSThread *thread, Method *method, JSTaggedValue homeObject,
155                                       uint16_t length, JSTaggedValue env);
156     static JSTaggedValue LdSendableClass(JSThread *thread, JSTaggedValue env, uint16_t level);
157     static JSTaggedValue LdSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue thisFunc);
158     static JSTaggedValue StSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue value,
159                                         JSTaggedValue thisFunc);
160     static JSTaggedValue NotifyInlineCache(JSThread *thread, Method *method);
161     static JSTaggedValue ThrowReferenceError(JSThread *thread, JSTaggedValue prop, const char *desc);
162 
163     static JSTaggedValue ResolveClass(JSThread *thread, JSTaggedValue ctor, TaggedArray *literal, JSTaggedValue base,
164                                       JSTaggedValue lexenv);
165     static JSTaggedValue CloneClassFromTemplate(JSThread *thread, JSTaggedValue ctor, JSTaggedValue base,
166                                                 JSTaggedValue lexenv);
167     static JSTaggedValue CreateClassWithBuffer(JSThread *thread, JSTaggedValue base,
168                                                JSTaggedValue lexenv, JSTaggedValue constpool,
169                                                uint16_t methodId, uint16_t literalId, JSTaggedValue module,
170                                                JSTaggedValue length);
171     static JSTaggedValue CreateSharedClass(JSThread *thread, JSTaggedValue base,
172                                            JSTaggedValue constpool, uint16_t methodId, uint16_t literalId,
173                                            uint16_t length, JSTaggedValue module);
174     static JSTaggedValue SetClassConstructorLength(JSThread *thread, JSTaggedValue ctor, JSTaggedValue length);
175     static JSTaggedValue GetModuleNamespace(JSThread *thread, JSTaggedValue localName);
176     static JSTaggedValue GetModuleNamespace(JSThread *thread, int32_t index);
177     static JSTaggedValue LdBigInt(JSThread *thread, JSTaggedValue numberBigInt);
178     static JSTaggedValue ThrowTypeError(JSThread *thread, const char *message);
179     static JSTaggedValue SetClassInheritanceRelationship(JSThread *thread, JSTaggedValue ctor, JSTaggedValue base);
180 
181     static JSTaggedValue AsyncGeneratorResolve(JSThread *thread, JSTaggedValue asyncFuncObj,
182                                                const JSTaggedValue value, JSTaggedValue flag);
183     static JSTaggedValue AsyncGeneratorReject(JSThread *thread, JSTaggedValue asyncFuncObj,
184                                               const JSTaggedValue value);
185     static JSTaggedValue CreateAsyncGeneratorObj(JSThread *thread, JSTaggedValue genFunc);
186 
187     static JSTaggedValue LdPatchVar(JSThread *thread, uint32_t index);
188     static JSTaggedValue StPatchVar(JSThread *thread, uint32_t index, JSTaggedValue value);
189 
190     static JSTaggedValue NotifyConcurrentResult(JSThread *thread, JSTaggedValue result, JSTaggedValue hint);
191     static JSTaggedValue DefineField(JSThread *thread, JSTaggedValue obj, JSTaggedValue propKey, JSTaggedValue value);
192     static JSTaggedValue CreatePrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
193         uint32_t count, JSTaggedValue constpool, uint32_t literalId, JSTaggedValue module);
194     static JSTaggedValue DefinePrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
195         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj, JSTaggedValue value);
196     static JSTaggedValue LdPrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
197         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj);
198     static JSTaggedValue StPrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
199         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj, JSTaggedValue value);
200     static JSTaggedValue TestIn(JSThread *thread, JSTaggedValue lexicalEnv,
201         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj);
202     static JSTaggedValue UpdateAOTHClass(JSThread *thread, JSTaggedValue jshclass,
203                                          JSTaggedValue newjshclass, JSTaggedValue key);
204 
205 private:
206     static JSTaggedValue ThrowSyntaxError(JSThread *thread, const char *message);
207     static JSTaggedValue GetCallSpreadArgs(JSThread *thread, JSTaggedValue array);
208 };
209 }  // namespace panda::ecmascript
210 #endif  // ECMASCRIPT_INTERPRETER_SLOW_RUNTIME_STUB_H
211