messages.h 38.4 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 28
  MessageLocation(Handle<Script> script, int start_pos, int end_pos,
                  Handle<JSFunction> function = Handle<JSFunction>())
29 30
      : script_(script),
        start_pos_(start_pos),
31 32
        end_pos_(end_pos),
        function_(function) {}
33
  MessageLocation() : start_pos_(-1), end_pos_(-1) { }
34 35 36 37

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

 private:
  Handle<Script> script_;
  int start_pos_;
  int end_pos_;
44
  Handle<JSFunction> function_;
45 46 47
};


48 49
class CallSite {
 public:
50
  CallSite(Isolate* isolate, Handle<JSObject> call_site_obj);
51

52 53 54 55
  Handle<Object> GetFileName();
  Handle<Object> GetFunctionName();
  Handle<Object> GetScriptNameOrSourceUrl();
  Handle<Object> GetMethodName();
56
  // Return 1-based line number, including line offset.
57
  int GetLineNumber();
58
  // Return 1-based column number, including column offset if first line.
59 60 61 62 63
  int GetColumnNumber();
  bool IsNative();
  bool IsToplevel();
  bool IsEval();
  bool IsConstructor();
64

65 66
  bool IsValid() { return !fun_.is_null(); }

67
 private:
68
  Isolate* isolate_;
69 70
  Handle<Object> receiver_;
  Handle<JSFunction> fun_;
71
  int32_t pos_;
72 73 74
};


75 76
#define MESSAGE_TEMPLATES(T)                                                   \
  /* Error */                                                                  \
77
  T(None, "")                                                                  \
78
  T(CyclicProto, "Cyclic __proto__ value")                                     \
79
  T(Debugger, "Debugger: %")                                                   \
80
  T(DebuggerLoading, "Error loading debugger")                                 \
81
  T(DefaultOptionsMissing, "Internal % error. Default options are missing.")   \
82
  T(UncaughtException, "Uncaught %")                                           \
83 84 85
  T(Unsupported, "Not supported")                                              \
  T(WrongServiceType, "Internal error, wrong service type: %")                 \
  T(WrongValueType, "Internal error. Wrong value type.")                       \
86 87 88 89
  /* TypeError */                                                              \
  T(ApplyNonFunction,                                                          \
    "Function.prototype.apply was called on %, which is a % and not a "        \
    "function")                                                                \
90 91 92 93
  T(ArrayBufferTooShort,                                                       \
    "Derived ArrayBuffer constructor created a buffer which was too small")    \
  T(ArrayBufferSpeciesThis,                                                    \
    "ArrayBuffer subclass returned this from species constructor")             \
94 95
  T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements")             \
  T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements")         \
96
  T(ArrayNotSubclassable, "Subclassing Arrays is not currently supported.")    \
97 98
  T(CalledNonCallable, "% is not a function")                                  \
  T(CalledOnNonObject, "% called on non-object")                               \
99
  T(CalledOnNullOrUndefined, "% called on null or undefined")                  \
100 101
  T(CallSiteExpectsFunction,                                                   \
    "CallSite expects function as second argument, got %")                     \
102
  T(CannotConvertToPrimitive, "Cannot convert object to primitive value")      \
103
  T(CannotPreventExt, "Cannot prevent extensions")                             \
104 105
  T(CannotFreezeArrayBufferView,                                               \
    "Cannot freeze array buffer views with elements")                          \
106
  T(CircularStructure, "Converting circular structure to JSON")                \
107
  T(ConstructAbstractClass, "Abstract class % not directly constructable")     \
108
  T(ConstAssign, "Assignment to constant variable.")                           \
109
  T(ConstructorNonCallable,                                                    \
110
    "Class constructor % cannot be invoked without 'new'")                     \
111
  T(ConstructorNotFunction, "Constructor % requires 'new'")                    \
112
  T(ConstructorNotReceiver, "The .constructor property is not an object")      \
113
  T(CurrencyCode, "Currency code is required with currency style.")            \
