messages.h 38.7 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
#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
  T(CalledNonCallable, "% is not a function")                                  \
97
  T(CalledNonCallableInstanceOf, "right-hand side is not a function")          \
98
  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
  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")                                \
241
  T(ProxyHandlerOrTargetRevoked,                                               \
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
    "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")                                                           \
262
  T(ProxyPrivate, "Cannot pass private property name to proxy trap")           \
263
  T(ProxyRevoked, "Cannot perform '%' on a proxy that has been revoked")       \
264 265 266 267 268 269 270 271 272 273 274 275 276 277
  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 '%'")                    \
278
  T(ReadGlobalReferenceThroughProxy, "Trying to access '%' through proxy")     \
279
  T(RedefineDisallowed, "Cannot redefine property: %")                         \
280 281
  T(RedefineExternalArray,                                                     \
    "Cannot redefine a property of an object with external array elements")    \
282
  T(ReduceNoInitial, "Reduce of empty array with no initial value")            \
283 284
  T(RegExpFlags,                                                               \
    "Cannot supply flags when constructing one RegExp from another")           \
285 286
  T(RegExpNonObject, "% getter called on non-object %")                        \
  T(RegExpNonRegExp, "% getter called on non-RegExp object")                   \
287 288 289 290
  T(ReinitializeIntl, "Trying to re-initialize % object.")                     \
  T(ResolvedOptionsCalledOnNonObject,                                          \
    "resolvedOptions method called on a non-object or on a object that is "    \
    "not Intl.%.")                                                             \
291
  T(ResolverNotAFunction, "Promise resolver % is not a function")              \
292 293 294
  T(RestrictedFunctionProperties,                                              \
    "'caller' and 'arguments' are restricted function properties and cannot "  \
    "be accessed in this context.")                                            \
295
  T(ReturnMethodNotCallable, "The iterator's 'return' method is not callable") \
296
  T(StaticPrototype, "Classes may not have static property named prototype")   \
297
  T(StrictCannotAssign, "Cannot assign to read only '%' in strict mode")       \
298 299 300 301
  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")        \
302 303 304
  T(StrictReadOnlyProperty,                                                    \
    "Cannot assign to read only property '%' of % '%'")                        \
  T(StrictCannotCreateProperty, "Cannot create property '%' on % '%'")         \
305 306
  T(StrongArity,                                                               \
    "In strong mode, calling a function with too few arguments is deprecated") \
307 308
  T(StrongImplicitConversion,                                                  \
    "In strong mode, implicit conversions are deprecated")                     \
neis's avatar
neis committed
309 310
  T(SymbolIteratorInvalid,                                                     \
    "Result of the Symbol.iterator method is not an object")                   \
311
  T(SymbolKeyFor, "% is not a symbol")                                         \
312 313
  T(SymbolToNumber, "Cannot convert a Symbol value to a number")               \
  T(SymbolToString, "Cannot convert a Symbol value to a string")               \
314
  T(SimdToNumber, "Cannot convert a SIMD value to a number")                   \
neis's avatar
neis committed
315
  T(ThrowMethodMissing, "The iterator does not provide a 'throw' method.")     \
316 317
  T(UndefinedOrNullToObject, "Cannot convert undefined or null to object")     \
  T(ValueAndAccessor,                                                          \
318 319
    "Invalid property descriptor. Cannot both specify accessors and a value "  \
    "or writable attribute, %")                                                \
320
  T(VarRedeclaration, "Identifier '%' has already been declared")              \
321
  T(WrongArgs, "%: Arguments list has wrong type")                             \
322 323 324
  /* ReferenceError */                                                         \
  T(NonMethod, "'super' is referenced from non-method")                        \
  T(NotDefined, "% is not defined")                                            \
325 326 327
  T(StrongSuperCallMissing,                                                    \
    "In strong mode, invoking the super constructor in a subclass is "         \
    "required")                                                                \
328
  T(UnsupportedSuper, "Unsupported reference to 'super'")                      \
329
  /* RangeError */                                                             \
330
  T(DateRange, "Provided date is not in valid range.")                         \
jshin's avatar
jshin committed
331 332 333 334 335
  T(ExpectedTimezoneID,                                                        \
    "Expected Area/Location(/Location)* for time zone, got %")                 \
  T(ExpectedLocation,                                                          \
    "Expected letters optionally connected with underscores or hyphens for "   \
    "a location, got %")                                                       \
336
  T(InvalidArrayBufferLength, "Invalid array buffer length")                   \
337
  T(ArrayBufferAllocationFailed, "Array buffer allocation failed")             \
338
  T(InvalidArrayLength, "Invalid array length")                                \
339 340
  T(InvalidCodePoint, "Invalid code point %")                                  \
  T(InvalidCountValue, "Invalid count value")                                  \
341
  T(InvalidCurrencyCode, "Invalid currency code: %")                           \
342 343 344 345
  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") \
346
  T(InvalidHint, "Invalid hint: %")                                            \
347
  T(InvalidLanguageTag, "Invalid language tag: %")                             \
