• 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     /* -------------- Common API Begin, Don't change those interface!!! ----------------- */
30     static JSTaggedValue CallSpreadDyn(JSThread *thread, JSTaggedValue func, JSTaggedValue obj, JSTaggedValue array);
31     static JSTaggedValue NegDyn(JSThread *thread, JSTaggedValue value);
32     static JSTaggedValue AsyncFunctionEnter(JSThread *thread);
33     static JSTaggedValue ToNumber(JSThread *thread, JSTaggedValue value);
34     static JSTaggedValue NotDyn(JSThread *thread, JSTaggedValue value);
35     static JSTaggedValue IncDyn(JSThread *thread, JSTaggedValue value);
36     static JSTaggedValue DecDyn(JSThread *thread, JSTaggedValue value);
37     static void ThrowDyn(JSThread *thread, JSTaggedValue value);
38     static JSTaggedValue GetPropIterator(JSThread *thread, JSTaggedValue value);
39     static void ThrowConstAssignment(JSThread *thread, JSTaggedValue value);
40     static JSTaggedValue Add2Dyn(JSThread *thread, EcmaVM *ecma_vm, JSTaggedValue left, JSTaggedValue right);
41     static JSTaggedValue Sub2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
42     static JSTaggedValue Mul2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
43     static JSTaggedValue Div2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
44     static JSTaggedValue Mod2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
45     static JSTaggedValue EqDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
46     static JSTaggedValue NotEqDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
47     static JSTaggedValue LessDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
48     static JSTaggedValue LessEqDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
49     static JSTaggedValue GreaterDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
50     static JSTaggedValue GreaterEqDyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
51     static JSTaggedValue Shl2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
52     static JSTaggedValue Shr2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
53     static JSTaggedValue Ashr2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
54     static JSTaggedValue And2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
55     static JSTaggedValue Or2Dyn(JSThread *thread, JSTaggedValue left, JSTaggedValue right);
56     static JSTaggedValue Xor2Dyn(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 NewObjDynRange(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 ExpDyn(JSThread *thread, JSTaggedValue base, JSTaggedValue exponent);
67     static JSTaggedValue IsInDyn(JSThread *thread, JSTaggedValue prop, JSTaggedValue obj);
68     static JSTaggedValue InstanceofDyn(JSThread *thread, JSTaggedValue obj, JSTaggedValue target);
69 
70     static JSTaggedValue NewLexicalEnvDyn(JSThread *thread, uint16_t numVars);
71     static JSTaggedValue NewLexicalEnvWithNameDyn(JSThread *thread, uint16_t numVars, uint16_t scopeId);
72     static JSTaggedValue CreateIterResultObj(JSThread *thread, JSTaggedValue value, JSTaggedValue flag);
73 
74     static JSTaggedValue CreateGeneratorObj(JSThread *thread, JSTaggedValue genFunc);
75     static JSTaggedValue SuspendGenerator(JSThread *thread, JSTaggedValue genObj, JSTaggedValue value);
76     static JSTaggedValue AsyncFunctionAwaitUncaught(JSThread *thread, JSTaggedValue asyncFuncObj, JSTaggedValue value);
77     static JSTaggedValue AsyncFunctionResolveOrReject(JSThread *thread, JSTaggedValue asyncFuncObj, JSTaggedValue value,
78                                                       bool is_resolve);
79 
80     static JSTaggedValue NewObjSpreadDyn(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget,
81                                          JSTaggedValue array);
82     static void ThrowUndefinedIfHole(JSThread *thread, JSTaggedValue obj);
83     static void ThrowIfNotObject(JSThread *thread);
84     static void ThrowThrowNotExists(JSThread *thread);
85     static void ThrowPatternNonCoercible(JSThread *thread);
86     static JSTaggedValue ThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index, JSTaggedValue thisValue);
87     static void ThrowDeleteSuperProperty(JSThread *thread);
88 
89     static JSTaggedValue StOwnByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value);
90     static JSTaggedValue StOwnByNameWithNameSet(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop,
91                                                 JSTaggedValue value);
92     static JSTaggedValue StOwnByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, JSTaggedValue value);
93     static JSTaggedValue StOwnByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue value);
94     static JSTaggedValue StOwnByValueWithNameSet(JSThread *thread, JSTaggedValue obj, JSTaggedValue key,
95                                                  JSTaggedValue value);
96     static JSTaggedValue CreateEmptyArray(JSThread *thread, ObjectFactory *factory, JSHandle<GlobalEnv> globalEnv);
97     static JSTaggedValue CreateEmptyObject(JSThread *thread, ObjectFactory *factory, JSHandle<GlobalEnv> globalEnv);
98     static JSTaggedValue CreateObjectWithBuffer(JSThread *thread, ObjectFactory *factory, JSObject *literal);
99     static JSTaggedValue CreateObjectHavingMethod(JSThread *thread, ObjectFactory *factory, JSObject *literal,
100                                                   JSTaggedValue env, ConstantPool *constpool);
101     static JSTaggedValue SetObjectWithProto(JSThread *thread, JSTaggedValue proto, JSTaggedValue obj);
102     static JSTaggedValue CreateArrayWithBuffer(JSThread *thread, ObjectFactory *factory, JSArray *literal);
103 
104     static JSTaggedValue GetTemplateObject(JSThread *thread, JSTaggedValue literal);
105     static JSTaggedValue GetNextPropName(JSThread *thread, JSTaggedValue iter);
106     static JSTaggedValue CopyDataProperties(JSThread *thread, JSTaggedValue dst, JSTaggedValue src);
107 
108     static JSTaggedValue GetUnmapedArgs(JSThread *thread, JSTaggedType *sp, uint32_t actualNumArgs, uint32_t startIdx);
109     static JSTaggedValue CopyRestArgs(JSThread *thread, JSTaggedType *sp, uint32_t restNumArgs, uint32_t startIdx);
110     static JSTaggedValue GetIterator(JSThread *thread, JSTaggedValue obj);
111     static JSTaggedValue IterNext(JSThread *thread, JSTaggedValue iter);
112     static JSTaggedValue CloseIterator(JSThread *thread, JSTaggedValue iter);
113     static JSTaggedValue ImportModule(JSThread *thread, JSTaggedValue moduleName);
114     static void StModuleVar(JSThread *thread, JSTaggedValue exportName, JSTaggedValue exportObj);
115     static void CopyModule(JSThread *thread, JSTaggedValue srcModule);
116     static JSTaggedValue LdModvarByName(JSThread *thread, JSTaggedValue moduleObj, JSTaggedValue itemName);
117     static JSTaggedValue CreateRegExpWithLiteral(JSThread *thread, JSTaggedValue pattern, uint8_t flags);
118     static JSTaggedValue GetIteratorNext(JSThread *thread, JSTaggedValue obj, JSTaggedValue method);
119 
120     static JSTaggedValue DefineGetterSetterByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop,
121                                                    JSTaggedValue getter, JSTaggedValue setter, bool flag);
122 
123     static JSTaggedValue LdObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, bool callGetter,
124                                       JSTaggedValue receiver);
125     static JSTaggedValue StObjByIndex(JSThread *thread, JSTaggedValue obj, uint32_t idx, JSTaggedValue value);
126     static JSTaggedValue LdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter,
127                                      JSTaggedValue receiver);
128     static JSTaggedValue StObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value);
129     static JSTaggedValue LdObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, bool callGetter,
130                                       JSTaggedValue receiver);
131     static JSTaggedValue StObjByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, JSTaggedValue value);
132     static JSTaggedValue TryLdGlobalByName(JSThread *thread, JSTaggedValue global, JSTaggedValue prop);
133     static JSTaggedValue TryStGlobalByName(JSThread *thread, JSTaggedValue prop);
134     static JSTaggedValue LdGlobalVar(JSThread *thread, JSTaggedValue global, JSTaggedValue prop);
135     static JSTaggedValue StGlobalVar(JSThread *thread, JSTaggedValue prop, JSTaggedValue value);
136     static JSTaggedValue StGlobalRecord(JSThread *thread, JSTaggedValue prop, JSTaggedValue value, bool isConst);
137     static JSTaggedValue LdGlobalRecord(JSThread *thread, JSTaggedValue key);
138     static JSTaggedValue TryUpdateGlobalRecord(JSThread *thread, JSTaggedValue prop, JSTaggedValue value);
139     static JSTaggedValue StArraySpread(JSThread *thread, JSTaggedValue dst, JSTaggedValue index, JSTaggedValue src);
140 
141     static JSTaggedValue DefineGeneratorFunc(JSThread *thread, JSFunction *func);
142     static JSTaggedValue DefineAsyncFunc(JSThread *thread, JSFunction *func);
143     static JSTaggedValue DefineNCFuncDyn(JSThread *thread, JSFunction *func);
144     static JSTaggedValue DefinefuncDyn(JSThread *thread, JSFunction *func);
145 
146     static JSTaggedValue SuperCall(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget, uint16_t firstVRegIdx,
147                                    uint16_t length);
148     static JSTaggedValue SuperCallSpread(JSThread *thread, JSTaggedValue func, JSTaggedValue newTarget,
149                                          JSTaggedValue array);
150     static JSTaggedValue DefineMethod(JSThread *thread, JSFunction *func, JSTaggedValue homeObject);
151     static JSTaggedValue LdSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue thisFunc);
152     static JSTaggedValue StSuperByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue key, JSTaggedValue value,
153                                         JSTaggedValue thisFunc);
154     static JSTaggedValue NotifyInlineCache(JSThread *thread, JSFunction *func, JSMethod *method);
155     static JSTaggedValue ThrowReferenceError(JSThread *thread, JSTaggedValue prop, const char *desc);
156 
157     static JSTaggedValue ResolveClass(JSThread *thread, JSTaggedValue ctor, TaggedArray *literal, JSTaggedValue base,
158                                       JSTaggedValue lexenv, ConstantPool *constpool);
159     static JSTaggedValue CloneClassFromTemplate(JSThread *thread, JSTaggedValue ctor, JSTaggedValue base,
160                                                 JSTaggedValue lexenv, ConstantPool *constpool);
161     static JSTaggedValue SetClassConstructorLength(JSThread *thread, JSTaggedValue ctor, JSTaggedValue length);
162     static JSTaggedValue LdBigInt(JSThread *thread, JSTaggedValue numberBigInt);
163     static JSTaggedValue ThrowTypeError(JSThread *thread, const char *message);
164     /* -------------- Common API End, Don't change those interface!!! ----------------- */
165 
166 private:
167     static JSTaggedValue ThrowSyntaxError(JSThread *thread, const char *message);
168     static JSTaggedValue GetCallSpreadArgs(JSThread *thread, JSTaggedValue array);
169     static JSTaggedValue SetClassInheritanceRelationship(JSThread *thread, JSTaggedValue ctor, JSTaggedValue base);
170 };
171 }  // namespace panda::ecmascript
172 #endif  // ECMASCRIPT_INTERPRETER_SLOW_RUNTIME_STUB_H
173