114 115
  T(DataViewNotArrayBuffer,                                                    \
    "First argument to DataView constructor must be an ArrayBuffer")           \
116
  T(DateType, "this is not a Date object.")                                    \
117 118
  T(DebuggerFrame, "Debugger: Invalid frame index.")                           \
  T(DebuggerType, "Debugger: Parameters have wrong types.")                    \
119
  T(DeclarationMissingInitializer, "Missing initializer in % declaration")     \
120
  T(DefineDisallowed, "Cannot define property:%, object is not extensible.")   \
121 122 123 124 125
  T(DuplicateTemplateProperty, "Object template has duplicate property '%'")   \
  T(ExtendsValueGenerator,                                                     \
    "Class extends value % may not be a generator function")                   \
  T(ExtendsValueNotFunction,                                                   \
    "Class extends value % is not a function 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 133 134 135
  T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %")  \
  T(InstanceofFunctionExpected,                                                \
    "Expecting a function in instanceof check, but got %")                     \
  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
  T(InvalidSimdOperation, "% is not a valid type for this SIMD operation.")    \
139 140
  T(IteratorResultNotAnObject, "Iterator result % is not an object")           \
  T(IteratorValueNotAnObject, "Iterator value % is not an entry object")       \
141 142 143 144 145 146
  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 %.")    \
147
  T(NoAccess, "no access")                                                     \
148
  T(NonCoercible, "Cannot match against 'undefined' or 'null'.")               \
149 150 151 152
  T(NonExtensibleProto, "% is not extensible")                                 \
  T(NonObjectPropertyLoad, "Cannot read property '%' of %")                    \
  T(NonObjectPropertyStore, "Cannot set property '%' of %")                    \
  T(NoSetterInCallback, "Cannot set property % of % which has only a getter")  \
153
  T(NotAnIterator, "% is not an iterator")                                     \
154
  T(NotAPromise, "% is not a promise")                                         \
155
  T(NotConstructor, "% is not a constructor")                                  \
156 157
  T(NotDateObject, "this is not a Date object.")                               \
  T(NotIntlObject, "% is not an i18n object.")                                 \
158 159
  T(NotGeneric, "% is not generic")                                            \
  T(NotIterable, "% is not iterable")                                          \
160
  T(NotPropertyName, "% is not a valid property name")                         \
161
  T(NotTypedArray, "this is not a typed array.")                               \
binji's avatar
binji committed
162 163
  T(NotSharedTypedArray, "% is not a shared typed array.")                     \
  T(NotIntegerSharedTypedArray, "% is not an integer shared typed array.")     \
binji's avatar
binji committed
164
  T(NotInt32SharedTypedArray, "% is not an int32 shared typed array.")         \
165 166 167
  T(ObjectGetterExpectingFunction,                                             \
    "Object.prototype.__defineGetter__: Expecting function")                   \
  T(ObjectGetterCallable, "Getter must be a function: %")                      \
168
  T(ObjectNotExtensible, "Can't add property %, object is not extensible")     \
169 170 171
  T(ObjectSetterExpectingFunction,                                             \
    "Object.prototype.__defineSetter__: Expecting function")                   \
  T(ObjectSetterCallable, "Setter must be a function: %")                      \
172 173 174
  T(ObserveCallbackFrozen,                                                     \
    "Object.observe cannot deliver to a frozen function object")               \
  T(ObserveGlobalProxy, "% cannot be called on the global proxy object")       \
175
  T(ObserveAccessChecked, "% cannot be called on access-checked objects")      \
176 177 178 179 180 181 182 183 184
  T(ObserveInvalidAccept,                                                      \
    "Third argument to Object.observe must be an array of strings.")           \
  T(ObserveNonFunction, "Object.% cannot deliver to non-function")             \
  T(ObserveNonObject, "Object.% cannot % non-object")                          \
  T(ObserveNotifyNonNotifier, "notify called on non-notifier object")          \
  T(ObservePerformNonFunction, "Cannot perform non-function")                  \
  T(ObservePerformNonString, "Invalid non-string changeType")                  \
  T(ObserveTypeNonString,                                                      \
    "Invalid changeRecord with non-string 'type' property")                    \
185 186
  T(OrdinaryFunctionCalledAsConstructor,                                       \
    "Function object that's not a constructor was created with new")           \
187
  T(PromiseCyclic, "Chaining cycle detected for promise %")                    \
188 189
  T(PromiseExecutorAlreadyInvoked,                                             \
    "Promise executor has already been invoked with non-undefined arguments")  \
190
  T(PropertyDescObject, "Property description must be an object: %")           \
191 192
  T(PropertyNotFunction,                                                       \
    "'%' returned for property '%' of object '%' is not a function")           \
193
  T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %")    \
194 195
  T(PrototypeParentNotAnObject,                                                \
    "Class extends value does not have valid prototype property %")            \
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 235 236 237 238 239 240 241 242 243
  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(ProxyEnumerateNonObject, "'enumerate' on proxy: trap returned non-object") \
  T(ProxyEnumerateNonString,                                                   \
    "'enumerate' on proxy: trap result includes non-string")                   \
  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")                                \
244
  T(ProxyHandlerOrTargetRevoked,                                               \
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
    "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")                                                           \
265
  T(ProxyPrivate, "Cannot pass private property name to proxy trap")           \
266
  T(ProxyRevoked, "Cannot perform '%' on a proxy that has been revoked")       \
267 268 269 270 271 272 273 274 275 276 277 278 279 280
  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 '%'")                    \
281
  T(ReadGlobalReferenceThroughProxy, "Trying to access '%' through proxy")     \
282
  T(RedefineDisallowed, "Cannot redefine property: %")                         \
283 284
  T(RedefineExternalArray,                                                     \
    "Cannot redefine a property of an object with external array elements")    \
285
  T(ReduceNoInitial, "Reduce of empty array with no initial value")            \
286 287
  T(RegExpFlags,                                                               \
    "Cannot supply flags when constructing one RegExp from another")           \
288 289
  T(RegExpNonObject, "% getter called on non-object %")                        \
  T(RegExpNonRegExp, "% getter called on non-RegExp object")                   \
290 291 292 293
  T(ReinitializeIntl, "Trying to re-initialize % object.")                     \
  T(ResolvedOptionsCalledOnNonObject,                                          \
    "resolvedOptions method called on a non-object or on a object that is "    \
    "not Intl.%.")                                                             \
294
  T(ResolverNotAFunction, "Promise resolver % is not a function")              \
295 296 297 298
  T(RestrictedFunctionProperties,                                              \
    "'caller' and 'arguments' are restricted function properties and cannot "  \
    "be accessed in this context.")                                            \
  T(StaticPrototype, "Classes may not have static property named prototype")   \
299
  T(StrictCannotAssign, "Cannot assign to read only '%' in strict mode")       \
300 301 302 303
  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")        \
304 305 306
  T(StrictReadOnlyProperty,                                                    \
    "Cannot assign to read only property '%' of % '%'")                        \
  T(StrictCannotCreateProperty, "Cannot create property '%' on % '%'")         \
307 308
  T(StrongArity,                                                               \
    "In strong mode, calling a function with too few arguments is deprecated") \
309
  T(StrongDeleteProperty,                                                      \
310
    "Deleting property '%' of strong object '%' is deprecated")                \
311
  T(StrongExtendNull, "In strong mode, classes extending null are deprecated") \
312 313
  T(StrongImplicitConversion,                                                  \
    "In strong mode, implicit conversions are deprecated")                     \
314 315 316
  T(StrongRedefineDisallowed,                                                  \
    "On strong object %, redefining writable, non-configurable property '%' "  \
    "to be non-writable is deprecated")                                        \
317 318
  T(StrongSetProto,                                                            \
    "On strong object %, redefining the internal prototype is deprecated")     \
319
  T(SymbolKeyFor, "% is not a symbol")                                         \
320 321
  T(SymbolToNumber, "Cannot convert a Symbol value to a number")               \
  T(SymbolToString, "Cannot convert a Symbol value to a string")               \
322
  T(SimdToNumber, "Cannot convert a SIMD value to a number")                   \
323 324
  T(UndefinedOrNullToObject, "Cannot convert undefined or null to object")     \
  T(ValueAndAccessor,                                                          \
325 326
    "Invalid property descriptor. Cannot both specify accessors and a value "  \
    "or writable attribute, %")                                                \
327
  T(VarRedeclaration, "Identifier '%' has already been declared")              \
328
  T(WrongArgs, "%: Arguments list has wrong type")                             \
329 330 331
  /* ReferenceError */                                                         \
  T(NonMethod, "'super' is referenced from non-method")                        \
  T(NotDefined, "% is not defined")                                            \
332 333 334 335 336
  T(StrongSuperCallMissing,                                                    \
    "In strong mode, invoking the super constructor in a subclass is "         \
    "required")                                                                \
  T(StrongUnboundGlobal,                                                       \
    "In strong mode, using an undeclared global variable '%' is not allowed")  \
337
  T(UnsupportedSuper, "Unsupported reference to 'super'")                      \
338
  /* RangeError */                                                             \
339
  T(DateRange, "Provided date is not in valid range.")                         \
jshin's avatar
jshin committed
340 341 342 343 344
  T(ExpectedTimezoneID,                                                        \
    "Expected Area/Location(/Location)* for time zone, got %")                 \
  T(ExpectedLocation,                                                          \
    "Expected letters optionally connected with underscores or hyphens for "   \
    "a location, got %")                                                       \
345
  T(InvalidArrayBufferLength, "Invalid array buffer length")                   \
346
  T(ArrayBufferAllocationFailed, "Array buffer allocation failed")             \
347
  T(InvalidArrayLength, "Invalid array length")                                \
348 349
  T(InvalidCodePoint, "Invalid code point %")                                  \
  T(InvalidCountValue, "Invalid count value")                                  \
350
  T(InvalidCurrencyCode, "Invalid currency code: %")                           \
351 352 353 354
  T(InvalidDataViewAccessorOffset,                                             \
    "Offset is outside the bounds of the DataView")                            \
  T(InvalidDataViewLength, "Invalid data view length")                         \
  T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \
355
  T(InvalidHint, "Invalid hint: %")                                            \
356
  T(InvalidLanguageTag, "Invalid language tag: %")                             \
357 358
  T(InvalidWeakMapKey, "Invalid value used as weak map key")                   \
  T(InvalidWeakSetValue, "Invalid value used in weak set")                     \
359
  T(InvalidStringLength, "Invalid string length")                              \
360
  T(InvalidTimeValue, "Invalid time value")                                    \
361 362 363
  T(InvalidTypedArrayAlignment, "% of % should be a multiple of %")            \
  T(InvalidTypedArrayLength, "Invalid typed array length")                     \
  T(InvalidTypedArrayOffset, "Start offset is too large:")                     \
364
  T(LetInLexicalBinding, "let is disallowed as a lexically bound name")        \
365 366
  T(LocaleMatcher, "Illegal value for localeMatcher:%")                        \
  T(NormalizationForm, "The normalization form should be one of %.")           \
367
  T(NumberFormatRange, "% argument must be between 0 and 20")                  \
368
  T(PropertyValueOutOfRange, "% value is out of range.")                       \
369 370
  T(StackOverflow, "Maximum call stack size exceeded")                         \
  T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
371
  T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36")  \
372 373
  T(TypedArraySetNegativeOffset, "Start offset is negative")                   \
  T(TypedArraySetSourceTooLarge, "Source is too large")                        \
374 375
  T(UnsupportedTimeZone, "Unsupported time zone specified %")                  \
  T(ValueOutOfRange, "Value % out of range for % options property %")          \
376
  /* SyntaxError */                                                            \
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
  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")        \
  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")           \
  T(ForInLoopInitializer,                                                      \
    "for-in loop variable declaration may not have an initializer.")           \
  T(ForInOfLoopMultiBindings,                                                  \
    "Invalid left-hand side in % loop: Must have a single binding.")           \
  T(ForOfLoopInitializer,                                                      \
    "for-of loop variable declaration may not have an initializer.")           \
  T(IllegalAccess, "Illegal access")                                           \
  T(IllegalBreak, "Illegal break statement")                                   \
  T(IllegalContinue, "Illegal continue statement")                             \
