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(ProxyGetPropertyHandlerIsNull, "JSProxy::GetProperty: handler is Null") \ 78 V(ProxyGetPropertyResultTypeError, "JSProxy::GetProperty: TypeError of trapResult") \ 79 V(ProxyGetPropertyResultNotUndefined, "JSProxy::GetProperty: trapResult is not undefined") \ 80 V(ProxySetPropertyHandlerIsNull, "JSProxy::SetProperty: handler is Null") \ 81 V(ProxySetPropertyReturnFalse, "JSProxy::SetProperty: 'set' return false") \ 82 V(ProxySetPropertyResultTypeError, "JSProxy::SetProperty: TypeError of trapResult") \ 83 V(ProxySetPropertyResultNotAccessor, "JSProxy::SetProperty: TypeError of AccessorDescriptor") \ 84 V(InOperatorOnNonObject, "Cannot use 'in' operator in Non-Object") \ 85 V(CurrentModuleUndefined, "GetModuleValueOutter currentModule failed") \ 86 V(MisstakenResolvedBinding, "Get module value failed, mistaken ResolvedBinding") \ 87 V(CurrentModuleNotSourceTextModule, "Current module is not SourceTextModule") \ 88 V(ModuleEnvMustBeDefined, "Environment of current module must not be undefined") \ 89 V(CheckIsResolvedIndexBinding, "Current resolution must be ResolvedIndexBinding") \ 90 V(RecordNameMustBeString, "RecordName must be string") \ 91 V(LexicalEnvIsInvalid, "LexicalEnv of native JSFunction is invalid, it should be GlobalEnv or Undefined") \ 92 V(CurrentEnvIsInvalid, "CurrentEnv is invalid, it should be GlobalEnv, LexicalEnv or SFunctionEnv") \ 93 V(AccessCompositeClassField, "this field of CompositeClass is unavailable") \ 94 V(HClassAddressIsInvalid, "HClass address is invalid") 95 96 #define DEBUG_CHECK_MESSAGE_STRING_LIST(V) \ 97 V(IsCallable) \ 98 V(LoadHClass) \ 99 V(IsDictionaryMode) \ 100 V(IsClassConstructor) \ 101 V(IsClassPrototype) \ 102 V(IsExtensible) \ 103 V(IsEcmaObject) \ 104 V(IsJSObject) \ 105 V(IsString) \ 106 V(IsJSHClass) \ 107 V(IsNotDictionaryMode) \ 108 V(InitializeWithSpeicalValue) \ 109 V(IsSendableFunctionModule) \ 110 V(HasPendingException) 111 112 class MessageString { 113 public: 114 enum MessageId { 115 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 116 #define DEF_MESSAGE_ID(name, string) Message_##name, 117 COMMON_MESSAGE_STRING_LIST(DEF_MESSAGE_ID) 118 #undef DEF_MESSAGE_ID 119 #define DEF_MESSAGE_ID(name) Message_##name, 120 ASM_INTERPRETER_BC_STUB_LIST(DEF_MESSAGE_ID, DEF_MESSAGE_ID, DEF_MESSAGE_ID) 121 ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_MESSAGE_ID) 122 ASM_INTERPRETER_BC_HELPER_STUB_LIST(DEF_MESSAGE_ID) 123 BASELINE_COMPILER_BUILTIN_LIST(DEF_MESSAGE_ID) 124 COMMON_STUB_LIST(DEF_MESSAGE_ID) 125 #define DEF_MESSAGE_ID_DYN(name, ...) DEF_MESSAGE_ID(name) 126 ASM_INTERPRETER_BC_PROFILER_STUB_LIST(DEF_MESSAGE_ID_DYN) 127 #undef DEF_MESSAGE_ID_DYN 128 #define DEF_BUILTINS_STUB_MESSAGE_ID(name, type, ...) Message_##type##name, 129 BUILTINS_STUB_LIST(DEF_MESSAGE_ID, DEF_BUILTINS_STUB_MESSAGE_ID, DEF_MESSAGE_ID) 130 #undef DEF_BUILTINS_STUB_MESSAGE_ID 131 RUNTIME_ASM_STUB_LIST(DEF_MESSAGE_ID) 132 DEBUG_CHECK_MESSAGE_STRING_LIST(DEF_MESSAGE_ID) 133 #undef DEF_MESSAGE_ID 134 MAX_MESSAGE_COUNT, 135 ASM_INTERPRETER_START = Message_INT32_VALUE + 1, 136 BUILTINS_STUB_START = Message_StringCharCodeAt, 137 BUILTINS_STUB_LAST = Message_ArrayConstructor, 138 }; 139 static const std::string& PUBLIC_API GetMessageString(int id); 140 IsBuiltinsStubMessageString(int id)141 static bool IsBuiltinsStubMessageString(int id) 142 { 143 return (id >= BUILTINS_STUB_START) && (id <= BUILTINS_STUB_LAST); 144 } 145 }; 146 147 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 148 #define GET_MESSAGE_STRING_ID(name) static_cast<int>((MessageString::MessageId::Message_##name)) 149 #define GET_MESSAGE_STRING(name) MessageString::GetMessageString(GET_MESSAGE_STRING_ID(name)).c_str() 150 } // namespace panda::ecmascript 151 #endif // ECMASCRIPT_MESSAGE_STRING_H 152