Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | // The infrastructure used for (localized) message reporting in V8. |
| 6 | // |
| 7 | // Note: there's a big unresolved issue about ownership of the data |
| 8 | // structures used by this framework. |
| 9 | |
| 10 | #ifndef V8_MESSAGES_H_ |
| 11 | #define V8_MESSAGES_H_ |
| 12 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | #include "src/base/smart-pointers.h" |
| 14 | #include "src/handles.h" |
| 15 | #include "src/list.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 16 | |
| 17 | namespace v8 { |
| 18 | namespace internal { |
| 19 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 20 | // Forward declarations. |
| 21 | class JSMessageObject; |
| 22 | class LookupIterator; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 23 | class SourceInfo; |
| 24 | |
| 25 | class MessageLocation { |
| 26 | public: |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 27 | MessageLocation(Handle<Script> script, int start_pos, int end_pos); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | MessageLocation(Handle<Script> script, int start_pos, int end_pos, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 29 | Handle<JSFunction> function); |
| 30 | MessageLocation(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 31 | |
| 32 | Handle<Script> script() const { return script_; } |
| 33 | int start_pos() const { return start_pos_; } |
| 34 | int end_pos() const { return end_pos_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 35 | Handle<JSFunction> function() const { return function_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 36 | |
| 37 | private: |
| 38 | Handle<Script> script_; |
| 39 | int start_pos_; |
| 40 | int end_pos_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 41 | Handle<JSFunction> function_; |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | class CallSite { |
| 46 | public: |
| 47 | CallSite(Isolate* isolate, Handle<JSObject> call_site_obj); |
| 48 | |
| 49 | Handle<Object> GetFileName(); |
| 50 | Handle<Object> GetFunctionName(); |
| 51 | Handle<Object> GetScriptNameOrSourceUrl(); |
| 52 | Handle<Object> GetMethodName(); |
| 53 | // Return 1-based line number, including line offset. |
| 54 | int GetLineNumber(); |
| 55 | // Return 1-based column number, including column offset if first line. |
| 56 | int GetColumnNumber(); |
| 57 | bool IsNative(); |
| 58 | bool IsToplevel(); |
| 59 | bool IsEval(); |
| 60 | bool IsConstructor(); |
| 61 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 62 | bool IsJavaScript() { return !fun_.is_null(); } |
| 63 | bool IsWasm() { return !wasm_obj_.is_null(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 64 | |
| 65 | private: |
| 66 | Isolate* isolate_; |
| 67 | Handle<Object> receiver_; |
| 68 | Handle<JSFunction> fun_; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 69 | int32_t pos_ = -1; |
| 70 | Handle<JSObject> wasm_obj_; |
| 71 | uint32_t wasm_func_index_ = static_cast<uint32_t>(-1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 74 | #define MESSAGE_TEMPLATES(T) \ |
| 75 | /* Error */ \ |
| 76 | T(None, "") \ |
| 77 | T(CyclicProto, "Cyclic __proto__ value") \ |
| 78 | T(Debugger, "Debugger: %") \ |
| 79 | T(DebuggerLoading, "Error loading debugger") \ |
| 80 | T(DefaultOptionsMissing, "Internal % error. Default options are missing.") \ |
| 81 | T(UncaughtException, "Uncaught %") \ |
| 82 | T(Unsupported, "Not supported") \ |
| 83 | T(WrongServiceType, "Internal error, wrong service type: %") \ |
| 84 | T(WrongValueType, "Internal error. Wrong value type.") \ |
| 85 | /* TypeError */ \ |
| 86 | T(ApplyNonFunction, \ |
| 87 | "Function.prototype.apply was called on %, which is a % and not a " \ |
| 88 | "function") \ |
| 89 | T(ArrayBufferTooShort, \ |
| 90 | "Derived ArrayBuffer constructor created a buffer which was too small") \ |
| 91 | T(ArrayBufferSpeciesThis, \ |
| 92 | "ArrayBuffer subclass returned this from species constructor") \ |
| 93 | T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements") \ |
| 94 | T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements") \ |
| 95 | T(ArrayNotSubclassable, "Subclassing Arrays is not currently supported.") \ |
| 96 | T(CalledNonCallable, "% is not a function") \ |
| 97 | T(CalledOnNonObject, "% called on non-object") \ |
| 98 | T(CalledOnNullOrUndefined, "% called on null or undefined") \ |
| 99 | T(CallSiteExpectsFunction, \ |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 100 | "CallSite expects wasm object as first or function as second argument, " \ |
| 101 | "got <%, %>") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 102 | T(CallSiteMethod, "CallSite method % expects CallSite as receiver") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 103 | T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \ |
| 104 | T(CannotPreventExt, "Cannot prevent extensions") \ |
| 105 | T(CannotFreezeArrayBufferView, \ |
| 106 | "Cannot freeze array buffer views with elements") \ |
| 107 | T(CircularStructure, "Converting circular structure to JSON") \ |
| 108 | T(ConstructAbstractClass, "Abstract class % not directly constructable") \ |
| 109 | T(ConstAssign, "Assignment to constant variable.") \ |
| 110 | T(ConstructorNonCallable, \ |
| 111 | "Class constructor % cannot be invoked without 'new'") \ |
| 112 | T(ConstructorNotFunction, "Constructor % requires 'new'") \ |
| 113 | T(ConstructorNotReceiver, "The .constructor property is not an object") \ |
| 114 | T(CurrencyCode, "Currency code is required with currency style.") \ |
| 115 | T(DataViewNotArrayBuffer, \ |
| 116 | "First argument to DataView constructor must be an ArrayBuffer") \ |
| 117 | T(DateType, "this is not a Date object.") \ |
| 118 | T(DebuggerFrame, "Debugger: Invalid frame index.") \ |
| 119 | T(DebuggerType, "Debugger: Parameters have wrong types.") \ |
| 120 | T(DeclarationMissingInitializer, "Missing initializer in % declaration") \ |
| 121 | T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 122 | T(DetachedOperation, "Cannot perform % on a detached ArrayBuffer") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 123 | T(DuplicateTemplateProperty, "Object template has duplicate property '%'") \ |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 124 | T(ExtendsValueNotConstructor, \ |
| 125 | "Class extends value % is not a constructor or null") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 126 | T(FirstArgumentNotRegExp, \ |
| 127 | "First argument to % must not be a regular expression") \ |
| 128 | T(FunctionBind, "Bind must be called on a function") \ |
| 129 | T(GeneratorRunning, "Generator is already running") \ |
| 130 | T(IllegalInvocation, "Illegal invocation") \ |
| 131 | T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 132 | T(InstanceofNonobjectProto, \ |
| 133 | "Function has non-object prototype '%' in instanceof check") \ |
| 134 | T(InvalidArgument, "invalid_argument") \ |
| 135 | T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 136 | T(InvalidRegExpExecResult, \ |
| 137 | "RegExp exec method returned something other than an Object or null") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 138 | T(InvalidSimdOperation, "% is not a valid type for this SIMD operation.") \ |
| 139 | T(IteratorResultNotAnObject, "Iterator result % is not an object") \ |
| 140 | T(IteratorValueNotAnObject, "Iterator value % is not an entry object") \ |
| 141 | T(LanguageID, "Language ID should be string or object.") \ |
| 142 | T(MethodCalledOnWrongObject, \ |
| 143 | "Method % called on a non-object or on a wrong type of object.") \ |
| 144 | T(MethodInvokedOnNullOrUndefined, \ |
| 145 | "Method invoked on undefined or null value.") \ |
| 146 | T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \ |
| 147 | T(NoAccess, "no access") \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 148 | T(NonCallableInInstanceOfCheck, \ |
| 149 | "Right-hand side of 'instanceof' is not callable") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 150 | T(NonCoercible, "Cannot match against 'undefined' or 'null'.") \ |
| 151 | T(NonExtensibleProto, "% is not extensible") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 152 | T(NonObjectInInstanceOfCheck, \ |
| 153 | "Right-hand side of 'instanceof' is not an object") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 154 | T(NonObjectPropertyLoad, "Cannot read property '%' of %") \ |
| 155 | T(NonObjectPropertyStore, "Cannot set property '%' of %") \ |
| 156 | T(NoSetterInCallback, "Cannot set property % of % which has only a getter") \ |
| 157 | T(NotAnIterator, "% is not an iterator") \ |
| 158 | T(NotAPromise, "% is not a promise") \ |
| 159 | T(NotConstructor, "% is not a constructor") \ |
| 160 | T(NotDateObject, "this is not a Date object.") \ |
| 161 | T(NotIntlObject, "% is not an i18n object.") \ |
| 162 | T(NotGeneric, "% is not generic") \ |
| 163 | T(NotIterable, "% is not iterable") \ |
| 164 | T(NotPropertyName, "% is not a valid property name") \ |
| 165 | T(NotTypedArray, "this is not a typed array.") \ |
| 166 | T(NotSharedTypedArray, "% is not a shared typed array.") \ |
| 167 | T(NotIntegerSharedTypedArray, "% is not an integer shared typed array.") \ |
| 168 | T(NotInt32SharedTypedArray, "% is not an int32 shared typed array.") \ |
| 169 | T(ObjectGetterExpectingFunction, \ |
| 170 | "Object.prototype.__defineGetter__: Expecting function") \ |
| 171 | T(ObjectGetterCallable, "Getter must be a function: %") \ |
| 172 | T(ObjectNotExtensible, "Can't add property %, object is not extensible") \ |
| 173 | T(ObjectSetterExpectingFunction, \ |
| 174 | "Object.prototype.__defineSetter__: Expecting function") \ |
| 175 | T(ObjectSetterCallable, "Setter must be a function: %") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 176 | T(OrdinaryFunctionCalledAsConstructor, \ |
| 177 | "Function object that's not a constructor was created with new") \ |
| 178 | T(PromiseCyclic, "Chaining cycle detected for promise %") \ |
| 179 | T(PromiseExecutorAlreadyInvoked, \ |
| 180 | "Promise executor has already been invoked with non-undefined arguments") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 181 | T(PromiseNonCallable, "Promise resolve or reject function is not callable") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 182 | T(PropertyDescObject, "Property description must be an object: %") \ |
| 183 | T(PropertyNotFunction, \ |
| 184 | "'%' returned for property '%' of object '%' is not a function") \ |
| 185 | T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %") \ |
| 186 | T(PrototypeParentNotAnObject, \ |
| 187 | "Class extends value does not have valid prototype property %") \ |
| 188 | T(ProxyConstructNonObject, \ |
| 189 | "'construct' on proxy: trap returned non-object ('%')") \ |
| 190 | T(ProxyDefinePropertyNonConfigurable, \ |
| 191 | "'defineProperty' on proxy: trap returned truish for defining " \ |
| 192 | "non-configurable property '%' which is either non-existant or " \ |
| 193 | "configurable in the proxy target") \ |
| 194 | T(ProxyDefinePropertyNonExtensible, \ |
| 195 | "'defineProperty' on proxy: trap returned truish for adding property '%' " \ |
| 196 | " to the non-extensible proxy target") \ |
| 197 | T(ProxyDefinePropertyIncompatible, \ |
| 198 | "'defineProperty' on proxy: trap returned truish for adding property '%' " \ |
| 199 | " that is incompatible with the existing property in the proxy target") \ |
| 200 | T(ProxyDeletePropertyNonConfigurable, \ |
| 201 | "'deleteProperty' on proxy: trap returned truish for property '%' which " \ |
| 202 | "is non-configurable in the proxy target") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 203 | T(ProxyGetNonConfigurableData, \ |
| 204 | "'get' on proxy: property '%' is a read-only and " \ |
| 205 | "non-configurable data property on the proxy target but the proxy " \ |
| 206 | "did not return its actual value (expected '%' but got '%')") \ |
| 207 | T(ProxyGetNonConfigurableAccessor, \ |
| 208 | "'get' on proxy: property '%' is a non-configurable accessor " \ |
| 209 | "property on the proxy target and does not have a getter function, but " \ |
| 210 | "the trap did not return 'undefined' (got '%')") \ |
| 211 | T(ProxyGetOwnPropertyDescriptorIncompatible, \ |
| 212 | "'getOwnPropertyDescriptor' on proxy: trap returned descriptor for " \ |
| 213 | "property '%' that is incompatible with the existing property in the " \ |
| 214 | "proxy target") \ |
| 215 | T(ProxyGetOwnPropertyDescriptorInvalid, \ |
| 216 | "'getOwnPropertyDescriptor' on proxy: trap returned neither object nor " \ |
| 217 | "undefined for property '%'") \ |
| 218 | T(ProxyGetOwnPropertyDescriptorNonConfigurable, \ |
| 219 | "'getOwnPropertyDescriptor' on proxy: trap reported non-configurability " \ |
| 220 | "for property '%' which is either non-existant or configurable in the " \ |
| 221 | "proxy target") \ |
| 222 | T(ProxyGetOwnPropertyDescriptorNonExtensible, \ |
| 223 | "'getOwnPropertyDescriptor' on proxy: trap returned undefined for " \ |
| 224 | "property '%' which exists in the non-extensible proxy target") \ |
| 225 | T(ProxyGetOwnPropertyDescriptorUndefined, \ |
| 226 | "'getOwnPropertyDescriptor' on proxy: trap returned undefined for " \ |
| 227 | "property '%' which is non-configurable in the proxy target") \ |
| 228 | T(ProxyGetPrototypeOfInvalid, \ |
| 229 | "'getPrototypeOf' on proxy: trap returned neither object nor null") \ |
| 230 | T(ProxyGetPrototypeOfNonExtensible, \ |
| 231 | "'getPrototypeOf' on proxy: proxy target is non-extensible but the " \ |
| 232 | "trap did not return its actual prototype") \ |
| 233 | T(ProxyHandlerOrTargetRevoked, \ |
| 234 | "Cannot create proxy with a revoked proxy as target or handler") \ |
| 235 | T(ProxyHasNonConfigurable, \ |
| 236 | "'has' on proxy: trap returned falsish for property '%' which exists in " \ |
| 237 | "the proxy target as non-configurable") \ |
| 238 | T(ProxyHasNonExtensible, \ |
| 239 | "'has' on proxy: trap returned falsish for property '%' but the proxy " \ |
| 240 | "target is not extensible") \ |
| 241 | T(ProxyIsExtensibleInconsistent, \ |
| 242 | "'isExtensible' on proxy: trap result does not reflect extensibility of " \ |
| 243 | "proxy target (which is '%')") \ |
| 244 | T(ProxyNonObject, \ |
| 245 | "Cannot create proxy with a non-object as target or handler") \ |
| 246 | T(ProxyOwnKeysMissing, \ |
| 247 | "'ownKeys' on proxy: trap result did not include '%'") \ |
| 248 | T(ProxyOwnKeysNonExtensible, \ |
| 249 | "'ownKeys' on proxy: trap returned extra keys but proxy target is " \ |
| 250 | "non-extensible") \ |
| 251 | T(ProxyPreventExtensionsExtensible, \ |
| 252 | "'preventExtensions' on proxy: trap returned truish but the proxy target " \ |
| 253 | "is extensible") \ |
| 254 | T(ProxyPrivate, "Cannot pass private property name to proxy trap") \ |
| 255 | T(ProxyRevoked, "Cannot perform '%' on a proxy that has been revoked") \ |
| 256 | T(ProxySetFrozenData, \ |
| 257 | "'set' on proxy: trap returned truish for property '%' which exists in " \ |
| 258 | "the proxy target as a non-configurable and non-writable data property " \ |
| 259 | "with a different value") \ |
| 260 | T(ProxySetFrozenAccessor, \ |
| 261 | "'set' on proxy: trap returned truish for property '%' which exists in " \ |
| 262 | "the proxy target as a non-configurable and non-writable accessor " \ |
| 263 | "property without a setter") \ |
| 264 | T(ProxySetPrototypeOfNonExtensible, \ |
| 265 | "'setPrototypeOf' on proxy: trap returned truish for setting a new " \ |
| 266 | "prototype on the non-extensible proxy target") \ |
| 267 | T(ProxyTrapReturnedFalsish, "'%' on proxy: trap returned falsish") \ |
| 268 | T(ProxyTrapReturnedFalsishFor, \ |
| 269 | "'%' on proxy: trap returned falsish for property '%'") \ |
| 270 | T(ReadGlobalReferenceThroughProxy, "Trying to access '%' through proxy") \ |
| 271 | T(RedefineDisallowed, "Cannot redefine property: %") \ |
| 272 | T(RedefineExternalArray, \ |
| 273 | "Cannot redefine a property of an object with external array elements") \ |
| 274 | T(ReduceNoInitial, "Reduce of empty array with no initial value") \ |
| 275 | T(RegExpFlags, \ |
| 276 | "Cannot supply flags when constructing one RegExp from another") \ |
| 277 | T(RegExpNonObject, "% getter called on non-object %") \ |
| 278 | T(RegExpNonRegExp, "% getter called on non-RegExp object") \ |
| 279 | T(ReinitializeIntl, "Trying to re-initialize % object.") \ |
| 280 | T(ResolvedOptionsCalledOnNonObject, \ |
| 281 | "resolvedOptions method called on a non-object or on a object that is " \ |
| 282 | "not Intl.%.") \ |
| 283 | T(ResolverNotAFunction, "Promise resolver % is not a function") \ |
| 284 | T(RestrictedFunctionProperties, \ |
| 285 | "'caller' and 'arguments' are restricted function properties and cannot " \ |
| 286 | "be accessed in this context.") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 287 | T(ReturnMethodNotCallable, "The iterator's 'return' method is not callable") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 288 | T(StaticPrototype, "Classes may not have static property named prototype") \ |
| 289 | T(StrictCannotAssign, "Cannot assign to read only '%' in strict mode") \ |
| 290 | T(StrictDeleteProperty, "Cannot delete property '%' of %") \ |
| 291 | T(StrictPoisonPill, \ |
| 292 | "'caller', 'callee', and 'arguments' properties may not be accessed on " \ |
| 293 | "strict mode functions or the arguments objects for calls to them") \ |
| 294 | T(StrictReadOnlyProperty, \ |
| 295 | "Cannot assign to read only property '%' of % '%'") \ |
| 296 | T(StrictCannotCreateProperty, "Cannot create property '%' on % '%'") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 297 | T(SymbolIteratorInvalid, \ |
| 298 | "Result of the Symbol.iterator method is not an object") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 299 | T(SymbolKeyFor, "% is not a symbol") \ |
| 300 | T(SymbolToNumber, "Cannot convert a Symbol value to a number") \ |
| 301 | T(SymbolToString, "Cannot convert a Symbol value to a string") \ |
| 302 | T(SimdToNumber, "Cannot convert a SIMD value to a number") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 303 | T(ThrowMethodMissing, "The iterator does not provide a 'throw' method.") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 304 | T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \ |
| 305 | T(ValueAndAccessor, \ |
| 306 | "Invalid property descriptor. Cannot both specify accessors and a value " \ |
| 307 | "or writable attribute, %") \ |
| 308 | T(VarRedeclaration, "Identifier '%' has already been declared") \ |
| 309 | T(WrongArgs, "%: Arguments list has wrong type") \ |
| 310 | /* ReferenceError */ \ |
| 311 | T(NonMethod, "'super' is referenced from non-method") \ |
| 312 | T(NotDefined, "% is not defined") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 313 | T(UnsupportedSuper, "Unsupported reference to 'super'") \ |
| 314 | /* RangeError */ \ |
| 315 | T(DateRange, "Provided date is not in valid range.") \ |
| 316 | T(ExpectedTimezoneID, \ |
| 317 | "Expected Area/Location(/Location)* for time zone, got %") \ |
| 318 | T(ExpectedLocation, \ |
| 319 | "Expected letters optionally connected with underscores or hyphens for " \ |
| 320 | "a location, got %") \ |
| 321 | T(InvalidArrayBufferLength, "Invalid array buffer length") \ |
| 322 | T(ArrayBufferAllocationFailed, "Array buffer allocation failed") \ |
| 323 | T(InvalidArrayLength, "Invalid array length") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 324 | T(InvalidAtomicAccessIndex, "Invalid atomic access index") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 325 | T(InvalidCodePoint, "Invalid code point %") \ |
| 326 | T(InvalidCountValue, "Invalid count value") \ |
| 327 | T(InvalidCurrencyCode, "Invalid currency code: %") \ |
| 328 | T(InvalidDataViewAccessorOffset, \ |
| 329 | "Offset is outside the bounds of the DataView") \ |
| 330 | T(InvalidDataViewLength, "Invalid data view length") \ |
| 331 | T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \ |
| 332 | T(InvalidHint, "Invalid hint: %") \ |
| 333 | T(InvalidLanguageTag, "Invalid language tag: %") \ |
| 334 | T(InvalidWeakMapKey, "Invalid value used as weak map key") \ |
| 335 | T(InvalidWeakSetValue, "Invalid value used in weak set") \ |
| 336 | T(InvalidStringLength, "Invalid string length") \ |
| 337 | T(InvalidTimeValue, "Invalid time value") \ |
| 338 | T(InvalidTypedArrayAlignment, "% of % should be a multiple of %") \ |
| 339 | T(InvalidTypedArrayLength, "Invalid typed array length") \ |
| 340 | T(InvalidTypedArrayOffset, "Start offset is too large:") \ |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 341 | T(InvalidSimdIndex, "Index out of bounds for SIMD operation") \ |
| 342 | T(InvalidSimdLaneValue, "Lane value out of bounds for SIMD operation") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 343 | T(LetInLexicalBinding, "let is disallowed as a lexically bound name") \ |
| 344 | T(LocaleMatcher, "Illegal value for localeMatcher:%") \ |
| 345 | T(NormalizationForm, "The normalization form should be one of %.") \ |
| 346 | T(NumberFormatRange, "% argument must be between 0 and 20") \ |
| 347 | T(PropertyValueOutOfRange, "% value is out of range.") \ |
| 348 | T(StackOverflow, "Maximum call stack size exceeded") \ |
| 349 | T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \ |
| 350 | T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \ |
| 351 | T(TypedArraySetNegativeOffset, "Start offset is negative") \ |
| 352 | T(TypedArraySetSourceTooLarge, "Source is too large") \ |
| 353 | T(UnsupportedTimeZone, "Unsupported time zone specified %") \ |
| 354 | T(ValueOutOfRange, "Value % out of range for % options property %") \ |
| 355 | /* SyntaxError */ \ |
| 356 | T(BadGetterArity, "Getter must not have any formal parameters.") \ |
| 357 | T(BadSetterArity, "Setter must have exactly one formal parameter.") \ |
| 358 | T(ConstructorIsAccessor, "Class constructor may not be an accessor") \ |
| 359 | T(ConstructorIsGenerator, "Class constructor may not be a generator") \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 360 | T(ConstructorIsAsync, "Class constructor may not be an async method") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 361 | T(DerivedConstructorReturn, \ |
| 362 | "Derived constructors may only return object or undefined") \ |
| 363 | T(DuplicateConstructor, "A class may only have one constructor") \ |
| 364 | T(DuplicateExport, "Duplicate export of '%'") \ |
| 365 | T(DuplicateProto, \ |
| 366 | "Duplicate __proto__ fields are not allowed in object literals") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 367 | T(ForInOfLoopInitializer, \ |
| 368 | "% loop variable declaration may not have an initializer.") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 369 | T(ForInOfLoopMultiBindings, \ |
| 370 | "Invalid left-hand side in % loop: Must have a single binding.") \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 371 | T(GeneratorInLegacyContext, \ |
| 372 | "Generator declarations are not allowed in legacy contexts.") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 373 | T(IllegalBreak, "Illegal break statement") \ |
| 374 | T(IllegalContinue, "Illegal continue statement") \ |
| 375 | T(IllegalLanguageModeDirective, \ |
| 376 | "Illegal '%' directive in function with non-simple parameter list") \ |
| 377 | T(IllegalReturn, "Illegal return statement") \ |
| 378 | T(InvalidEscapedReservedWord, "Keyword must not contain escaped characters") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 379 | T(InvalidEscapedMetaProperty, "'%' must not contain escaped characters") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 380 | T(InvalidLhsInAssignment, "Invalid left-hand side in assignment") \ |
| 381 | T(InvalidCoverInitializedName, "Invalid shorthand property initializer") \ |
| 382 | T(InvalidDestructuringTarget, "Invalid destructuring assignment target") \ |
| 383 | T(InvalidLhsInFor, "Invalid left-hand side in for-loop") \ |
| 384 | T(InvalidLhsInPostfixOp, \ |
| 385 | "Invalid left-hand side expression in postfix operation") \ |
| 386 | T(InvalidLhsInPrefixOp, \ |
| 387 | "Invalid left-hand side expression in prefix operation") \ |
| 388 | T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 389 | T(InvalidOrUnexpectedToken, "Invalid or unexpected token") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 390 | T(JsonParseUnexpectedEOS, "Unexpected end of JSON input") \ |
| 391 | T(JsonParseUnexpectedToken, "Unexpected token % in JSON at position %") \ |
| 392 | T(JsonParseUnexpectedTokenNumber, "Unexpected number in JSON at position %") \ |
| 393 | T(JsonParseUnexpectedTokenString, "Unexpected string in JSON at position %") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 394 | T(LabelRedeclaration, "Label '%' has already been declared") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 395 | T(LabelledFunctionDeclaration, \ |
| 396 | "Labelled function declaration not allowed as the body of a control flow " \ |
| 397 | "structure") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 398 | T(MalformedArrowFunParamList, "Malformed arrow function parameter list") \ |
| 399 | T(MalformedRegExp, "Invalid regular expression: /%/: %") \ |
| 400 | T(MalformedRegExpFlags, "Invalid regular expression flags") \ |
| 401 | T(ModuleExportUndefined, "Export '%' is not defined in module") \ |
| 402 | T(MultipleDefaultsInSwitch, \ |
| 403 | "More than one default clause in switch statement") \ |
| 404 | T(NewlineAfterThrow, "Illegal newline after throw") \ |
| 405 | T(NoCatchOrFinally, "Missing catch or finally after try") \ |
| 406 | T(NotIsvar, "builtin %%IS_VAR: not a variable") \ |
| 407 | T(ParamAfterRest, "Rest parameter must be last formal parameter") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 408 | T(InvalidRestParameter, \ |
| 409 | "Rest parameter must be an identifier or destructuring pattern") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 410 | T(PushPastSafeLength, \ |
| 411 | "Pushing % elements on an array-like of length % " \ |
| 412 | "is disallowed, as the total surpasses 2**53-1") \ |
| 413 | T(ElementAfterRest, "Rest element must be last element in array") \ |
| 414 | T(BadSetterRestParameter, \ |
| 415 | "Setter function argument must not be a rest parameter") \ |
| 416 | T(ParamDupe, "Duplicate parameter name not allowed in this context") \ |
| 417 | T(ParenthesisInArgString, "Function arg string contains parenthesis") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 418 | T(RuntimeWrongNumArgs, "Runtime function given wrong number of arguments") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 419 | T(SingleFunctionLiteral, "Single function literal required") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 420 | T(SloppyFunction, \ |
| 421 | "In non-strict mode code, functions can only be declared at top level, " \ |
| 422 | "inside a block, or as the body of an if statement.") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 423 | T(SpeciesNotConstructor, \ |
| 424 | "object.constructor[Symbol.species] is not a constructor") \ |
| 425 | T(StrictDelete, "Delete of an unqualified identifier in strict mode.") \ |
| 426 | T(StrictEvalArguments, "Unexpected eval or arguments in strict mode") \ |
| 427 | T(StrictFunction, \ |
| 428 | "In strict mode code, functions can only be declared at top level or " \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 429 | "inside a block.") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 430 | T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \ |
| 431 | T(StrictWith, "Strict mode code may not include a with statement") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 432 | T(TemplateOctalLiteral, \ |
| 433 | "Octal literals are not allowed in template strings.") \ |
| 434 | T(ThisFormalParameter, "'this' is not a valid formal parameter name") \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 435 | T(AwaitBindingIdentifier, \ |
| 436 | "'await' is not a valid identifier name in an async function") \ |
| 437 | T(AwaitExpressionFormalParameter, \ |
| 438 | "Illegal await-expression in formal parameters of async function") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 439 | T(TooManyArguments, \ |
| 440 | "Too many arguments in function call (only 65535 allowed)") \ |
| 441 | T(TooManyParameters, \ |
| 442 | "Too many parameters in function definition (only 65535 allowed)") \ |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 443 | T(TooManySpreads, \ |
| 444 | "Literal containing too many nested spreads (up to 65534 allowed)") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 445 | T(TooManyVariables, "Too many variables declared (only 4194303 allowed)") \ |
| 446 | T(TypedArrayTooShort, \ |
| 447 | "Derived TypedArray constructor created an array which was too small") \ |
| 448 | T(UnexpectedEOS, "Unexpected end of input") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 449 | T(UnexpectedFunctionSent, \ |
| 450 | "function.sent expression is not allowed outside a generator") \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 451 | T(UnexpectedInsideTailCall, "Unexpected expression inside tail call") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 452 | T(UnexpectedReserved, "Unexpected reserved word") \ |
| 453 | T(UnexpectedStrictReserved, "Unexpected strict mode reserved word") \ |
| 454 | T(UnexpectedSuper, "'super' keyword unexpected here") \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 455 | T(UnexpectedSloppyTailCall, \ |
| 456 | "Tail call expressions are not allowed in non-strict mode") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 457 | T(UnexpectedNewTarget, "new.target expression is not allowed here") \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 458 | T(UnexpectedTailCall, "Tail call expression is not allowed here") \ |
| 459 | T(UnexpectedTailCallInCatchBlock, \ |
| 460 | "Tail call expression in catch block when finally block is also present") \ |
| 461 | T(UnexpectedTailCallInForInOf, "Tail call expression in for-in/of body") \ |
| 462 | T(UnexpectedTailCallInTryBlock, "Tail call expression in try block") \ |
| 463 | T(UnexpectedTailCallOfEval, "Tail call of a direct eval is not allowed") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 464 | T(UnexpectedTemplateString, "Unexpected template string") \ |
| 465 | T(UnexpectedToken, "Unexpected token %") \ |
| 466 | T(UnexpectedTokenIdentifier, "Unexpected identifier") \ |
| 467 | T(UnexpectedTokenNumber, "Unexpected number") \ |
| 468 | T(UnexpectedTokenString, "Unexpected string") \ |
| 469 | T(UnexpectedTokenRegExp, "Unexpected regular expression") \ |
| 470 | T(UnknownLabel, "Undefined label '%'") \ |
| 471 | T(UnterminatedArgList, "missing ) after argument list") \ |
| 472 | T(UnterminatedRegExp, "Invalid regular expression: missing /") \ |
| 473 | T(UnterminatedTemplate, "Unterminated template literal") \ |
| 474 | T(UnterminatedTemplateExpr, "Missing } in template expression") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 475 | T(FoundNonCallableHasInstance, "Found non-callable @@hasInstance") \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 476 | T(InvalidHexEscapeSequence, "Invalid hexadecimal escape sequence") \ |
| 477 | T(InvalidUnicodeEscapeSequence, "Invalid Unicode escape sequence") \ |
| 478 | T(UndefinedUnicodeCodePoint, "Undefined Unicode code-point") \ |
| 479 | T(YieldInParameter, "Yield expression not allowed in formal parameter") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 480 | /* EvalError */ \ |
| 481 | T(CodeGenFromStrings, "%") \ |
| 482 | /* URIError */ \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 483 | T(URIMalformed, "URI malformed") \ |
| 484 | /* Wasm errors (currently Error) */ \ |
| 485 | T(WasmTrapUnreachable, "unreachable") \ |
| 486 | T(WasmTrapMemOutOfBounds, "memory access out of bounds") \ |
| 487 | T(WasmTrapDivByZero, "divide by zero") \ |
| 488 | T(WasmTrapDivUnrepresentable, "divide result unrepresentable") \ |
| 489 | T(WasmTrapRemByZero, "remainder by zero") \ |
| 490 | T(WasmTrapFloatUnrepresentable, "integer result unrepresentable") \ |
| 491 | T(WasmTrapFuncInvalid, "invalid function") \ |
| 492 | T(WasmTrapFuncSigMismatch, "function signature mismatch") |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 493 | |
| 494 | class MessageTemplate { |
| 495 | public: |
| 496 | enum Template { |
| 497 | #define TEMPLATE(NAME, STRING) k##NAME, |
| 498 | MESSAGE_TEMPLATES(TEMPLATE) |
| 499 | #undef TEMPLATE |
| 500 | kLastMessage |
| 501 | }; |
| 502 | |
| 503 | static const char* TemplateString(int template_index); |
| 504 | |
| 505 | static MaybeHandle<String> FormatMessage(int template_index, |
| 506 | Handle<String> arg0, |
| 507 | Handle<String> arg1, |
| 508 | Handle<String> arg2); |
| 509 | |
| 510 | static Handle<String> FormatMessage(Isolate* isolate, int template_index, |
| 511 | Handle<Object> arg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 512 | }; |
| 513 | |
| 514 | |
| 515 | // A message handler is a convenience interface for accessing the list |
| 516 | // of message listeners registered in an environment |
| 517 | class MessageHandler { |
| 518 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 519 | // Returns a message object for the API to use. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 520 | static Handle<JSMessageObject> MakeMessageObject( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 521 | Isolate* isolate, MessageTemplate::Template type, |
| 522 | MessageLocation* location, Handle<Object> argument, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 523 | Handle<JSArray> stack_frames); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 524 | |
| 525 | // Report a formatted message (needs JS allocation). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 526 | static void ReportMessage(Isolate* isolate, MessageLocation* loc, |
| 527 | Handle<JSMessageObject> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 528 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 529 | static void DefaultMessageReport(Isolate* isolate, const MessageLocation* loc, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 530 | Handle<Object> message_obj); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 531 | static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 532 | static base::SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate, |
| 533 | Handle<Object> data); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 534 | }; |
| 535 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 536 | |
| 537 | } // namespace internal |
| 538 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 539 | |
| 540 | #endif // V8_MESSAGES_H_ |