396 397
  T(IllegalLanguageModeDirective,                                              \
    "Illegal '%' directive in function with non-simple parameter list")        \
398
  T(IllegalReturn, "Illegal return statement")                                 \
399
  T(InvalidEscapedReservedWord, "Keyword must not contain escaped characters") \
400
  T(InvalidLhsInAssignment, "Invalid left-hand side in assignment")            \
401 402
  T(InvalidCoverInitializedName, "Invalid shorthand property initializer")     \
  T(InvalidDestructuringTarget, "Invalid destructuring assignment target")     \
403 404 405 406 407
  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")                   \
408
  T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'")    \
409 410
  T(LabelRedeclaration, "Label '%' has already been declared")                 \
  T(MalformedArrowFunParamList, "Malformed arrow function parameter list")     \
411
  T(MalformedRegExp, "Invalid regular expression: /%/: %")                     \
412 413 414 415 416 417 418 419
  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")            \
420 421 422
  T(PushPastSafeLength,                                                        \
    "Pushing % elements on an array-like of length % "                         \
    "is disallowed, as the total surpasses 2**53-1")                           \
423
  T(ElementAfterRest, "Rest element must be last element in array")            \
424 425
  T(BadSetterRestParameter,                                                    \
    "Setter function argument must not be a rest parameter")                   \
