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