• 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 NewSendableEnv(JSThread *thread, uint16_t numVars);
74     static JSTaggedValue NewLexicalEnvWithName(JSThread *thread, uint16_t numVars, uint16_t scopeId);
75     static JSTaggedValue CreateIterResultObj(JSThread *thread, JSTaggedValue value, JSTaggedValue flag);
76 
77     static JSTaggedValue CreateGeneratorObj(JSThread *thread, JSTaggedValue genFunc);
78     static JSTaggedValue SuspendGenerator(JSThread *thread, JSTaggedValue genObj, JSTaggedValue value);
79     static void SetGeneratorState(JSThread *thread, JSTaggedValue genObj, int32_t index);
80     static JSTaggedValue AsyncFunctionAwaitUncaught(JSThread *thread, JSTaggedValue asyncFuncObj, JSTaggedValue value);
81     static JSTaggedValue AsyncFunctionResolveOrReject(JSThread *thread, JSTaggedValue asyncFuncObj, JSTaggedValue value,
82                                                       bool is_resolve);
83 
84     static JSTaggedValue NewObjApply(JSThread *thread, JSTaggedValue func, JSTaggedValue array);
85     static void ThrowUndefinedIfHole(JSThread *thread, JSTaggedValue obj);
86     static void ThrowIfNotObject(JSThread *thread);
87     static void ThrowThrowNotExists(JSThread *thread);
88     static void ThrowPatternNonCoercible(JSThread *thread);
89     static JSTaggedValue ThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index, JSTaggedValue thisValue);
90     static void ThrowDeleteSuperProperty(JSThread *thread);
91 
92     static JSTaggedValue StOwnByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value);
93     static JSTaggedValue StOwnByNameWithNameSet(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop,
94                                                 JSTaggedValue value);
95     static JSTaggedValue StOwnByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, JSTaggedValue value);
96     static JSTaggedValue StOwnByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue value);
97     static JSTaggedValue StOwnByValueWithNameSet(JSThread *thread, JSTaggedValue obj, JSTaggedValue key,
98                                                  JSTaggedValue value);
99     static JSTaggedValue CreateEmptyArray(JSThread *thread, ObjectFactory *factory, JSHandle<GlobalEnv> globalEnv);
100     static JSTaggedValue CreateEmptyObject(JSThread *thread, ObjectFactory *factory, JSHandle<GlobalEnv> globalEnv);
101     static JSTaggedValue CreateObjectWithBuffer(JSThread *thread, ObjectFactory *factory, JSObject *literal);
102     static JSTaggedValue CreateObjectHavingMethod(JSThread *thread, ObjectFactory *factory, JSObject *literal,
103                                                   JSTaggedValue env);
104     static JSTaggedValue SetObjectWithProto(JSThread *thread, JSTaggedValue proto, JSTaggedValue obj);
105     static JSTaggedValue CreateArrayWithBuffer(JSThread *thread, ObjectFactory *factory, JSArray *literal);
106 
107     static JSTaggedValue GetTemplateObject(JSThread *thread, JSTaggedValue literal);
108     static JSTaggedValue GetNextPropName(JSThread *thread, JSTaggedValue iter);
109     static JSTaggedValue CopyDataProperties(JSThread *thread, JSTaggedValue dst, JSTaggedValue src);
110 
111     static JSTaggedValue GetUnmapedArgs(JSThread *thread, JSTaggedType *sp, uint32_t actualNumArgs, uint32_t startIdx);
112     static JSTaggedValue CopyRestArgs(JSThread *thread, JSTaggedType *sp, uint32_t restNumArgs, uint32_t startIdx);
113     static JSTaggedValue GetIterator(JSThread *thread, JSTaggedValue obj);
114     static JSTaggedValue GetAsyncIterator(JSThread *thread, JSTaggedValue obj);
115     static JSTaggedValue IterNext(JSThread *thread, JSTaggedValue iter);
116     static JSTaggedValue CloseIterator(JSThread *thread, JSTaggedValue iter);
117     static void StModuleVar(JSThread *thread, JSTaggedValue key, JSTaggedValue value);
118     static JSTaggedValue LdModuleVar(JSThread *thread, JSTaggedValue key, bool inner);
119     static void StModuleVar(JSThread *thread, int32_t index, JSTaggedValue value);
120     static JSTaggedValue LdLocalModuleVar(JSThread *thread, int32_t index);
121     static JSTaggedValue LdExternalModuleVar(JSThread *thread, int32_t index);
122     static JSTaggedValue LdSendableExternalModuleVar(JSThread *thread, int32_t index, JSTaggedValue thisFunc);
123     static JSTaggedValue LdSendableLocalModuleVar(JSThread *thread, int32_t index, JSTaggedValue thisFunc);
124     static JSTaggedValue LdLazyExternalModuleVar(JSThread *thread, int32_t index, JSTaggedValue thisFunc);
125     static JSTaggedValue LdLazySendableExternalModuleVar(JSThread *thread, int32_t index, JSTaggedValue thisFunc);
126     static JSTaggedValue CreateRegExpWithLiteral(JSThread *thread, JSTaggedValue pattern, uint8_t flags);
127     static JSTaggedValue GetIteratorNext(JSThread *thread, JSTaggedValue obj, JSTaggedValue method);
128 
129     static JSTaggedValue DefineGetterSetterByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop,
130                                                    JSTaggedValue getter, JSTaggedValue setter, bool flag);
131 
132     static JSTaggedValue LdObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, bool callGetter,
133                                       JSTaggedValue receiver);
134     static JSTaggedValue StObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, JSTaggedValue value);
135     static JSTaggedValue LdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter,
136                                      JSTaggedValue receiver);
137     static JSTaggedValue StObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value);
138     static JSTaggedValue LdObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter,
139                                       JSTaggedValue receiver);
140     static JSTaggedValue StObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value);
141     static JSTaggedValue TryLdGlobalByNameFromGlobalProto(JSThread *thread, JSTaggedValue global, JSTaggedValue prop);
142     static JSTaggedValue TryStGlobalByName(JSThread *thread, JSTaggedValue prop);
143     static JSTaggedValue LdGlobalVarFromGlobalProto(JSThread *thread, JSTaggedValue global, JSTaggedValue prop);
144     static JSTaggedValue StGlobalVar(JSThread *thread, JSTaggedValue prop, JSTaggedValue value);
145     static JSTaggedValue StGlobalRecord(JSThread *thread, JSTaggedValue prop, JSTaggedValue value, bool isConst);
146     static JSTaggedValue LdGlobalRecord(JSThread *thread, JSTaggedValue key);
147     static JSTaggedValue TryUpdateGlobalRecord(JSThread *thread, JSTaggedValue prop, JSTaggedValue value);
148     static JSTaggedValue StArraySpread(JSThread *thread, JSTaggedValue dst, JSTaggedValue index, JSTaggedValue src);
149 
150     static JSTaggedValue DefineFunc(JSThread *thread, JSTaggedValue constPool, uint16_t methodId,
151                                     JSTaggedValue module, uint16_t length, JSTaggedValue envHandle,
152                                     JSTaggedValue homeObject);
153     static JSTaggedValue GetSuperConstructor(JSThread *thread, JSTaggedValue ctor);
154     static JSTaggedValue SuperCall(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget, uint16_t firstVRegIdx,
155                                    uint16_t length);
156     static JSTaggedValue SuperCallSpread(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget,
157                                          JSTaggedValue array);
158     static JSTaggedValue SuperCallForwardAllArgs(JSThread *thread, JSTaggedType *sp, JSTaggedValue func,
159                                                  JSTaggedValue newTarget, uint32_t restNumArgs, uint32_t startIdx);
160     static JSTaggedValue DynamicImport(JSThread *thread, JSTaggedValue specifier, JSTaggedValue func);
161     static JSTaggedValue DefineMethod(JSThread *thread, Method *method, JSTaggedValue homeObject,
162                                       uint16_t length, JSTaggedValue env, JSTaggedValue module);
163     static JSTaggedValue LdSendableClass(JSThread *thread, JSTaggedValue env, uint16_t level);
164     static JSTaggedValue LdSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue thisFunc);
165     static JSTaggedValue StSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue value,
166                                         JSTaggedValue thisFunc);
167     static JSTaggedValue NotifyInlineCache(JSThread *thread, JSFunction *function);
168     static JSTaggedValue ThrowReferenceError(JSThread *thread, JSTaggedValue prop, const char *desc);
169 
170     static JSTaggedValue ResolveClass(JSThread *thread, JSTaggedValue ctor, TaggedArray *literal, JSTaggedValue base,
171                                       JSTaggedValue lexenv);
172     static JSTaggedValue CloneClassFromTemplate(JSThread *thread, JSTaggedValue ctor, JSTaggedValue base,
173                                                 JSTaggedValue lexenv);
174     static JSTaggedValue CreateClassWithBuffer(JSThread *thread, JSTaggedValue base,
175                                                JSTaggedValue lexenv, JSTaggedValue constpool,
176                                                uint16_t methodId, uint16_t literalId, JSTaggedValue module,
177                                                JSTaggedValue length);
178     static JSTaggedValue CreateSharedClass(JSThread *thread, JSTaggedValue base,
179                                            JSTaggedValue constpool, uint16_t methodId, uint16_t literalId,
180                                            uint16_t length, JSTaggedValue module);
181     static JSTaggedValue SetClassConstructorLength(JSThread *thread, JSTaggedValue ctor, JSTaggedValue length);
182     static JSTaggedValue GetModuleNamespace(JSThread *thread, JSTaggedValue localName);
183     static JSTaggedValue GetModuleNamespace(JSThread *thread, int32_t index);
184     static JSTaggedValue LdBigInt(JSThread *thread, JSTaggedValue numberBigInt);
185     static JSTaggedValue ThrowTypeError(JSThread *thread, const char *message);
186     static JSTaggedValue SetClassInheritanceRelationship(JSThread *thread, JSTaggedValue ctor, JSTaggedValue base);
187 
188     static JSTaggedValue AsyncGeneratorResolve(JSThread *thread, JSTaggedValue asyncFuncObj,
189                                                const JSTaggedValue value, JSTaggedValue flag);
190     static JSTaggedValue AsyncGeneratorReject(JSThread *thread, JSTaggedValue asyncFuncObj,
191                                               const JSTaggedValue value);
192     static JSTaggedValue CreateAsyncGeneratorObj(JSThread *thread, JSTaggedValue genFunc);
193 
194     static JSTaggedValue LdPatchVar(JSThread *thread, uint32_t index);
195     static JSTaggedValue StPatchVar(JSThread *thread, uint32_t index, JSTaggedValue value);
196 
197     static JSTaggedValue NotifyConcurrentResult(JSThread *thread, JSTaggedValue result, JSTaggedValue hint);
198     static JSTaggedValue DefineField(JSThread *thread, JSTaggedValue obj, JSTaggedValue propKey, JSTaggedValue value);
199     static JSTaggedValue CreatePrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
200         uint32_t count, JSTaggedValue constpool, uint32_t literalId, JSTaggedValue module);
201     static JSTaggedValue DefinePrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
202         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj, JSTaggedValue value);
203     static JSTaggedValue LdPrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
204         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj);
205     static JSTaggedValue StPrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv,
206         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj, JSTaggedValue value);
207     static JSTaggedValue TestIn(JSThread *thread, JSTaggedValue lexicalEnv,
208         uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj);
209     static JSTaggedValue UpdateAOTHClass(JSThread *thread, JSTaggedValue jshclass,
210                                          JSTaggedValue newjshclass, JSTaggedValue key);
211 
212 private:
213     static JSTaggedValue ThrowSyntaxError(JSThread *thread, const char *message);
214     static JSTaggedValue GetCallSpreadArgs(JSThread *thread, JSTaggedValue array);
215 };
216 }  // namespace panda::ecmascript
217 #endif  // ECMASCRIPT_INTERPRETER_SLOW_RUNTIME_STUB_H
218