messages.h 36.9 KB
Newer Older
1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4 5 6 7 8 9 10 11 12

// The infrastructure used for (localized) message reporting in V8.
//
// Note: there's a big unresolved issue about ownership of the data
// structures used by this framework.

#ifndef V8_MESSAGES_H_
#define V8_MESSAGES_H_

13
#include "src/base/smart-pointers.h"
14
#include "src/handles.h"
15
#include "src/list.h"
16

17 18
namespace v8 {
namespace internal {
19

20 21 22
// Forward declarations.
class JSMessageObject;
class LookupIterator;
23 24 25 26
class SourceInfo;

class MessageLocation {
 public:
27
  MessageLocation(Handle<Script> script, int start_pos, int end_pos);
28
  MessageLocation(Handle<Script> script, int start_pos, int end_pos,
29 30
                  Handle<JSFunction> function);
  MessageLocation();
31 32 33 34

  Handle<Script> script() const { return script_; }
  int start_pos() const { return start_pos_; }
  int end_pos() const { return end_pos_; }
35
  Handle<JSFunction> function() const { return function_; }
36 37 38 39 40

 private:
  Handle<Script> script_;
  int start_pos_;
  int end_pos_;
41
  Handle<JSFunction> function_;
42 43 44
};


45 46
class CallSite {
 public:
47
  CallSite(Isolate* isolate, Handle<JSObject> call_site_obj);
48

49 50 51 52
  Handle<Object> GetFileName();
  Handle<Object> GetFunctionName();
  Handle<Object> GetScriptNameOrSourceUrl();
  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 57 58 59 60
  int GetColumnNumber();
  bool IsNative();
  bool IsToplevel();
  bool IsEval();
  bool IsConstructor();
61

62 63
  bool IsJavaScript() { return !fun_.is_null(); }
  bool IsWasm() { return !wasm_obj_.is_null(); }
64

65
 private:
66
  Isolate* isolate_;
67 68
  Handle<Object> receiver_;
  Handle<JSFunction> fun_;
69 70 71
  int32_t pos_ = -1;
  Handle<JSObject> wasm_obj_;
  uint32_t wasm_func_index_ = static_cast<uint32_t>(-1);
72 73
};

74 75
#define MESSAGE_TEMPLATES(T)                                                   \
  /* 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 83 84
  T(Unsupported, "Not supported")                                              \
  T(WrongServiceType, "Internal error, wrong service type: %")                 \
  T(WrongValueType, "Internal error. Wrong value type.")                       \
85 86 87 88
  /* TypeError */                                                              \
  T(ApplyNonFunction,                                                          \
    "Function.prototype.apply was called on %, which is a % and not a "        \
    "function")                                                                \
89 90 91 92
  T(ArrayBufferTooShort,                                                       \
    "Derived ArrayBuffer constructor created a buffer which was too small")    \
  T(ArrayBufferSpeciesThis,                                                    \
    "ArrayBuffer subclass returned this from species constructor")             \
93 94
  T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements")             \
  T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements")         \
95
  T(ArrayNotSubclassable, "Subclassing Arrays is not currently supported.")    \
96 97
  T(CalledNonCallable, "% is not a function")                                  \
  T(CalledOnNonObject, "% called on non-object")                               \
98
  T(CalledOnNullOrUndefined, "% called on null or undefined")                  \
99
  T(CallSiteExpectsFunction,                                                   \
100 101
    "CallSite expects wasm object as first or function as second argument, "   \
    "got <%, %>")                                                              \
102
  T(CallSiteMethod, "CallSite method % expects CallSite as receiver")          \
103
  T(CannotConvertToPrimitive, "Cannot convert object to primitive value")      \
104
  T(CannotPreventExt, "Cannot prevent extensions")                             \
105 106
  T(CannotFreezeArrayBufferView,                                               \
    "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 116
  T(DataViewNotArrayBuffer,                                                    \
    "First argument to DataView constructor must be an ArrayBuffer")           \
117
  T(DateType, "this is not a Date object.")                                    \
118 119
  T(DebuggerFrame, "Debugger: Invalid frame index.")                           \
  T(DebuggerType, "Debugger: Parameters have wrong types.")                    \
120
  T(DeclarationMissingInitializer, "Missing initializer in % declaration")     \
121
  T(DefineDisallowed, "Cannot define property:%, object is not extensible.")   \
122
  T(DetachedOperation, "Cannot perform % on a detached ArrayBuffer")           \
123
  T(DuplicateTemplateProperty, "Object template has duplicate property '%'")   \
124 125
  T(ExtendsValueNotConstructor,                                                \
    "Class extends value % is not a constructor or null")                      \
126 127
  T(FirstArgumentNotRegExp,                                                    \
    "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 132
  T(ImmutablePrototypeSet,                                                     \
    "Immutable prototype object '%' cannot have their prototype set")          \
133 134 135
  T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %")  \
  T(InstanceofNonobjectProto,                                                  \
    "Function has non-object prototype '%' in instanceof check")               \
136
  T(InvalidArgument, "invalid_argument")                                       \
137
  T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %")   \
138 139
  T(InvalidRegExpExecResult,                                                   \
    "RegExp exec method returned something other than an Object or null")      \
140
  T(InvalidSimdOperation, "% is not a valid type for this SIMD operation.")    \
141 142
  T(IteratorResultNotAnObject, "Iterator result % is not an object")           \
  T(IteratorValueNotAnObject, "Iterator value % is not an entry object")       \
143 144 145 146 147 148
  T(LanguageID, "Language ID should be string or object.")                     \
  T(MethodCalledOnWrongObject,                                                 \
    "Method % called on a non-object or on a wrong type of object.")           \
  T(MethodInvokedOnNullOrUndefined,                                            \
    "Method invoked on undefined or null value.")                              \
  T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.")    \
149
  T(NoAccess, "no access")                                                     \
150 151
  T(NonCallableInInstanceOfCheck,                                              \
    "Right-hand side of 'instanceof' is not callable")                         \
152
  T(NonCoercible, "Cannot match against 'undefined' or 'null'.")               \
153
  T(NonExtensibleProto, "% is not extensible")                                 \
154 155
  T(NonObjectInInstanceOfCheck,                                                \
    "Right-hand side of 'instanceof' is not an object")                        \
156 157 158
  T(NonObjectPropertyLoad, "Cannot read property '%' of %")                    \
  T(NonObjectPropertyStore, "Cannot set property '%' of %")                    \
  T(NoSetterInCallback, "Cannot set property % of % which has only a getter")  \
159
  T(NotAnIterator, "% is not an iterator")                                     \
160
  T(NotAPromise, "% is not a promise")                                         \
161
  T(NotConstructor, "% is not a constructor")                                  \
162 163
  T(NotDateObject, "this is not a Date object.")                               \
  T(NotIntlObject, "% is not an i18n object.")                                 \
164 165
  T(NotGeneric, "% is not generic")                                            \
  T(NotIterable, "% is not iterable")                                          \
166
  T(NotPropertyName, "% is not a valid property name")                         \
167
  T(NotTypedArray, "this is not a typed array.")                               \
binji's avatar
binji committed
168 169
  T(NotSharedTypedArray, "% is not a shared typed array.")                     \
  T(NotIntegerSharedTypedArray, "% is not an integer shared typed array.")     \
binji's avatar
binji committed
170
  T(NotInt32SharedTypedArray, "% is not an int32 shared typed array.")         \
171 172 173
  T(ObjectGetterExpectingFunction,                                             \
    "Object.prototype.__defineGetter__: Expecting function")                   \
  T(ObjectGetterCallable, "Getter must be a function: %")                      \
174
  T(ObjectNotExtensible, "Can't add property %, object is not extensible")     \
175 176 177
  T(ObjectSetterExpectingFunction,                                             \
    "Object.prototype.__defineSetter__: Expecting function")                   \
  T(ObjectSetterCallable, "Setter must be a function: %")                      \
178 179
  T(OrdinaryFunctionCalledAsConstructor,                                       \
    "Function object that's not a constructor was created with new")           \
180
  T(PromiseCyclic, "Chaining cycle detected for promise %")                    \
181 182
  T(PromiseExecutorAlreadyInvoked,                                             \
    "Promise executor has already been invoked with non-undefined arguments")  \
183
  T(PromiseNonCallable, "Promise resolve or reject function is not callable")  \
184
  T(PropertyDescObject, "Property description must be an object: %")           \
185 186
  T(PropertyNotFunction,                                                       \
    "'%' returned for property '%' of object '%' is not a function")           \
187
  T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %")    \
188 189
  T(PrototypeParentNotAnObject,                                                \
    "Class extends value does not have valid prototype property %")            \
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  T(ProxyConstructNonObject,                                                   \
    "'construct' on proxy: trap returned non-object ('%')")                    \
  T(ProxyDefinePropertyNonConfigurable,                                        \
    "'defineProperty' on proxy: trap returned truish for defining "            \
    "non-configurable property '%' which is either non-existant or "           \
    "configurable in the proxy target")                                        \
  T(ProxyDefinePropertyNonExtensible,                                          \
    "'defineProperty' on proxy: trap returned truish for adding property '%' " \
    " to the non-extensible proxy target")                                     \
  T(ProxyDefinePropertyIncompatible,                                           \
    "'defineProperty' on proxy: trap returned truish for adding property '%' " \
    " that is incompatible with the existing property in the proxy target")    \
  T(ProxyDeletePropertyNonConfigurable,                                        \
    "'deleteProperty' on proxy: trap returned truish for property '%' which "  \
    "is non-configurable in the proxy target")                                 \
  T(ProxyGetNonConfigurableData,                                               \
    "'get' on proxy: property '%' is a read-only and "                         \
    "non-configurable data property on the proxy target but the proxy "        \
    "did not return its actual value (expected '%' but got '%')")              \
  T(ProxyGetNonConfigurableAccessor,                                           \
    "'get' on proxy: property '%' is a non-configurable accessor "             \
    "property on the proxy target and does not have a getter function, but "   \
    "the trap did not return 'undefined' (got '%')")                           \
  T(ProxyGetOwnPropertyDescriptorIncompatible,                                 \
    "'getOwnPropertyDescriptor' on proxy: trap returned descriptor for "       \
    "property '%' that is incompatible with the existing property in the "     \
    "proxy target")                                                            \
  T(ProxyGetOwnPropertyDescriptorInvalid,                                      \
    "'getOwnPropertyDescriptor' on proxy: trap returned neither object nor "   \
    "undefined for property '%'")                                              \
  T(ProxyGetOwnPropertyDescriptorNonConfigurable,                              \
    "'getOwnPropertyDescriptor' on proxy: trap reported non-configurability "  \
    "for property '%' which is either non-existant or configurable in the "    \
    "proxy target")                                                            \
  T(ProxyGetOwnPropertyDescriptorNonExtensible,                                \
    "'getOwnPropertyDescriptor' on proxy: trap returned undefined for "        \
    "property '%' which exists in the non-extensible proxy target")            \
  T(ProxyGetOwnPropertyDescriptorUndefined,                                    \
    "'getOwnPropertyDescriptor' on proxy: trap returned undefined for "        \
    "property '%' which is non-configurable in the proxy target")              \
  T(ProxyGetPrototypeOfInvalid,                                                \
    "'getPrototypeOf' on proxy: trap returned neither object nor null")        \
  T(ProxyGetPrototypeOfNonExtensible,                                          \
    "'getPrototypeOf' on proxy: proxy target is non-extensible but the "       \
    "trap did not return its actual prototype")                                \
235
  T(ProxyHandlerOrTargetRevoked,                                               \
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
    "Cannot create proxy with a revoked proxy as target or handler")           \
  T(ProxyHasNonConfigurable,                                                   \
    "'has' on proxy: trap returned falsish for property '%' which exists in "  \
    "the proxy target as non-configurable")                                    \
  T(ProxyHasNonExtensible,                                                     \
    "'has' on proxy: trap returned falsish for property '%' but the proxy "    \
    "target is not extensible")                                                \
  T(ProxyIsExtensibleInconsistent,                                             \
    "'isExtensible' on proxy: trap result does not reflect extensibility of "  \
    "proxy target (which is '%')")                                             \
  T(ProxyNonObject,                                                            \
    "Cannot create proxy with a non-object as target or handler")              \
  T(ProxyOwnKeysMissing,                                                       \
    "'ownKeys' on proxy: trap result did not include '%'")                     \
  T(ProxyOwnKeysNonExtensible,                                                 \
    "'ownKeys' on proxy: trap returned extra keys but proxy target is "        \
    "non-extensible")                                                          \
  T(ProxyPreventExtensionsExtensible,                                          \
    "'preventExtensions' on proxy: trap returned truish but the proxy target " \
    "is extensible")                                                           \
256
  T(ProxyPrivate, "Cannot pass private property name to proxy trap")           \
257
  T(ProxyRevoked, "Cannot perform '%' on a proxy that has been revoked")       \
258 259 260 261 262 263 264 265 266 267 268 269 270 271
  T(ProxySetFrozenData,                                                        \
    "'set' on proxy: trap returned truish for property '%' which exists in "   \
    "the proxy target as a non-configurable and non-writable data property "   \
    "with a different value")                                                  \
  T(ProxySetFrozenAccessor,                                                    \
    "'set' on proxy: trap returned truish for property '%' which exists in "   \
    "the proxy target as a non-configurable and non-writable accessor "        \
    "property without a setter")                                               \
  T(ProxySetPrototypeOfNonExtensible,                                          \
    "'setPrototypeOf' on proxy: trap returned truish for setting a new "       \
    "prototype on the non-extensible proxy target")                            \
  T(ProxyTrapReturnedFalsish, "'%' on proxy: trap returned falsish")           \
  T(ProxyTrapReturnedFalsishFor,                                               \
    "'%' on proxy: trap returned falsish for property '%'")                    \
272
  T(ReadGlobalReferenceThroughProxy, "Trying to access '%' through proxy")     \
273
  T(RedefineDisallowed, "Cannot redefine property: %")                         \
274 275
  T(RedefineExternalArray,                                                     \
    "Cannot redefine a property of an object with external array elements")    \
276
  T(ReduceNoInitial, "Reduce of empty array with no initial value")            \
277 278
  T(RegExpFlags,                                                               \
    "Cannot supply flags when constructing one RegExp from another")           \
279 280
  T(RegExpNonObject, "% getter called on non-object %")                        \
  T(RegExpNonRegExp, "% getter called on non-RegExp object")                   \
281 282 283 284
  T(ReinitializeIntl, "Trying to re-initialize % object.")                     \
  T(ResolvedOptionsCalledOnNonObject,                                          \
    "resolvedOptions method called on a non-object or on a object that is "    \
    "not Intl.%.")                                                             \
285
  T(ResolverNotAFunction, "Promise resolver % is not a function")              \
286 287 288
  T(RestrictedFunctionProperties,                                              \
    "'caller' and 'arguments' are restricted function properties and cannot "  \
    "be accessed in this context.")                                            \
289
  T(ReturnMethodNotCallable, "The iterator's 'return' method is not callable") \
290
  T(StaticPrototype, "Classes may not have static property named prototype")   \
291
  T(StrictCannotAssign, "Cannot assign to read only '%' in strict mode")       \
292 293 294 295
  T(StrictDeleteProperty, "Cannot delete property '%' of %")                   \
  T(StrictPoisonPill,                                                          \
    "'caller', 'callee', and 'arguments' properties may not be accessed on "   \
    "strict mode functions or the arguments objects for calls to them")        \
296 297 298
  T(StrictReadOnlyProperty,                                                    \
    "Cannot assign to read only property '%' of % '%'")                        \
  T(StrictCannotCreateProperty, "Cannot create property '%' on % '%'")         \
neis's avatar
neis committed
299 300
  T(SymbolIteratorInvalid,                                                     \
    "Result of the Symbol.iterator method is not an object")                   \
301
  T(SymbolKeyFor, "% is not a symbol")                                         \
302 303
  T(SymbolToNumber, "Cannot convert a Symbol value to a number")               \
  T(SymbolToString, "Cannot convert a Symbol value to a string")               \
304
  T(SimdToNumber, "Cannot convert a SIMD value to a number")                   \
neis's avatar
neis committed
305
  T(ThrowMethodMissing, "The iterator does not provide a 'throw' method.")     \
306 307
  T(UndefinedOrNullToObject, "Cannot convert undefined or null to object")     \
  T(ValueAndAccessor,                                                          \
308 309
    "Invalid property descriptor. Cannot both specify accessors and a value "  \
    "or writable attribute, %")                                                \
310
  T(VarRedeclaration, "Identifier '%' has already been declared")              \
311
  T(WrongArgs, "%: Arguments list has wrong type")                             \
312 313 314 315
  /* ReferenceError */                                                         \
  T(NonMethod, "'super' is referenced from non-method")                        \
  T(NotDefined, "% is not defined")                                            \
  T(UnsupportedSuper, "Unsupported reference to 'super'")                      \
316
  /* RangeError */                                                             \
317
  T(DateRange, "Provided date is not in valid range.")                         \
jshin's avatar
jshin committed
318 319 320 321 322
  T(ExpectedTimezoneID,                                                        \
    "Expected Area/Location(/Location)* for time zone, got %")                 \
  T(ExpectedLocation,                                                          \
    "Expected letters optionally connected with underscores or hyphens for "   \
    "a location, got %")                                                       \
323
  T(InvalidArrayBufferLength, "Invalid array buffer length")                   \
324
  T(ArrayBufferAllocationFailed, "Array buffer allocation failed")             \
325
  T(InvalidArrayLength, "Invalid array length")                                \
326
  T(InvalidAtomicAccessIndex, "Invalid atomic access index")                   \
327 328
  T(InvalidCodePoint, "Invalid code point %")                                  \
  T(InvalidCountValue, "Invalid count value")                                  \
329
  T(InvalidCurrencyCode, "Invalid currency code: %")                           \
330 331
  T(InvalidDataViewAccessorOffset,                                             \
    "Offset is outside the bounds of the DataView")                            \
332 333
  T(InvalidDataViewLength, "Invalid data view length")                         \
  T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \
334
  T(InvalidHint, "Invalid hint: %")                                            \
335
  T(InvalidLanguageTag, "Invalid language tag: %")                             \
336 337
  T(InvalidWeakMapKey, "Invalid value used as weak map key")                   \
  T(InvalidWeakSetValue, "Invalid value used in weak set")                     \
338
  T(InvalidStringLength, "Invalid string length")                              \
339
  T(InvalidTimeValue, "Invalid time value")                                    \
340 341 342
  T(InvalidTypedArrayAlignment, "% of % should be a multiple of %")            \
  T(InvalidTypedArrayLength, "Invalid typed array length")                     \
  T(InvalidTypedArrayOffset, "Start offset is too large:")                     \
343 344
  T(InvalidSimdIndex, "Index out of bounds for SIMD operation")                \
  T(InvalidSimdLaneValue, "Lane value out of bounds for SIMD operation")       \
345
  T(LetInLexicalBinding, "let is disallowed as a lexically bound name")        \
346 347
  T(LocaleMatcher, "Illegal value for localeMatcher:%")                        \
  T(NormalizationForm, "The normalization form should be one of %.")           \
348
  T(NumberFormatRange, "% argument must be between 0 and 20")                  \
349
  T(PropertyValueOutOfRange, "% value is out of range.")                       \
350 351
  T(StackOverflow, "Maximum call stack size exceeded")                         \
  T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
352
  T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36")  \
353 354
  T(TypedArraySetNegativeOffset, "Start offset is negative")                   \
  T(TypedArraySetSourceTooLarge, "Source is too large")                        \
355 356
  T(UnsupportedTimeZone, "Unsupported time zone specified %")                  \
  T(ValueOutOfRange, "Value % out of range for % options property %")          \
357
  /* SyntaxError */                                                            \
358 359 360 361
  T(BadGetterArity, "Getter must not have any formal parameters.")             \
  T(BadSetterArity, "Setter must have exactly one formal parameter.")          \
  T(ConstructorIsAccessor, "Class constructor may not be an accessor")         \
  T(ConstructorIsGenerator, "Class constructor may not be a generator")        \
362
  T(ConstructorIsAsync, "Class constructor may not be an async method")        \
363 364 365 366 367 368
  T(DerivedConstructorReturn,                                                  \
    "Derived constructors may only return object or undefined")                \
  T(DuplicateConstructor, "A class may only have one constructor")             \
  T(DuplicateExport, "Duplicate export of '%'")                                \
  T(DuplicateProto,                                                            \
    "Duplicate __proto__ fields are not allowed in object literals")           \
369 370
  T(ForInOfLoopInitializer,                                                    \
    "% loop variable declaration may not have an initializer.")                \
371 372
  T(ForInOfLoopMultiBindings,                                                  \
    "Invalid left-hand side in % loop: Must have a single binding.")           \
373 374
  T(GeneratorInLegacyContext,                                                  \
    "Generator declarations are not allowed in legacy contexts.")              \
375 376
  T(IllegalBreak, "Illegal break statement")                                   \
  T(IllegalContinue, "Illegal continue statement")                             \
377 378
  T(IllegalLanguageModeDirective,                                              \
    "Illegal '%' directive in function with non-simple parameter list")        \
379
  T(IllegalReturn, "Illegal return statement")                                 \
380
  T(InvalidEscapedReservedWord, "Keyword must not contain escaped characters") \
381
  T(InvalidEscapedMetaProperty, "'%' must not contain escaped characters")     \
382
  T(InvalidLhsInAssignment, "Invalid left-hand side in assignment")            \
383 384
  T(InvalidCoverInitializedName, "Invalid shorthand property initializer")     \
  T(InvalidDestructuringTarget, "Invalid destructuring assignment target")     \
385 386 387 388 389
  T(InvalidLhsInFor, "Invalid left-hand side in for-loop")                     \
  T(InvalidLhsInPostfixOp,                                                     \
    "Invalid left-hand side expression in postfix operation")                  \
  T(InvalidLhsInPrefixOp,                                                      \
    "Invalid left-hand side expression in prefix operation")                   \
390
  T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'")    \
391
  T(InvalidOrUnexpectedToken, "Invalid or unexpected token")                   \
392 393 394 395
  T(JsonParseUnexpectedEOS, "Unexpected end of JSON input")                    \
  T(JsonParseUnexpectedToken, "Unexpected token % in JSON at position %")      \
  T(JsonParseUnexpectedTokenNumber, "Unexpected number in JSON at position %") \
  T(JsonParseUnexpectedTokenString, "Unexpected string in JSON at position %") \
396
  T(LabelRedeclaration, "Label '%' has already been declared")                 \
397 398 399
  T(LabelledFunctionDeclaration,                                               \
    "Labelled function declaration not allowed as the body of a control flow " \
    "structure")                                                               \
400
  T(MalformedArrowFunParamList, "Malformed arrow function parameter list")     \
401
  T(MalformedRegExp, "Invalid regular expression: /%/: %")                     \
402 403 404 405 406 407 408 409
  T(MalformedRegExpFlags, "Invalid regular expression flags")                  \
  T(ModuleExportUndefined, "Export '%' is not defined in module")              \
  T(MultipleDefaultsInSwitch,                                                  \
    "More than one default clause in switch statement")                        \
  T(NewlineAfterThrow, "Illegal newline after throw")                          \
  T(NoCatchOrFinally, "Missing catch or finally after try")                    \
  T(NotIsvar, "builtin %%IS_VAR: not a variable")                              \
  T(ParamAfterRest, "Rest parameter must be last formal parameter")            \
410 411
  T(InvalidRestParameter,                                                      \
    "Rest parameter must be an identifier or destructuring pattern")           \
412 413 414
  T(PushPastSafeLength,                                                        \
    "Pushing % elements on an array-like of length % "                         \
    "is disallowed, as the total surpasses 2**53-1")                           \
415
  T(ElementAfterRest, "Rest element must be last element in array")            \
416 417
  T(BadSetterRestParameter,                                                    \
    "Setter function argument must not be a rest parameter")                   \
418
  T(ParamDupe, "Duplicate parameter name not allowed in this context")         \
419
  T(ParenthesisInArgString, "Function arg string contains parenthesis")        \
420
  T(RuntimeWrongNumArgs, "Runtime function given wrong number of arguments")   \
421
  T(SingleFunctionLiteral, "Single function literal required")                 \
422 423 424
  T(SloppyFunction,                                                            \
    "In non-strict mode code, functions can only be declared at top level, "   \
    "inside a block, or as the body of an if statement.")                      \
425 426
  T(SpeciesNotConstructor,                                                     \
    "object.constructor[Symbol.species] is not a constructor")                 \
427 428 429 430
  T(StrictDelete, "Delete of an unqualified identifier in strict mode.")       \
  T(StrictEvalArguments, "Unexpected eval or arguments in strict mode")        \
  T(StrictFunction,                                                            \
    "In strict mode code, functions can only be declared at top level or "     \
431
    "inside a block.")                                                         \
432 433 434 435 436
  T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.")      \
  T(StrictWith, "Strict mode code may not include a with statement")           \
  T(TemplateOctalLiteral,                                                      \
    "Octal literals are not allowed in template strings.")                     \
  T(ThisFormalParameter, "'this' is not a valid formal parameter name")        \
437 438 439 440
  T(AwaitBindingIdentifier,                                                    \
    "'await' is not a valid identifier name in an async function")             \
  T(AwaitExpressionFormalParameter,                                            \
    "Illegal await-expression in formal parameters of async function")         \
441 442 443 444
  T(TooManyArguments,                                                          \
    "Too many arguments in function call (only 65535 allowed)")                \
  T(TooManyParameters,                                                         \
    "Too many parameters in function definition (only 65535 allowed)")         \
445 446
  T(TooManySpreads,                                                            \
    "Literal containing too many nested spreads (up to 65534 allowed)")        \
447
  T(TooManyVariables, "Too many variables declared (only 4194303 allowed)")    \
448 449
  T(TypedArrayTooShort,                                                        \
    "Derived TypedArray constructor created an array which was too small")     \
450
  T(UnexpectedEOS, "Unexpected end of input")                                  \
451 452
  T(UnexpectedFunctionSent,                                                    \
    "function.sent expression is not allowed outside a generator")             \
453
  T(UnexpectedInsideTailCall, "Unexpected expression inside tail call")        \
454 455 456
  T(UnexpectedReserved, "Unexpected reserved word")                            \
  T(UnexpectedStrictReserved, "Unexpected strict mode reserved word")          \
  T(UnexpectedSuper, "'super' keyword unexpected here")                        \
457 458
  T(UnexpectedSloppyTailCall,                                                  \
    "Tail call expressions are not allowed in non-strict mode")                \
459
  T(UnexpectedNewTarget, "new.target expression is not allowed here")          \
460 461 462 463 464
  T(UnexpectedTailCall, "Tail call expression is not allowed here")            \
  T(UnexpectedTailCallInCatchBlock,                                            \
    "Tail call expression in catch block when finally block is also present")  \
  T(UnexpectedTailCallInForInOf, "Tail call expression in for-in/of body")     \
  T(UnexpectedTailCallInTryBlock, "Tail call expression in try block")         \
465
  T(UnexpectedTailCallOfEval, "Tail call of a direct eval is not allowed")     \
466
  T(UnexpectedTemplateString, "Unexpected template string")                    \
467
  T(UnexpectedToken, "Unexpected token %")                                     \
468
  T(UnexpectedTokenIdentifier, "Unexpected identifier")                        \
469 470
  T(UnexpectedTokenNumber, "Unexpected number")                                \
  T(UnexpectedTokenString, "Unexpected string")                                \
471
  T(UnexpectedTokenRegExp, "Unexpected regular expression")                    \
472 473 474 475 476
  T(UnknownLabel, "Undefined label '%'")                                       \
  T(UnterminatedArgList, "missing ) after argument list")                      \
  T(UnterminatedRegExp, "Invalid regular expression: missing /")               \
  T(UnterminatedTemplate, "Unterminated template literal")                     \
  T(UnterminatedTemplateExpr, "Missing } in template expression")              \
477
  T(FoundNonCallableHasInstance, "Found non-callable @@hasInstance")           \
478 479 480
  T(InvalidHexEscapeSequence, "Invalid hexadecimal escape sequence")           \
  T(InvalidUnicodeEscapeSequence, "Invalid Unicode escape sequence")           \
  T(UndefinedUnicodeCodePoint, "Undefined Unicode code-point")                 \
481
  T(YieldInParameter, "Yield expression not allowed in formal parameter")      \
482
  /* EvalError */                                                              \
483 484
  T(CodeGenFromStrings, "%")                                                   \
  /* URIError */                                                               \
485 486 487 488 489 490 491 492 493
  T(URIMalformed, "URI malformed")                                             \
  /* Wasm errors (currently Error) */                                          \
  T(WasmTrapUnreachable, "unreachable")                                        \
  T(WasmTrapMemOutOfBounds, "memory access out of bounds")                     \
  T(WasmTrapDivByZero, "divide by zero")                                       \
  T(WasmTrapDivUnrepresentable, "divide result unrepresentable")               \
  T(WasmTrapRemByZero, "remainder by zero")                                    \
  T(WasmTrapFloatUnrepresentable, "integer result unrepresentable")            \
  T(WasmTrapFuncInvalid, "invalid function")                                   \
494 495
  T(WasmTrapFuncSigMismatch, "function signature mismatch")                    \
  T(WasmTrapMemAllocationFail, "failed to allocate memory")
496 497 498 499 500 501 502 503 504 505

class MessageTemplate {
 public:
  enum Template {
#define TEMPLATE(NAME, STRING) k##NAME,
    MESSAGE_TEMPLATES(TEMPLATE)
#undef TEMPLATE
        kLastMessage
  };

506 507
  static const char* TemplateString(int template_index);

508 509 510 511
  static MaybeHandle<String> FormatMessage(int template_index,
                                           Handle<String> arg0,
                                           Handle<String> arg1,
                                           Handle<String> arg2);
512 513 514 515 516 517 518 519 520 521 522 523

  static Handle<String> FormatMessage(Isolate* isolate, int template_index,
                                      Handle<Object> arg);
};


// A message handler is a convenience interface for accessing the list
// of message listeners registered in an environment
class MessageHandler {
 public:
  // Returns a message object for the API to use.
  static Handle<JSMessageObject> MakeMessageObject(
524 525 526
      Isolate* isolate, MessageTemplate::Template type,
      MessageLocation* location, Handle<Object> argument,
      Handle<JSArray> stack_frames);
527 528 529

  // Report a formatted message (needs JS allocation).
  static void ReportMessage(Isolate* isolate, MessageLocation* loc,
530
                            Handle<JSMessageObject> message);
531 532 533 534

  static void DefaultMessageReport(Isolate* isolate, const MessageLocation* loc,
                                   Handle<Object> message_obj);
  static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
rmcilroy's avatar
rmcilroy committed
535 536
  static base::SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
                                                           Handle<Object> data);
537
};
538 539


540 541
}  // namespace internal
}  // namespace v8
542 543

#endif  // V8_MESSAGES_H_