blob: c71e11ba24dd99bb2225576cd8a2e6443a25bd99 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5// The infrastructure used for (localized) message reporting in V8.
6//
7// Note: there's a big unresolved issue about ownership of the data
8// structures used by this framework.
9
10#ifndef V8_MESSAGES_H_
11#define V8_MESSAGES_H_
12
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013#include "src/base/smart-pointers.h"
14#include "src/handles.h"
15#include "src/list.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000016
17namespace v8 {
18namespace internal {
19
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000020// Forward declarations.
21class JSMessageObject;
22class LookupIterator;
Steve Blocka7e24c12009-10-30 11:49:00 +000023class SourceInfo;
24
25class MessageLocation {
26 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027 MessageLocation(Handle<Script> script, int start_pos, int end_pos,
28 Handle<JSFunction> function = Handle<JSFunction>())
Steve Blocka7e24c12009-10-30 11:49:00 +000029 : script_(script),
30 start_pos_(start_pos),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000031 end_pos_(end_pos),
32 function_(function) {}
Steve Blocka7e24c12009-10-30 11:49:00 +000033 MessageLocation() : start_pos_(-1), end_pos_(-1) { }
34
35 Handle<Script> script() const { return script_; }
36 int start_pos() const { return start_pos_; }
37 int end_pos() const { return end_pos_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038 Handle<JSFunction> function() const { return function_; }
Steve Blocka7e24c12009-10-30 11:49:00 +000039
40 private:
41 Handle<Script> script_;
42 int start_pos_;
43 int end_pos_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000044 Handle<JSFunction> function_;
45};
46
47
48class CallSite {
49 public:
50 CallSite(Isolate* isolate, Handle<JSObject> call_site_obj);
51
52 Handle<Object> GetFileName();
53 Handle<Object> GetFunctionName();
54 Handle<Object> GetScriptNameOrSourceUrl();
55 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 int GetColumnNumber();
60 bool IsNative();
61 bool IsToplevel();
62 bool IsEval();
63 bool IsConstructor();
64
65 bool IsValid() { return !fun_.is_null(); }
66
67 private:
68 Isolate* isolate_;
69 Handle<Object> receiver_;
70 Handle<JSFunction> fun_;
71 int32_t pos_;
72};
73
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000074#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") \
Ben Murdoch097c5b22016-05-18 11:27:45 +010097 T(CalledNonCallableInstanceOf, "right-hand side is not a function") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000098 T(CalledOnNonObject, "% called on non-object") \
99 T(CalledOnNullOrUndefined, "% called on null or undefined") \
100 T(CallSiteExpectsFunction, \
101 "CallSite expects function as second argument, got %") \
102 T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
103 T(CannotPreventExt, "Cannot prevent extensions") \
104 T(CannotFreezeArrayBufferView, \
105 "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 T(DataViewNotArrayBuffer, \
115 "First argument to DataView constructor must be an ArrayBuffer") \
116 T(DateType, "this is not a Date object.") \
117 T(DebuggerFrame, "Debugger: Invalid frame index.") \
118 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 T(DuplicateTemplateProperty, "Object template has duplicate property '%'") \
122 T(ExtendsValueGenerator, \
123 "Class extends value % may not be a generator function") \
124 T(ExtendsValueNotFunction, \
125 "Class extends value % is not a function 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(InstanceofFunctionExpected, \
133 "Expecting a function in instanceof check, but got %") \
134 T(InstanceofNonobjectProto, \
135 "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 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(NonCoercible, "Cannot match against 'undefined' or 'null'.") \
149 T(NonExtensibleProto, "% is not extensible") \
150 T(NonObjectPropertyLoad, "Cannot read property '%' of %") \
151 T(NonObjectPropertyStore, "Cannot set property '%' of %") \
152 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 T(NotDateObject, "this is not a Date object.") \
157 T(NotIntlObject, "% is not an i18n object.") \
158 T(NotGeneric, "% is not generic") \
159 T(NotIterable, "% is not iterable") \
160 T(NotPropertyName, "% is not a valid property name") \
161 T(NotTypedArray, "this is not a typed array.") \
162 T(NotSharedTypedArray, "% is not a shared typed array.") \
163 T(NotIntegerSharedTypedArray, "% is not an integer shared typed array.") \
164 T(NotInt32SharedTypedArray, "% is not an int32 shared typed array.") \
165 T(ObjectGetterExpectingFunction, \
166 "Object.prototype.__defineGetter__: Expecting function") \
167 T(ObjectGetterCallable, "Getter must be a function: %") \
168 T(ObjectNotExtensible, "Can't add property %, object is not extensible") \
169 T(ObjectSetterExpectingFunction, \
170 "Object.prototype.__defineSetter__: Expecting function") \
171 T(ObjectSetterCallable, "Setter must be a function: %") \
172 T(ObserveCallbackFrozen, \
173 "Object.observe cannot deliver to a frozen function object") \
174 T(ObserveGlobalProxy, "% cannot be called on the global proxy object") \
175 T(ObserveAccessChecked, "% cannot be called on access-checked objects") \
176 T(ObserveInvalidAccept, \
177 "Third argument to Object.observe must be an array of strings.") \
178 T(ObserveNonFunction, "Object.% cannot deliver to non-function") \
179 T(ObserveNonObject, "Object.% cannot % non-object") \
180 T(ObserveNotifyNonNotifier, "notify called on non-notifier object") \
181 T(ObservePerformNonFunction, "Cannot perform non-function") \
182 T(ObservePerformNonString, "Invalid non-string changeType") \
183 T(ObserveTypeNonString, \
184 "Invalid changeRecord with non-string 'type' property") \
185 T(OrdinaryFunctionCalledAsConstructor, \
186 "Function object that's not a constructor was created with new") \
187 T(PromiseCyclic, "Chaining cycle detected for promise %") \
188 T(PromiseExecutorAlreadyInvoked, \
189 "Promise executor has already been invoked with non-undefined arguments") \
190 T(PropertyDescObject, "Property description must be an object: %") \
191 T(PropertyNotFunction, \
192 "'%' returned for property '%' of object '%' is not a function") \
193 T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %") \
194 T(PrototypeParentNotAnObject, \
195 "Class extends value does not have valid prototype property %") \
196 T(ProxyConstructNonObject, \
197 "'construct' on proxy: trap returned non-object ('%')") \
198 T(ProxyDefinePropertyNonConfigurable, \
199 "'defineProperty' on proxy: trap returned truish for defining " \
200 "non-configurable property '%' which is either non-existant or " \
201 "configurable in the proxy target") \
202 T(ProxyDefinePropertyNonExtensible, \
203 "'defineProperty' on proxy: trap returned truish for adding property '%' " \
204 " to the non-extensible proxy target") \
205 T(ProxyDefinePropertyIncompatible, \
206 "'defineProperty' on proxy: trap returned truish for adding property '%' " \
207 " that is incompatible with the existing property in the proxy target") \
208 T(ProxyDeletePropertyNonConfigurable, \
209 "'deleteProperty' on proxy: trap returned truish for property '%' which " \
210 "is non-configurable in the proxy target") \
211 T(ProxyEnumerateNonObject, "'enumerate' on proxy: trap returned non-object") \
212 T(ProxyEnumerateNonString, \
213 "'enumerate' on proxy: trap result includes non-string") \
214 T(ProxyGetNonConfigurableData, \
215 "'get' on proxy: property '%' is a read-only and " \
216 "non-configurable data property on the proxy target but the proxy " \
217 "did not return its actual value (expected '%' but got '%')") \
218 T(ProxyGetNonConfigurableAccessor, \
219 "'get' on proxy: property '%' is a non-configurable accessor " \
220 "property on the proxy target and does not have a getter function, but " \
221 "the trap did not return 'undefined' (got '%')") \
222 T(ProxyGetOwnPropertyDescriptorIncompatible, \
223 "'getOwnPropertyDescriptor' on proxy: trap returned descriptor for " \
224 "property '%' that is incompatible with the existing property in the " \
225 "proxy target") \
226 T(ProxyGetOwnPropertyDescriptorInvalid, \
227 "'getOwnPropertyDescriptor' on proxy: trap returned neither object nor " \
228 "undefined for property '%'") \
229 T(ProxyGetOwnPropertyDescriptorNonConfigurable, \
230 "'getOwnPropertyDescriptor' on proxy: trap reported non-configurability " \
231 "for property '%' which is either non-existant or configurable in the " \
232 "proxy target") \
233 T(ProxyGetOwnPropertyDescriptorNonExtensible, \
234 "'getOwnPropertyDescriptor' on proxy: trap returned undefined for " \
235 "property '%' which exists in the non-extensible proxy target") \
236 T(ProxyGetOwnPropertyDescriptorUndefined, \
237 "'getOwnPropertyDescriptor' on proxy: trap returned undefined for " \
238 "property '%' which is non-configurable in the proxy target") \
239 T(ProxyGetPrototypeOfInvalid, \
240 "'getPrototypeOf' on proxy: trap returned neither object nor null") \
241 T(ProxyGetPrototypeOfNonExtensible, \
242 "'getPrototypeOf' on proxy: proxy target is non-extensible but the " \
243 "trap did not return its actual prototype") \
244 T(ProxyHandlerOrTargetRevoked, \
245 "Cannot create proxy with a revoked proxy as target or handler") \
246 T(ProxyHasNonConfigurable, \
247 "'has' on proxy: trap returned falsish for property '%' which exists in " \
248 "the proxy target as non-configurable") \
249 T(ProxyHasNonExtensible, \
250 "'has' on proxy: trap returned falsish for property '%' but the proxy " \
251 "target is not extensible") \
252 T(ProxyIsExtensibleInconsistent, \
253 "'isExtensible' on proxy: trap result does not reflect extensibility of " \
254 "proxy target (which is '%')") \
255 T(ProxyNonObject, \
256 "Cannot create proxy with a non-object as target or handler") \
257 T(ProxyOwnKeysMissing, \
258 "'ownKeys' on proxy: trap result did not include '%'") \
259 T(ProxyOwnKeysNonExtensible, \
260 "'ownKeys' on proxy: trap returned extra keys but proxy target is " \
261 "non-extensible") \
262 T(ProxyPreventExtensionsExtensible, \
263 "'preventExtensions' on proxy: trap returned truish but the proxy target " \
264 "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 T(ProxySetFrozenData, \
268 "'set' on proxy: trap returned truish for property '%' which exists in " \
269 "the proxy target as a non-configurable and non-writable data property " \
270 "with a different value") \
271 T(ProxySetFrozenAccessor, \
272 "'set' on proxy: trap returned truish for property '%' which exists in " \
273 "the proxy target as a non-configurable and non-writable accessor " \
274 "property without a setter") \
275 T(ProxySetPrototypeOfNonExtensible, \
276 "'setPrototypeOf' on proxy: trap returned truish for setting a new " \
277 "prototype on the non-extensible proxy target") \
278 T(ProxyTrapReturnedFalsish, "'%' on proxy: trap returned falsish") \
279 T(ProxyTrapReturnedFalsishFor, \
280 "'%' on proxy: trap returned falsish for property '%'") \
281 T(ReadGlobalReferenceThroughProxy, "Trying to access '%' through proxy") \
282 T(RedefineDisallowed, "Cannot redefine property: %") \
283 T(RedefineExternalArray, \
284 "Cannot redefine a property of an object with external array elements") \
285 T(ReduceNoInitial, "Reduce of empty array with no initial value") \
286 T(RegExpFlags, \
287 "Cannot supply flags when constructing one RegExp from another") \
288 T(RegExpNonObject, "% getter called on non-object %") \
289 T(RegExpNonRegExp, "% getter called on non-RegExp object") \
290 T(ReinitializeIntl, "Trying to re-initialize % object.") \
291 T(ResolvedOptionsCalledOnNonObject, \
292 "resolvedOptions method called on a non-object or on a object that is " \
293 "not Intl.%.") \
294 T(ResolverNotAFunction, "Promise resolver % is not a function") \
295 T(RestrictedFunctionProperties, \
296 "'caller' and 'arguments' are restricted function properties and cannot " \
297 "be accessed in this context.") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100298 T(ReturnMethodNotCallable, "The iterator's 'return' method is not callable") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000299 T(StaticPrototype, "Classes may not have static property named prototype") \
300 T(StrictCannotAssign, "Cannot assign to read only '%' in strict mode") \
301 T(StrictDeleteProperty, "Cannot delete property '%' of %") \
302 T(StrictPoisonPill, \
303 "'caller', 'callee', and 'arguments' properties may not be accessed on " \
304 "strict mode functions or the arguments objects for calls to them") \
305 T(StrictReadOnlyProperty, \
306 "Cannot assign to read only property '%' of % '%'") \
307 T(StrictCannotCreateProperty, "Cannot create property '%' on % '%'") \
308 T(StrongArity, \
309 "In strong mode, calling a function with too few arguments is deprecated") \
310 T(StrongDeleteProperty, \
311 "Deleting property '%' of strong object '%' is deprecated") \
312 T(StrongExtendNull, "In strong mode, classes extending null are deprecated") \
313 T(StrongImplicitConversion, \
314 "In strong mode, implicit conversions are deprecated") \
315 T(StrongRedefineDisallowed, \
316 "On strong object %, redefining writable, non-configurable property '%' " \
317 "to be non-writable is deprecated") \
318 T(StrongSetProto, \
319 "On strong object %, redefining the internal prototype is deprecated") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100320 T(SymbolIteratorInvalid, \
321 "Result of the Symbol.iterator method is not an object") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000322 T(SymbolKeyFor, "% is not a symbol") \
323 T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
324 T(SymbolToString, "Cannot convert a Symbol value to a string") \
325 T(SimdToNumber, "Cannot convert a SIMD value to a number") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100326 T(ThrowMethodMissing, "The iterator does not provide a 'throw' method.") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000327 T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \
328 T(ValueAndAccessor, \
329 "Invalid property descriptor. Cannot both specify accessors and a value " \
330 "or writable attribute, %") \
331 T(VarRedeclaration, "Identifier '%' has already been declared") \
332 T(WrongArgs, "%: Arguments list has wrong type") \
333 /* ReferenceError */ \
334 T(NonMethod, "'super' is referenced from non-method") \
335 T(NotDefined, "% is not defined") \
336 T(StrongSuperCallMissing, \
337 "In strong mode, invoking the super constructor in a subclass is " \
338 "required") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000339 T(UnsupportedSuper, "Unsupported reference to 'super'") \
340 /* RangeError */ \
341 T(DateRange, "Provided date is not in valid range.") \
342 T(ExpectedTimezoneID, \
343 "Expected Area/Location(/Location)* for time zone, got %") \
344 T(ExpectedLocation, \
345 "Expected letters optionally connected with underscores or hyphens for " \
346 "a location, got %") \
347 T(InvalidArrayBufferLength, "Invalid array buffer length") \
348 T(ArrayBufferAllocationFailed, "Array buffer allocation failed") \
349 T(InvalidArrayLength, "Invalid array length") \
350 T(InvalidCodePoint, "Invalid code point %") \
351 T(InvalidCountValue, "Invalid count value") \
352 T(InvalidCurrencyCode, "Invalid currency code: %") \
353 T(InvalidDataViewAccessorOffset, \
354 "Offset is outside the bounds of the DataView") \
355 T(InvalidDataViewLength, "Invalid data view length") \
356 T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \
357 T(InvalidHint, "Invalid hint: %") \
358 T(InvalidLanguageTag, "Invalid language tag: %") \
359 T(InvalidWeakMapKey, "Invalid value used as weak map key") \
360 T(InvalidWeakSetValue, "Invalid value used in weak set") \
361 T(InvalidStringLength, "Invalid string length") \
362 T(InvalidTimeValue, "Invalid time value") \
363 T(InvalidTypedArrayAlignment, "% of % should be a multiple of %") \
364 T(InvalidTypedArrayLength, "Invalid typed array length") \
365 T(InvalidTypedArrayOffset, "Start offset is too large:") \
366 T(LetInLexicalBinding, "let is disallowed as a lexically bound name") \
367 T(LocaleMatcher, "Illegal value for localeMatcher:%") \
368 T(NormalizationForm, "The normalization form should be one of %.") \
369 T(NumberFormatRange, "% argument must be between 0 and 20") \
370 T(PropertyValueOutOfRange, "% value is out of range.") \
371 T(StackOverflow, "Maximum call stack size exceeded") \
372 T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
373 T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \
374 T(TypedArraySetNegativeOffset, "Start offset is negative") \
375 T(TypedArraySetSourceTooLarge, "Source is too large") \
376 T(UnsupportedTimeZone, "Unsupported time zone specified %") \
377 T(ValueOutOfRange, "Value % out of range for % options property %") \
378 /* SyntaxError */ \
379 T(BadGetterArity, "Getter must not have any formal parameters.") \
380 T(BadSetterArity, "Setter must have exactly one formal parameter.") \
381 T(ConstructorIsAccessor, "Class constructor may not be an accessor") \
382 T(ConstructorIsGenerator, "Class constructor may not be a generator") \
383 T(DerivedConstructorReturn, \
384 "Derived constructors may only return object or undefined") \
385 T(DuplicateConstructor, "A class may only have one constructor") \
386 T(DuplicateExport, "Duplicate export of '%'") \
387 T(DuplicateProto, \
388 "Duplicate __proto__ fields are not allowed in object literals") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100389 T(ForInOfLoopInitializer, \
390 "% loop variable declaration may not have an initializer.") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000391 T(ForInOfLoopMultiBindings, \
392 "Invalid left-hand side in % loop: Must have a single binding.") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000393 T(IllegalAccess, "Illegal access") \
394 T(IllegalBreak, "Illegal break statement") \
395 T(IllegalContinue, "Illegal continue statement") \
396 T(IllegalLanguageModeDirective, \
397 "Illegal '%' directive in function with non-simple parameter list") \
398 T(IllegalReturn, "Illegal return statement") \
399 T(InvalidEscapedReservedWord, "Keyword must not contain escaped characters") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100400 T(InvalidEscapedMetaProperty, "'%' must not contain escaped characters") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000401 T(InvalidLhsInAssignment, "Invalid left-hand side in assignment") \
402 T(InvalidCoverInitializedName, "Invalid shorthand property initializer") \
403 T(InvalidDestructuringTarget, "Invalid destructuring assignment target") \
404 T(InvalidLhsInFor, "Invalid left-hand side in for-loop") \
405 T(InvalidLhsInPostfixOp, \
406 "Invalid left-hand side expression in postfix operation") \
407 T(InvalidLhsInPrefixOp, \
408 "Invalid left-hand side expression in prefix operation") \
409 T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100410 T(JsonParseUnexpectedEOS, "Unexpected end of JSON input") \
411 T(JsonParseUnexpectedToken, "Unexpected token % in JSON at position %") \
412 T(JsonParseUnexpectedTokenNumber, "Unexpected number in JSON at position %") \
413 T(JsonParseUnexpectedTokenString, "Unexpected string in JSON at position %") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000414 T(LabelRedeclaration, "Label '%' has already been declared") \
415 T(MalformedArrowFunParamList, "Malformed arrow function parameter list") \
416 T(MalformedRegExp, "Invalid regular expression: /%/: %") \
417 T(MalformedRegExpFlags, "Invalid regular expression flags") \
418 T(ModuleExportUndefined, "Export '%' is not defined in module") \
419 T(MultipleDefaultsInSwitch, \
420 "More than one default clause in switch statement") \
421 T(NewlineAfterThrow, "Illegal newline after throw") \
422 T(NoCatchOrFinally, "Missing catch or finally after try") \
423 T(NotIsvar, "builtin %%IS_VAR: not a variable") \
424 T(ParamAfterRest, "Rest parameter must be last formal parameter") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100425 T(InvalidRestParameter, \
426 "Rest parameter must be an identifier or destructuring pattern") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000427 T(PushPastSafeLength, \
428 "Pushing % elements on an array-like of length % " \
429 "is disallowed, as the total surpasses 2**53-1") \
430 T(ElementAfterRest, "Rest element must be last element in array") \
431 T(BadSetterRestParameter, \
432 "Setter function argument must not be a rest parameter") \
433 T(ParamDupe, "Duplicate parameter name not allowed in this context") \
434 T(ParenthesisInArgString, "Function arg string contains parenthesis") \
435 T(SingleFunctionLiteral, "Single function literal required") \
436 T(SloppyLexical, \
437 "Block-scoped declarations (let, const, function, class) not yet " \
438 "supported outside strict mode") \
439 T(SpeciesNotConstructor, \
440 "object.constructor[Symbol.species] is not a constructor") \
441 T(StrictDelete, "Delete of an unqualified identifier in strict mode.") \
442 T(StrictEvalArguments, "Unexpected eval or arguments in strict mode") \
443 T(StrictFunction, \
444 "In strict mode code, functions can only be declared at top level or " \
445 "immediately within another function.") \
446 T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \
447 T(StrictWith, "Strict mode code may not include a with statement") \
448 T(StrongArguments, \
449 "In strong mode, 'arguments' is deprecated, use '...args' instead") \
450 T(StrongConstructorDirective, \
451 "\"use strong\" directive is disallowed in class constructor body") \
452 T(StrongConstructorReturnMisplaced, \
453 "In strong mode, returning from a constructor before its super " \
454 "constructor invocation or all assignments to 'this' is deprecated") \
455 T(StrongConstructorReturnValue, \
456 "In strong mode, returning a value from a constructor is deprecated") \
457 T(StrongConstructorSuper, \
458 "In strong mode, 'super' can only be used to invoke the super " \
459 "constructor, and cannot be nested inside another statement or " \
460 "expression") \
461 T(StrongConstructorThis, \
462 "In strong mode, 'this' can only be used to initialize properties, and " \
463 "cannot be nested inside another statement or expression") \
464 T(StrongDelete, \
465 "In strong mode, 'delete' is deprecated, use maps or sets instead") \
466 T(StrongDirectEval, "In strong mode, direct calls to eval are deprecated") \
467 T(StrongEllision, \
468 "In strong mode, arrays with holes are deprecated, use maps instead") \
469 T(StrongEmpty, \
470 "In strong mode, empty sub-statements are deprecated, make them explicit " \
471 "with '{}' instead") \
472 T(StrongEqual, \
473 "In strong mode, '==' and '!=' are deprecated, use '===' and '!==' " \
474 "instead") \
475 T(StrongForIn, \
476 "In strong mode, 'for'-'in' loops are deprecated, use 'for'-'of' instead") \
477 T(StrongPropertyAccess, \
478 "In strong mode, accessing missing property '%' of % is deprecated") \
479 T(StrongSuperCallDuplicate, \
480 "In strong mode, invoking the super constructor multiple times is " \
481 "deprecated") \
482 T(StrongSuperCallMisplaced, \
483 "In strong mode, the super constructor must be invoked before any " \
484 "assignment to 'this'") \
485 T(StrongSwitchFallthrough, \
486 "In strong mode, switch fall-through is deprecated, terminate each case " \
487 "with 'break', 'continue', 'return' or 'throw'") \
488 T(StrongUndefined, \
489 "In strong mode, binding or assigning to 'undefined' is deprecated") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000490 T(StrongVar, \
491 "In strong mode, 'var' is deprecated, use 'let' or 'const' instead") \
492 T(TemplateOctalLiteral, \
493 "Octal literals are not allowed in template strings.") \
494 T(ThisFormalParameter, "'this' is not a valid formal parameter name") \
495 T(TooManyArguments, \
496 "Too many arguments in function call (only 65535 allowed)") \
497 T(TooManyParameters, \
498 "Too many parameters in function definition (only 65535 allowed)") \
499 T(TooManyVariables, "Too many variables declared (only 4194303 allowed)") \
500 T(TypedArrayTooShort, \
501 "Derived TypedArray constructor created an array which was too small") \
502 T(UnexpectedEOS, "Unexpected end of input") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100503 T(UnexpectedFunctionSent, \
504 "function.sent expression is not allowed outside a generator") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000505 T(UnexpectedReserved, "Unexpected reserved word") \
506 T(UnexpectedStrictReserved, "Unexpected strict mode reserved word") \
507 T(UnexpectedSuper, "'super' keyword unexpected here") \
508 T(UnexpectedNewTarget, "new.target expression is not allowed here") \
509 T(UnexpectedTemplateString, "Unexpected template string") \
510 T(UnexpectedToken, "Unexpected token %") \
511 T(UnexpectedTokenIdentifier, "Unexpected identifier") \
512 T(UnexpectedTokenNumber, "Unexpected number") \
513 T(UnexpectedTokenString, "Unexpected string") \
514 T(UnexpectedTokenRegExp, "Unexpected regular expression") \
515 T(UnknownLabel, "Undefined label '%'") \
516 T(UnterminatedArgList, "missing ) after argument list") \
517 T(UnterminatedRegExp, "Invalid regular expression: missing /") \
518 T(UnterminatedTemplate, "Unterminated template literal") \
519 T(UnterminatedTemplateExpr, "Missing } in template expression") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100520 T(FoundNonCallableHasInstance, "Found non-callable @@hasInstance") \
521 T(NonObjectInInstanceOfCheck, "Expecting an object in instanceof check") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000522 /* EvalError */ \
523 T(CodeGenFromStrings, "%") \
524 /* URIError */ \
525 T(URIMalformed, "URI malformed")
526
527class MessageTemplate {
528 public:
529 enum Template {
530#define TEMPLATE(NAME, STRING) k##NAME,
531 MESSAGE_TEMPLATES(TEMPLATE)
532#undef TEMPLATE
533 kLastMessage
534 };
535
536 static const char* TemplateString(int template_index);
537
538 static MaybeHandle<String> FormatMessage(int template_index,
539 Handle<String> arg0,
540 Handle<String> arg1,
541 Handle<String> arg2);
542
543 static Handle<String> FormatMessage(Isolate* isolate, int template_index,
544 Handle<Object> arg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000545};
546
547
548// A message handler is a convenience interface for accessing the list
549// of message listeners registered in an environment
550class MessageHandler {
551 public:
Steve Blocka7e24c12009-10-30 11:49:00 +0000552 // Returns a message object for the API to use.
Steve Block1e0659c2011-05-24 12:43:12 +0100553 static Handle<JSMessageObject> MakeMessageObject(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000554 Isolate* isolate, MessageTemplate::Template type,
555 MessageLocation* location, Handle<Object> argument,
Steve Block1e0659c2011-05-24 12:43:12 +0100556 Handle<JSArray> stack_frames);
Steve Blocka7e24c12009-10-30 11:49:00 +0000557
558 // Report a formatted message (needs JS allocation).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000559 static void ReportMessage(Isolate* isolate, MessageLocation* loc,
560 Handle<JSMessageObject> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000561
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000562 static void DefaultMessageReport(Isolate* isolate, const MessageLocation* loc,
Steve Blocka7e24c12009-10-30 11:49:00 +0000563 Handle<Object> message_obj);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000564 static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000565 static base::SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
566 Handle<Object> data);
Steve Blocka7e24c12009-10-30 11:49:00 +0000567};
568
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000569
570} // namespace internal
571} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000572
573#endif // V8_MESSAGES_H_