426
  T(ParamDupe, "Duplicate parameter name not allowed in this context")         \
427
  T(ParenthesisInArgString, "Function arg string contains parenthesis")        \
428 429 430 431
  T(SingleFunctionLiteral, "Single function literal required")                 \
  T(SloppyLexical,                                                             \
    "Block-scoped declarations (let, const, function, class) not yet "         \
    "supported outside strict mode")                                           \
432 433
  T(SpeciesNotConstructor,                                                     \
    "object.constructor[Symbol.species] is not a constructor")                 \
434 435 436 437 438 439 440 441 442
  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 "     \
    "immediately within another function.")                                    \
  T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.")      \
  T(StrictWith, "Strict mode code may not include a with statement")           \
  T(StrongArguments,                                                           \
    "In strong mode, 'arguments' is deprecated, use '...args' instead")        \
443 444
  T(StrongConstructorDirective,                                                \
    "\"use strong\" directive is disallowed in class constructor body")        \
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
  T(StrongConstructorReturnMisplaced,                                          \
    "In strong mode, returning from a constructor before its super "           \
    "constructor invocation or all assignments to 'this' is deprecated")       \
  T(StrongConstructorReturnValue,                                              \
    "In strong mode, returning a value from a constructor is deprecated")      \
  T(StrongConstructorSuper,                                                    \
    "In strong mode, 'super' can only be used to invoke the super "            \
    "constructor, and cannot be nested inside another statement or "           \
    "expression")                                                              \
  T(StrongConstructorThis,                                                     \
    "In strong mode, 'this' can only be used to initialize properties, and "   \
    "cannot be nested inside another statement or expression")                 \
  T(StrongDelete,                                                              \
    "In strong mode, 'delete' is deprecated, use maps or sets instead")        \
  T(StrongDirectEval, "In strong mode, direct calls to eval are deprecated")   \
  T(StrongEllision,                                                            \
    "In strong mode, arrays with holes are deprecated, use maps instead")      \
  T(StrongEmpty,                                                               \
    "In strong mode, empty sub-statements are deprecated, make them explicit " \
    "with '{}' instead")                                                       \
  T(StrongEqual,                                                               \
    "In strong mode, '==' and '!=' are deprecated, use '===' and '!==' "       \
    "instead")                                                                 \
  T(StrongForIn,                                                               \
    "In strong mode, 'for'-'in' loops are deprecated, use 'for'-'of' instead") \
