• 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_MESSAGE_STRING_H
17 #define ECMASCRIPT_MESSAGE_STRING_H
18 
19 #include <string>
20 
21 #include "ecmascript/compiler/builtins/builtins_stubs.h"
22 #include "ecmascript/compiler/common_stubs.h"
23 #include "ecmascript/compiler/interpreter_stub.h"
24 
25 namespace panda::ecmascript {
26 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
27 #define COMMON_MESSAGE_STRING_LIST(V)                                                        \
28     V(SetReadOnlyProperty, "Cannot assign to read only property")                            \
29     V(SetTypeMismatchedSharedProperty, "Cannot set sendable property with mismatched type")  \
30     V(CreateObjectWithSendableProto, "Cannot create object with sendable proto")             \
31     V(UpdateSendableAttributes, "Cannot update sendable object's attributes")                \
32     V(SetProtoWithSendable, "Cannot set proto with sendable object")                         \
33     V(ClassNotDerivedFromShared, "Class not derived from a sendable object")                 \
34     V(NotSendableSubClass, "The subclass of sendable class must be a sendable class")        \
35     V(FunctionCallNotConstructor, "class constructor cannot call")                           \
36     V(SetPropertyWhenNotExtensible, "Cannot add property in prevent extensions")             \
37     V(GetPropertyOutOfBounds, "Get Property index out-of-bounds")                            \
38     V(CanNotSetPropertyOnContainer, "Cannot set property on Container")                      \
39     V(NonCallable, "CallObj is NonCallable")                                                 \
40     V(ASM_INTERPRETER_STUB_NAME, "ASM_INTERPRETER stub name: ")                              \
41     V(OPCODE_OVERFLOW, "opcode overflow!")                                                   \
42     V(INT32_VALUE, "value: %ld")                                                             \
43     V(TargetTypeNotObject, "Type of target is not Object")                                   \
44     V(CanNotGetNotEcmaObject, "Can not get Prototype on non ECMA Object")                    \
45     V(InstanceOfErrorTargetNotCallable, "InstanceOf error when target is not Callable")      \
46     V(ApplyTargetNotCallable, "apply target is not callable")                                \
47     V(TargetNotStableJSArray, "target not stable JSArray")                                   \
48     V(LenGreaterThanMax, "len is bigger than 2^32 - 1")                                      \
49     V(ElementTypeNoElementTypes, "CreateListFromArrayLike: not an element of elementTypes")  \
50     V(TargetIsDetachedBuffer, "Is Detached Buffer")                                          \
51     V(ThisBranchIsUnreachable, "this branch is unreachable")                                 \
52     V(CanNotConvertNotUndefinedObject, "Cannot convert a UNDEFINED value to a JSObject")     \
53     V(CanNotConvertNotNullObject, "Cannot convert a NULL value to a JSObject")               \
54     V(CanNotConvertNotHoleObject, "Cannot convert a HOLE value to a JSObject")               \
55     V(CanNotConvertUnknowObject, "Cannot convert a Unknown object value to a JSObject")      \
56     V(CanNotConvertNotValidObject, "Obj is not a valid object")                              \
57     V(CanNotConvertContainerObject, "Can not delete property in Container Object")           \
58     V(InvalidStringLength, "Invalid string length")
59 
60 #define DEBUG_CHECK_MESSAGE_STRING_LIST(V)                                                   \
61     V(IsCallable)                                                                            \
62     V(LoadHClass)                                                                            \
63     V(IsDictionaryMode)                                                                      \
64     V(IsClassConstructor)                                                                    \
65     V(IsClassPrototype)                                                                      \
66     V(IsExtensible)                                                                          \
67     V(IsEcmaObject)                                                                          \
68     V(IsJSObject)                                                                            \
69     V(IsString)                                                                              \
70     V(IsJSHClass)                                                                            \
71     V(IsNotDictionaryMode)
72 
73 class MessageString {
74 public:
75     enum MessageId {
76     // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
77 #define DEF_MESSAGE_ID(name, string) Message_##name,
78         COMMON_MESSAGE_STRING_LIST(DEF_MESSAGE_ID)
79 #undef DEF_MESSAGE_ID
80 #define DEF_MESSAGE_ID(name) Message_##name,
81         ASM_INTERPRETER_BC_STUB_LIST(DEF_MESSAGE_ID, DEF_MESSAGE_ID, DEF_MESSAGE_ID)
82         ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_MESSAGE_ID)
83         ASM_INTERPRETER_BC_HELPER_STUB_LIST(DEF_MESSAGE_ID)
84 #define DEF_MESSAGE_ID_DYN(name, ...) DEF_MESSAGE_ID(name)
85         ASM_INTERPRETER_BC_PROFILER_STUB_LIST(DEF_MESSAGE_ID_DYN)
86 #undef DEF_MESSAGE_ID_DYN
87         BUILTINS_STUB_LIST(DEF_MESSAGE_ID)
88         RUNTIME_ASM_STUB_LIST(DEF_MESSAGE_ID)
89         DEBUG_CHECK_MESSAGE_STRING_LIST(DEF_MESSAGE_ID)
90 #undef DEF_MESSAGE_ID
91         MAX_MESSAGE_COUNT,
92         ASM_INTERPRETER_START = Message_INT32_VALUE + 1,
93         BUILTINS_STUB_START = Message_StringCharCodeAt,
94         BUILTINS_STUB_LAST = Message_ArrayConstructor,
95     };
96     static const std::string& GetMessageString(int id);
97 
IsBuiltinsStubMessageString(int id)98     static bool IsBuiltinsStubMessageString(int id)
99     {
100         return (id >= BUILTINS_STUB_START) && (id <= BUILTINS_STUB_LAST);
101     }
102 };
103 
104 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
105 #define GET_MESSAGE_STRING_ID(name) static_cast<int>((MessageString::MessageId::Message_##name))
106 #define GET_MESSAGE_STRING(name)  MessageString::GetMessageString(GET_MESSAGE_STRING_ID(name)).c_str()
107 }  // namespace panda::ecmascript
108 #endif  // ECMASCRIPT_MESSAGE_STRING_H
109