• 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_LANGUAGE_CONTEXT_H
17 #define ECMASCRIPT_LANGUAGE_CONTEXT_H
18 
19 #include "ecmascript/common.h"
20 #include "include/language_context.h"
21 
22 namespace panda {
23 class PUBLIC_API EcmaLanguageContext : public LanguageContextBase {
24 public:
25     EcmaLanguageContext() = default;
26 
27     DEFAULT_COPY_SEMANTIC(EcmaLanguageContext);
28     DEFAULT_MOVE_SEMANTIC(EcmaLanguageContext);
29 
30     ~EcmaLanguageContext() override = default;
31 
GetLanguage()32     panda_file::SourceLang GetLanguage() const override
33     {
34         return panda_file::SourceLang::ECMASCRIPT;
35     }
36 
GetCatchMethodAndOffset(Method * method,ManagedThread * thread)37     std::pair<Method *, uint32_t> GetCatchMethodAndOffset(
38         [[maybe_unused]] Method *method, [[maybe_unused]] ManagedThread *thread) const override
39     {
40         return std::make_pair(nullptr, 0);
41     }
42 
43     PandaVM *CreateVM(Runtime *runtime, const RuntimeOptions &options) const override;
44 
45     std::unique_ptr<ClassLinkerExtension> CreateClassLinkerExtension() const override;
46 
CreatePtLangExt()47     PandaUniquePtr<tooling::PtLangExt> CreatePtLangExt() const override
48     {
49         return nullptr;
50     }
51 
52     void ThrowException(ManagedThread *thread, const uint8_t *mutf8_name, const uint8_t *mutf8_msg) const override;
53 
GetInitialTaggedValue()54     coretypes::TaggedValue GetInitialTaggedValue() const override
55     {
56         UNREACHABLE();
57     }
58 
GetTypeTag(interpreter::TypeTag tag)59     uint64_t GetTypeTag([[maybe_unused]] interpreter::TypeTag tag) const override
60     {
61         UNREACHABLE();
62     }
63 
GetInitialDecodedValue()64     DecodedTaggedValue GetInitialDecodedValue() const override
65     {
66         UNREACHABLE();
67     }
68 
GetDecodedTaggedValue(const coretypes::TaggedValue & value)69     DecodedTaggedValue GetDecodedTaggedValue([[maybe_unused]] const coretypes::TaggedValue &value) const override
70     {
71         UNREACHABLE();
72     }
73 
GetEncodedTaggedValue(int64_t value,int64_t tag)74     coretypes::TaggedValue GetEncodedTaggedValue([[maybe_unused]] int64_t value,
75                                                  [[maybe_unused]] int64_t tag) const override
76     {
77         UNREACHABLE();
78     }
79 
CreateGC(mem::GCType gc_type,mem::ObjectAllocatorBase * object_allocator,const mem::GCSettings & settings)80     mem::GC *CreateGC([[maybe_unused]] mem::GCType gc_type, [[maybe_unused]] mem::ObjectAllocatorBase *object_allocator,
81                       [[maybe_unused]] const mem::GCSettings &settings) const override
82     {
83         UNREACHABLE();
84         return nullptr;
85     }
86 
IsCallableObject(ObjectHeader * obj)87     bool IsCallableObject([[maybe_unused]] ObjectHeader *obj) const override
88     {
89         UNREACHABLE();
90     }
91 
GetCallTarget(ObjectHeader * obj)92     Method *GetCallTarget([[maybe_unused]] ObjectHeader *obj) const override
93     {
94         UNREACHABLE();
95     }
96 
GetStringClassDescriptor()97     const uint8_t *GetStringClassDescriptor() const override
98     {
99         return utf::CStringAsMutf8("Lpanda/JSString;");
100     }
101 
GetObjectClassDescriptor()102     const uint8_t *GetObjectClassDescriptor() const override
103     {
104         return utf::CStringAsMutf8("Lpanda/JSObject;");
105     }
106 
GetClassClassDescriptor()107     const uint8_t *GetClassClassDescriptor() const override
108     {
109         return utf::CStringAsMutf8("Lpanda/HClass;");
110     }
111 
GetClassArrayClassDescriptor()112     const uint8_t *GetClassArrayClassDescriptor() const override
113     {
114         return utf::CStringAsMutf8("[Lpanda/JSObject;");
115     }
116 
GetStringArrayClassDescriptor()117     const uint8_t *GetStringArrayClassDescriptor() const override
118     {
119         return utf::CStringAsMutf8("[Lpanda/JSString;");
120     }
121 
GetCtorName()122     const uint8_t *GetCtorName() const override
123     {
124         return utf::CStringAsMutf8(".ctor");
125     }
126 
GetCctorName()127     const uint8_t *GetCctorName() const override
128     {
129         return utf::CStringAsMutf8(".cctor");
130     }
131 
GetNullPointerExceptionClassDescriptor()132     const uint8_t *GetNullPointerExceptionClassDescriptor() const override
133     {
134         return utf::CStringAsMutf8("Lpanda/NullPointerException;");
135     }
136 
GetArrayIndexOutOfBoundsExceptionClassDescriptor()137     const uint8_t *GetArrayIndexOutOfBoundsExceptionClassDescriptor() const override
138     {
139         return utf::CStringAsMutf8("Lpanda/ArrayIndexOutOfBoundsException;");
140     }
141 
GetIndexOutOfBoundsExceptionClassDescriptor()142     const uint8_t *GetIndexOutOfBoundsExceptionClassDescriptor() const override
143     {
144         return utf::CStringAsMutf8("Lpanda/IndexOutOfBoundsException;");
145     }
146 
GetIllegalStateExceptionClassDescriptor()147     const uint8_t *GetIllegalStateExceptionClassDescriptor() const override
148     {
149         return utf::CStringAsMutf8("Lpanda/IllegalStateException;");
150     }
151 
GetNegativeArraySizeExceptionClassDescriptor()152     const uint8_t *GetNegativeArraySizeExceptionClassDescriptor() const override
153     {
154         return utf::CStringAsMutf8("Lpanda/NegativeArraySizeException;");
155     }
156 
GetStringIndexOutOfBoundsExceptionClassDescriptor()157     const uint8_t *GetStringIndexOutOfBoundsExceptionClassDescriptor() const override
158     {
159         return utf::CStringAsMutf8("Lpanda/StringIndexOutOfBoundsException;");
160     }
161 
GetArithmeticExceptionClassDescriptor()162     const uint8_t *GetArithmeticExceptionClassDescriptor() const override
163     {
164         return utf::CStringAsMutf8("Lpanda/ArithmeticException;");
165     }
166 
GetClassCastExceptionClassDescriptor()167     const uint8_t *GetClassCastExceptionClassDescriptor() const override
168     {
169         return utf::CStringAsMutf8("Lpanda/ClassCastException;");
170     }
171 
GetAbstractMethodErrorClassDescriptor()172     const uint8_t *GetAbstractMethodErrorClassDescriptor() const override
173     {
174         return utf::CStringAsMutf8("Lpanda/AbstractMethodError;");
175     }
176 
GetArrayStoreExceptionClassDescriptor()177     const uint8_t *GetArrayStoreExceptionClassDescriptor() const override
178     {
179         return utf::CStringAsMutf8("Lpanda/ArrayStoreException;");
180     }
181 
GetRuntimeExceptionClassDescriptor()182     const uint8_t *GetRuntimeExceptionClassDescriptor() const override
183     {
184         return utf::CStringAsMutf8("Lpanda/RuntimeException;");
185     }
186 
GetFileNotFoundExceptionClassDescriptor()187     const uint8_t *GetFileNotFoundExceptionClassDescriptor() const override
188     {
189         return utf::CStringAsMutf8("Lpanda/FileNotFoundException;");
190     }
191 
GetIOExceptionClassDescriptor()192     const uint8_t *GetIOExceptionClassDescriptor() const override
193     {
194         return utf::CStringAsMutf8("Lpanda/IOException;");
195     }
196 
GetIllegalArgumentExceptionClassDescriptor()197     const uint8_t *GetIllegalArgumentExceptionClassDescriptor() const override
198     {
199         return utf::CStringAsMutf8("Lpanda/IllegalArgumentException;");
200     }
201 
GetIllegalAccessExceptionClassDescriptor()202     const uint8_t *GetIllegalAccessExceptionClassDescriptor() const override
203     {
204         return utf::CStringAsMutf8("Lpanda/IllegalAccessException;");
205     }
206 
GetOutOfMemoryErrorClassDescriptor()207     const uint8_t *GetOutOfMemoryErrorClassDescriptor() const override
208     {
209         return utf::CStringAsMutf8("Lpanda/OutOfMemoryError;");
210     }
211 
GetNoClassDefFoundErrorDescriptor()212     const uint8_t *GetNoClassDefFoundErrorDescriptor() const override
213     {
214         return utf::CStringAsMutf8("Lpanda/NoClassDefFoundError;");
215     }
216 
GetClassCircularityErrorDescriptor()217     const uint8_t *GetClassCircularityErrorDescriptor() const override
218     {
219         return utf::CStringAsMutf8("Lpanda/ClassCircularityError;");
220     }
221 
GetNoSuchFieldErrorDescriptor()222     const uint8_t *GetNoSuchFieldErrorDescriptor() const override
223     {
224         return utf::CStringAsMutf8("Lpanda/NoSuchFieldError;");
225     }
226 
GetNoSuchMethodErrorDescriptor()227     const uint8_t *GetNoSuchMethodErrorDescriptor() const override
228     {
229         return utf::CStringAsMutf8("Lpanda/NoSuchMethodError;");
230     }
231 
GetExceptionInInitializerErrorDescriptor()232     const uint8_t *GetExceptionInInitializerErrorDescriptor() const override
233     {
234         return utf::CStringAsMutf8("Lpanda/ExceptionInInitializerError;");
235     }
236 
GetClassNotFoundExceptionDescriptor()237     const uint8_t *GetClassNotFoundExceptionDescriptor() const override
238     {
239         return utf::CStringAsMutf8("Lpanda/ClassNotFoundException;");
240     }
241 
GetInstantiationErrorDescriptor()242     const uint8_t *GetInstantiationErrorDescriptor() const override
243     {
244         return utf::CStringAsMutf8("Lpanda/InstantiationError;");
245     }
246 
GetUnsupportedOperationExceptionClassDescriptor()247     const uint8_t *GetUnsupportedOperationExceptionClassDescriptor() const override
248     {
249         return utf::CStringAsMutf8("Lpanda/UnsupportedOperationException;");
250     }
251 
GetVerifyErrorClassDescriptor()252     const uint8_t *GetVerifyErrorClassDescriptor() const override
253     {
254         return utf::CStringAsMutf8("Lpanda/VerifyError;");
255     }
256 
GetIllegalMonitorStateExceptionDescriptor()257     const uint8_t *GetIllegalMonitorStateExceptionDescriptor() const override
258     {
259         return utf::CStringAsMutf8("Lpanda/IllegalMonitorStateException;");
260     }
261 
GetReferenceErrorDescriptor()262     const uint8_t *GetReferenceErrorDescriptor() const override
263     {
264         return utf::CStringAsMutf8("Lecma/ReferenceError;");
265     }
266 
GetTypedErrorDescriptor()267     const uint8_t *GetTypedErrorDescriptor() const override
268     {
269         return utf::CStringAsMutf8("Lecma/TypedError;");
270     }
271 };
272 }  // namespace panda
273 
274 #endif  // ECMASCRIPT_LANGUAGE_CONTEXT_H
275