470 471
  T(StrongPropertyAccess,                                                      \
    "In strong mode, accessing missing property '%' of % is deprecated")       \
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
  T(StrongSuperCallDuplicate,                                                  \
    "In strong mode, invoking the super constructor multiple times is "        \
    "deprecated")                                                              \
  T(StrongSuperCallMisplaced,                                                  \
    "In strong mode, the super constructor must be invoked before any "        \
    "assignment to 'this'")                                                    \
  T(StrongSwitchFallthrough,                                                   \
    "In strong mode, switch fall-through is deprecated, terminate each case "  \
    "with 'break', 'continue', 'return' or 'throw'")                           \
  T(StrongUndefined,                                                           \
    "In strong mode, binding or assigning to 'undefined' is deprecated")       \
  T(StrongUseBeforeDeclaration,                                                \
    "In strong mode, declaring variable '%' before its use is required")       \
  T(StrongVar,                                                                 \
    "In strong mode, 'var' is deprecated, use 'let' or 'const' instead")       \
  T(TemplateOctalLiteral,                                                      \
    "Octal literals are not allowed in template strings.")                     \
  T(ThisFormalParameter, "'this' is not a valid formal parameter name")        \
  T(TooManyArguments,                                                          \
    "Too many arguments in function call (only 65535 allowed)")                \
  T(TooManyParameters,                                                         \
    "Too many parameters in function definition (only 65535 allowed)")         \
  T(TooManyVariables, "Too many variables declared (only 4194303 allowed)")    \
