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 set readonly property") \ 29 V(FunctionCallNotConstructor, "class constructor cannot call") \ 30 V(SetPropertyWhenNotExtensible, "Cannot add property in prevent extensions ") \ 31 V(GetPropertyOutOfBounds, "Get Property index out-of-bounds") \ 32 V(CanNotSetPropertyOnContainer, "Cannot set property on Container") \ 33 V(NonCallable, "CallObj is NonCallable") \ 34 V(ASM_INTERPRETER_STUB_NAME, "ASM_INTERPRETER stub name: ") \ 35 V(OPCODE_OVERFLOW, "opcode overflow!") \ 36 V(INT32_VALUE, "value: %ld") \ 37 V(TargetTypeNotObject, "Type of target is not Object") \ 38 V(CanNotGetNotEcmaObject, "Can not get Prototype on non ECMA Object") \ 39 V(InstanceOfErrorTargetNotCallable, "InstanceOf error when target is not Callable") \ 40 V(ApplyTargetNotCallable, "apply target is not callable") \ 41 V(TargetNotStableJSArray, "target not stable JSArray") \ 42 V(LenGreaterThanMax, "len is bigger than 2^32 - 1") \ 43 V(ElementTypeNoElementTypes, "CreateListFromArrayLike: not an element of elementTypes") \ 44 V(TargetIsDetachedBuffer, "Is Detached Buffer") \ 45 V(ThisBranchIsUnreachable, "this branch is unreachable") 46 47 #define DEBUG_CHECK_MESSAGE_STRING_LIST(V) \ 48 V(IsCallable) \ 49 V(LoadHClass) \ 50 V(IsDictionaryMode) \ 51 V(IsClassConstructor) \ 52 V(IsClassPrototype) \ 53 V(IsExtensible) \ 54 V(IsEcmaObject) \ 55 V(IsJSObject) \ 56 V(IsString) \ 57 V(IsJSHClass) \ 58 V(IsNotDictionaryMode) 59 60 class MessageString { 61 public: 62 enum MessageId { 63 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 64 #define DEF_MESSAGE_ID(name, string) Message_##name, 65 COMMON_MESSAGE_STRING_LIST(DEF_MESSAGE_ID) 66 #undef DEF_MESSAGE_ID 67 #define DEF_MESSAGE_ID(name) Message_##name, 68 ASM_INTERPRETER_BC_STUB_LIST(DEF_MESSAGE_ID, DEF_MESSAGE_ID, DEF_MESSAGE_ID) 69 ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_MESSAGE_ID) 70 ASM_INTERPRETER_BC_HELPER_STUB_LIST(DEF_MESSAGE_ID) 71 #define DEF_MESSAGE_ID_DYN(name, ...) DEF_MESSAGE_ID(name) 72 ASM_INTERPRETER_BC_PROFILER_STUB_LIST(DEF_MESSAGE_ID_DYN) 73 #undef DEF_MESSAGE_ID_DYN 74 BUILTINS_STUB_LIST(DEF_MESSAGE_ID) 75 RUNTIME_ASM_STUB_LIST(DEF_MESSAGE_ID) 76 DEBUG_CHECK_MESSAGE_STRING_LIST(DEF_MESSAGE_ID) 77 #undef DEF_MESSAGE_ID 78 MAX_MESSAGE_COUNT, 79 ASM_INTERPRETER_START = Message_INT32_VALUE + 1, 80 BUILTINS_STUB_START = Message_CharCodeAt, 81 BUILTINS_STUB_LAST = Message_ArrayConstructor, 82 }; 83 static const std::string& GetMessageString(int id); 84 IsBuiltinsStubMessageString(int id)85 static bool IsBuiltinsStubMessageString(int id) 86 { 87 return (id >= BUILTINS_STUB_START) && (id <= BUILTINS_STUB_LAST); 88 } 89 }; 90 91 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 92 #define GET_MESSAGE_STRING_ID(name) static_cast<int>((MessageString::MessageId::Message_##name)) 93 } // namespace panda::ecmascript 94 #endif // ECMASCRIPT_MESSAGE_STRING_H 95