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(IterNotObject, "JSIterator::GetIterator: iter is not object") 71 72 #define DEBUG_CHECK_MESSAGE_STRING_LIST(V) \ 73 V(IsCallable) \ 74 V(LoadHClass) \ 75 V(IsDictionaryMode) \ 76 V(IsClassConstructor) \ 77 V(IsClassPrototype) \ 78 V(IsExtensible) \ 79 V(IsEcmaObject) \ 80 V(IsJSObject) \ 81 V(IsString) \ 82 V(IsJSHClass) \ 83 V(IsNotDictionaryMode) \ 84 V(InitializeWithSpeicalValue) \ 85 V(IsSendableFunctionModule) 86 87 class MessageString { 88 public: 89 enum MessageId { 90 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 91 #define DEF_MESSAGE_ID(name, string) Message_##name, 92 COMMON_MESSAGE_STRING_LIST(DEF_MESSAGE_ID) 93 #undef DEF_MESSAGE_ID 94 #define DEF_MESSAGE_ID(name) Message_##name, 95 ASM_INTERPRETER_BC_STUB_LIST(DEF_MESSAGE_ID, DEF_MESSAGE_ID, DEF_MESSAGE_ID) 96 ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_MESSAGE_ID) 97 ASM_INTERPRETER_BC_HELPER_STUB_LIST(DEF_MESSAGE_ID) 98 #define DEF_MESSAGE_ID_DYN(name, ...) DEF_MESSAGE_ID(name) 99 ASM_INTERPRETER_BC_PROFILER_STUB_LIST(DEF_MESSAGE_ID_DYN) 100 #undef DEF_MESSAGE_ID_DYN 101 #define DEF_BUILTINS_STUB_MESSAGE_ID(name, type, ...) Message_##type##name, 102 BUILTINS_STUB_LIST(DEF_MESSAGE_ID, DEF_BUILTINS_STUB_MESSAGE_ID, DEF_MESSAGE_ID) 103 #undef DEF_BUILTINS_STUB_MESSAGE_ID 104 RUNTIME_ASM_STUB_LIST(DEF_MESSAGE_ID) 105 DEBUG_CHECK_MESSAGE_STRING_LIST(DEF_MESSAGE_ID) 106 #undef DEF_MESSAGE_ID 107 MAX_MESSAGE_COUNT, 108 ASM_INTERPRETER_START = Message_INT32_VALUE + 1, 109 BUILTINS_STUB_START = Message_StringCharCodeAt, 110 BUILTINS_STUB_LAST = Message_ArrayConstructor, 111 }; 112 static const std::string& PUBLIC_API GetMessageString(int id); 113 IsBuiltinsStubMessageString(int id)114 static bool IsBuiltinsStubMessageString(int id) 115 { 116 return (id >= BUILTINS_STUB_START) && (id <= BUILTINS_STUB_LAST); 117 } 118 }; 119 120 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 121 #define GET_MESSAGE_STRING_ID(name) static_cast<int>((MessageString::MessageId::Message_##name)) 122 #define GET_MESSAGE_STRING(name) MessageString::GetMessageString(GET_MESSAGE_STRING_ID(name)).c_str() 123 } // namespace panda::ecmascript 124 #endif // ECMASCRIPT_MESSAGE_STRING_H 125