• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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/common_stub_csigns.h"
22 #include "ecmascript/compiler/interpreter_stub.h"
23 
24 namespace panda::ecmascript {
25 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
26 #define COMMON_MESSAGE_STRING_LIST(V)                                                        \
27     V(SetReadOnlyProperty, "Cannot assign to read only property")                            \
28     V(SetTypeMismatchedSharedProperty, "Cannot set sendable property with mismatched type")  \
29     V(CreateObjectWithSendableProto, "Cannot create object with sendable proto")             \
30     V(UpdateSendableAttributes, "Cannot update sendable object's attributes")                \
31     V(SetProtoWithSendable, "Cannot set proto with sendable object")                         \
32     V(ClassNotDerivedFromShared, "Class not derived from a sendable object")                 \
33     V(NotSendableSubClass, "The subclass of sendable class must be a sendable class")        \
34     V(FunctionCallNotConstructor, "class constructor cannot call")                           \
35     V(SetPropertyWhenNotExtensible, "Cannot add property in prevent extensions")             \
36     V(GetPropertyOutOfBounds, "Get Property index out-of-bounds")                            \
37     V(CanNotSetPropertyOnContainer, "Cannot set property on Container")                      \
38     V(NonCallable, "CallObj is NonCallable")                                                 \
39     V(ASM_INTERPRETER_STUB_NAME, "ASM_INTERPRETER stub name: ")                              \
40     V(OPCODE_OVERFLOW, "opcode overflow!")                                                   \
41     V(INT32_VALUE, "value: %ld")                                                             \
42     V(TargetTypeNotObject, "Type of target is not Object")                                   \
43     V(TargetTypeNotTypedArray, "The O is not a TypedArray.")                                 \
44     V(CanNotGetNotEcmaObject, "Can not get Prototype on non ECMA Object")                    \
45     V(SendableArrayForJson, "Array not supported for SENDABLE_JSON")                         \
46     V(InstanceOfErrorTargetNotCallable, "InstanceOf error when target is not Callable")      \
47     V(ApplyTargetNotCallable, "apply target is not callable")                                \
48     V(TargetNotStableJSArray, "target not stable JSArray")                                   \
49     V(LenGreaterThanMax, "len is bigger than 2^32 - 1")                                      \
50     V(ElementTypeNoElementTypes, "CreateListFromArrayLike: not an element of elementTypes")  \
51     V(TargetIsDetachedBuffer, "Is Detached Buffer")                                          \
52     V(ThisBranchIsUnreachable, "this branch is unreachable")                                 \
53     V(CanNotConvertNotUndefinedObject, "Cannot convert a UNDEFINED value to a JSObject")     \
54     V(CanNotConvertNotNullObject, "Cannot convert a NULL value to a JSObject")               \
55     V(CanNotConvertNotHoleObject, "Cannot convert a HOLE value to a JSObject")               \
56     V(CanNotConvertUnknowObject, "Cannot convert a Unknown object value to a JSObject")      \
57     V(CanNotConvertNotValidObject, "Obj is not a valid object")                              \
58     V(CanNotConvertContainerObject, "Can not delete property in Container Object")           \
59     V(InvalidStringLength, "Invalid string length")                                          \
60     V(InvalidNewTarget, "new.target is not an object")                                       \
61     V(ObjIsNotCallable, "obj is not Callable")                                               \
62     V(SharedObjectRefersLocalObject, "shared object refers a local object")                  \
63     V(InvalidRadixLength, "radix must be 2 to 36")                                           \
64     V(SetPrototypeOfFailed, "SetPrototypeOf: prototype set failed")                          \
65     V(ReviverOnlySupportUndefined, "reviver only supports undefined for SENDABLE_JSON")      \
66     V(DefineFieldField, "DefineField: obj is not Object")                                    \
67     V(IsNotPropertyKey, "key is not a property key")                                         \
68     V(CreateDataPropertyFailed, "failed to create data property")                            \
69     V(ValueIsNonSObject, "value is not a shared object")                                     \
70     V(MapIteratorTypeError, "this value is not a map iterator")                              \
71     V(SetIteratorTypeError, "this value is not a set iterator")                              \
72     V(LengthError, "length must be positive integer")                                        \
73     V(IterNotObject, "JSIterator::GetIterator: iter is not object")                          \
74     V(CanNotConvertObjectToPrimitiveValue, "Cannot convert object to primitive value")       \
75     V(CanNotConvertIllageValueToString, "Cannot convert a illegal value to a String")        \
76     V(CanNotConvertIllageValueToPrimitive, "Cannot convert a illegal value to a Primitive")  \
77     V(InOperatorOnNonObject, "Cannot use 'in' operator in Non-Object")
78 
79 #define DEBUG_CHECK_MESSAGE_STRING_LIST(V)                                                   \
80     V(IsCallable)                                                                            \
81     V(LoadHClass)                                                                            \
82     V(IsDictionaryMode)                                                                      \
83     V(IsClassConstructor)                                                                    \
84     V(IsClassPrototype)                                                                      \
85     V(IsExtensible)                                                                          \
86     V(IsEcmaObject)                                                                          \
87     V(IsJSObject)                                                                            \
88     V(IsString)                                                                              \
89     V(IsJSHClass)                                                                            \
90     V(IsNotDictionaryMode)                                                                   \
91     V(InitializeWithSpeicalValue)                                                            \
92     V(IsSendableFunctionModule)
93 
94 class MessageString {
95 public:
96     enum MessageId {
97     // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
98 #define DEF_MESSAGE_ID(name, string) Message_##name,
99         COMMON_MESSAGE_STRING_LIST(DEF_MESSAGE_ID)
100 #undef DEF_MESSAGE_ID
101 #define DEF_MESSAGE_ID(name) Message_##name,
102         ASM_INTERPRETER_BC_STUB_LIST(DEF_MESSAGE_ID, DEF_MESSAGE_ID, DEF_MESSAGE_ID)
103         ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_MESSAGE_ID)
104         ASM_INTERPRETER_BC_HELPER_STUB_LIST(DEF_MESSAGE_ID)
105 #define DEF_MESSAGE_ID_DYN(name, ...) DEF_MESSAGE_ID(name)
106         ASM_INTERPRETER_BC_PROFILER_STUB_LIST(DEF_MESSAGE_ID_DYN)
107 #undef DEF_MESSAGE_ID_DYN
108 #define DEF_BUILTINS_STUB_MESSAGE_ID(name, type, ...) Message_##type##name,
109         BUILTINS_STUB_LIST(DEF_MESSAGE_ID, DEF_BUILTINS_STUB_MESSAGE_ID, DEF_MESSAGE_ID)
110 #undef DEF_BUILTINS_STUB_MESSAGE_ID
111         RUNTIME_ASM_STUB_LIST(DEF_MESSAGE_ID)
112         DEBUG_CHECK_MESSAGE_STRING_LIST(DEF_MESSAGE_ID)
113 #undef DEF_MESSAGE_ID
114         MAX_MESSAGE_COUNT,
115         ASM_INTERPRETER_START = Message_INT32_VALUE + 1,
116         BUILTINS_STUB_START = Message_StringCharCodeAt,
117         BUILTINS_STUB_LAST = Message_ArrayConstructor,
118     };
119     static const std::string& PUBLIC_API GetMessageString(int id);
120 
IsBuiltinsStubMessageString(int id)121     static bool IsBuiltinsStubMessageString(int id)
122     {
123         return (id >= BUILTINS_STUB_START) && (id <= BUILTINS_STUB_LAST);
124     }
125 };
126 
127 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
128 #define GET_MESSAGE_STRING_ID(name) static_cast<int>((MessageString::MessageId::Message_##name))
129 #define GET_MESSAGE_STRING(name)  MessageString::GetMessageString(GET_MESSAGE_STRING_ID(name)).c_str()
130 }  // namespace panda::ecmascript
131 #endif  // ECMASCRIPT_MESSAGE_STRING_H
132