348 349
  T(InvalidWeakMapKey, "Invalid value used as weak map key")                   \
  T(InvalidWeakSetValue, "Invalid value used in weak set")                     \
350
  T(InvalidStringLength, "Invalid string length")                              \
351
  T(InvalidTimeValue, "Invalid time value")                                    \
352 353 354
  T(InvalidTypedArrayAlignment, "% of % should be a multiple of %")            \
  T(InvalidTypedArrayLength, "Invalid typed array length")                     \
  T(InvalidTypedArrayOffset, "Start offset is too large:")                     \
355
  T(LetInLexicalBinding, "let is disallowed as a lexically bound name")        \
356 357
  T(LocaleMatcher, "Illegal value for localeMatcher:%")                        \
  T(NormalizationForm, "The normalization form should be one of %.")           \
358
  T(NumberFormatRange, "% argument must be between 0 and 20")                  \
359
  T(PropertyValueOutOfRange, "% value is out of range.")                       \
360 361
  T(StackOverflow, "Maximum call stack size exceeded")                         \
  T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
362
  T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36")  \
363 364
  T(TypedArraySetNegativeOffset, "Start offset is negative")                   \
  T(TypedArraySetSourceTooLarge, "Source is too large")                        \
365 366
  T(UnsupportedTimeZone, "Unsupported time zone specified %")                  \
  T(ValueOutOfRange, "Value % out of range for % options property %")          \
367
  /* SyntaxError */                                                            \
368 369 370 371 372 373 374 375 376 377
  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")           \
378 379
  T(ForInOfLoopInitializer,                                                    \
    "% loop variable declaration may not have an initializer.")                \
380 381 382 383
  T(ForInOfLoopMultiBindings,                                                  \
    "Invalid left-hand side in % loop: Must have a single binding.")           \
  T(IllegalBreak, "Illegal break statement")                                   \
  T(IllegalContinue, "Illegal continue statement")                             \
384 385
  T(IllegalLanguageModeDirective,                                              \
    "Illegal '%' directive in function with non-simple parameter list")        \
386
  T(IllegalReturn, "Illegal return statement")                                 \
387
  T(InvalidEscapedReservedWord, "Keyword must not contain escaped characters") \
388
  T(InvalidEscapedMetaProperty, "'%' must not contain escaped characters")     \
389
  T(InvalidLhsInAssignment, "Invalid left-hand side in assignment")            \
390 391
  T(InvalidCoverInitializedName, "Invalid shorthand property initializer")     \
  T(InvalidDestructuringTarget, "Invalid destructuring assignment target")     \
392 393 394 395 396
  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")                   \
397
  T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'")    \
398
  T(InvalidOrUnexpectedToken, "Invalid or unexpected token")                   \
399 400 401 402
  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 %") \
403 404
  T(LabelRedeclaration, "Label '%' has already been declared")                 \
  T(MalformedArrowFunParamList, "Malformed arrow function parameter list")     \
405
  T(MalformedRegExp, "Invalid regular expression: /%/: %")                     \
406 407 408 409 410 411 412 413
  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")            \
414 415
  T(InvalidRestParameter,                                                      \
    "Rest parameter must be an identifier or destructuring pattern")           \
416 417 418
  T(PushPastSafeLength,                                                        \
    "Pushing % elements on an array-like of length % "                         \
    "is disallowed, as the total surpasses 2**53-1")                           \
419
  T(ElementAfterRest, "Rest element must be last element in array")            \
420 421
  T(BadSetterRestParameter,                                                    \
    "Setter function argument must not be a rest parameter")                   \
422
  T(ParamDupe, "Duplicate parameter name not allowed in this context")         \
423
  T(ParenthesisInArgString, "Function arg string contains parenthesis")        \
424
  T(RuntimeWrongNumArgs, "Runtime function given wrong number of arguments")   \
425
  T(SingleFunctionLiteral, "Single function literal required")                 \
426 427 428
  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.")                      \
429 430 431
  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
  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 "     \
438
    "inside a block.")                                                         \
439 440 441 442
  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
  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(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)")    \
493 494
  T(TypedArrayTooShort,                                                        \
    "Derived TypedArray constructor created an array which was too small")     \
495
  T(UnexpectedEOS, "Unexpected end of input")                                  \
496 497
  T(UnexpectedFunctionSent,                                                    \
    "function.sent expression is not allowed outside a generator")             \
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 514
  T(FoundNonCallableHasInstance, "Found non-callable @@hasInstance")           \
  T(NonObjectInInstanceOfCheck, "Expecting an object in instanceof check")     \
515
  /* EvalError */                                                              \
516 517 518
  T(CodeGenFromStrings, "%")                                                   \
  /* URIError */                                                               \
  T(URIMalformed, "URI malformed")
519 520 521 522 523 524 525 526 527 528

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

529 530
  static const char* TemplateString(int template_index);

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

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

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

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


563 564
}  // namespace internal
}  // namespace v8
565 566

#endif  // V8_MESSAGES_H_