495 496
  T(TypedArrayTooShort,                                                        \
    "Derived TypedArray constructor created an array which was too small")     \
497
  T(UnexpectedEOS, "Unexpected end of input")                                  \
498 499 500
  T(UnexpectedReserved, "Unexpected reserved word")                            \
  T(UnexpectedStrictReserved, "Unexpected strict mode reserved word")          \
  T(UnexpectedSuper, "'super' keyword unexpected here")                        \
501
  T(UnexpectedNewTarget, "new.target expression is not allowed here")          \
502
  T(UnexpectedTemplateString, "Unexpected template string")                    \
503
  T(UnexpectedToken, "Unexpected token %")                                     \
504
  T(UnexpectedTokenIdentifier, "Unexpected identifier")                        \
505 506
  T(UnexpectedTokenNumber, "Unexpected number")                                \
  T(UnexpectedTokenString, "Unexpected string")                                \
507
  T(UnexpectedTokenRegExp, "Unexpected regular expression")                    \
508 509 510 511 512
  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")              \
513
  /* EvalError */                                                              \
514 515 516
  T(CodeGenFromStrings, "%")                                                   \
  /* URIError */                                                               \
  T(URIMalformed, "URI malformed")
517 518 519 520 521 522 523 524 525 526

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

527 528
  static const char* TemplateString(int template_index);

529 530 531 532
  static MaybeHandle<String> FormatMessage(int template_index,
                                           Handle<String> arg0,
                                           Handle<String> arg1,
                                           Handle<String> arg2);
533 534 535 536 537 538 539 540 541 542 543 544

  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(
545 546 547
      Isolate* isolate, MessageTemplate::Template type,
      MessageLocation* location, Handle<Object> argument,
      Handle<JSArray> stack_frames);
548 549 550

  // Report a formatted message (needs JS allocation).
  static void ReportMessage(Isolate* isolate, MessageLocation* loc,
551
                            Handle<JSMessageObject> message);
552 553 554 555

  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
556 557
  static base::SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
                                                           Handle<Object> data);
558
};
559 560


561 562
}  // namespace internal
}  // namespace v8
563 564

#endif  // V8_MESSAGES_H_