blob: a9f321e3cb4c302c4c7ab4a1f611da7449dfc6e9 [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 Murdochc5610432016-08-08 18:44:38 +010027 MessageLocation(Handle<Script> script, int start_pos, int end_pos);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028 MessageLocation(Handle<Script> script, int start_pos, int end_pos,
Ben Murdochc5610432016-08-08 18:44:38 +010029 Handle<JSFunction> function);
30 MessageLocation();
Steve Blocka7e24c12009-10-30 11:49:00 +000031
32 Handle<Script> script() const { return script_; }
33 int start_pos() const { return start_pos_; }
34 int end_pos() const { return end_pos_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035 Handle<JSFunction> function() const { return function_; }
Steve Blocka7e24c12009-10-30 11:49:00 +000036
37 private:
38 Handle<Script> script_;
39 int start_pos_;
40 int end_pos_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000041 Handle<JSFunction> function_;
42};
43
44
45class 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
Ben Murdochc5610432016-08-08 18:44:38 +010062 bool IsJavaScript() { return !fun_.is_null(); }
63 bool IsWasm() { return !wasm_obj_.is_null(); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000064
65 private:
66 Isolate* isolate_;
67 Handle<Object> receiver_;
68 Handle<JSFunction> fun_;
Ben Murdochc5610432016-08-08 18:44:38 +010069 int32_t pos_ = -1;
70 Handle<JSObject> wasm_obj_;
71 uint32_t wasm_func_index_ = static_cast<uint32_t>(-1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000072};
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") \
97 T(CalledOnNonObject, "% called on non-object") \
98 T(CalledOnNullOrUndefined, "% called on null or undefined") \
99 T(CallSiteExpectsFunction, \
Ben Murdochc5610432016-08-08 18:44:38 +0100100 "CallSite expects function or number as second argument, got %") \
Ben Murdochda12d292016-06-02 14:46:10 +0100101 T(CallSiteMethod, "CallSite method % expects CallSite as receiver") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000102 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.") \
Ben Murdochc5610432016-08-08 18:44:38 +0100121 T(DetachedOperation, "Cannot perform % on a detached ArrayBuffer") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000122 T(DuplicateTemplateProperty, "Object template has duplicate property '%'") \
123 T(ExtendsValueGenerator, \
124 "Class extends value % may not be a generator function") \
125 T(ExtendsValueNotFunction, \
126 "Class extends value % is not a function or null") \
127 T(FirstArgumentNotRegExp, \
128 "First argument to % must not be a regular expression") \
129 T(FunctionBind, "Bind must be called on a function") \
130 T(GeneratorRunning, "Generator is already running") \
131 T(IllegalInvocation, "Illegal invocation") \
132 T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000133 T(InstanceofNonobjectProto, \
134 "Function has non-object prototype '%' in instanceof check") \
135 T(InvalidArgument, "invalid_argument") \
136 T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \
Ben Murdochda12d292016-06-02 14:46:10 +0100137 T(InvalidRegExpExecResult, \
138 "RegExp exec method returned something other than an Object or null") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000139 T(InvalidSimdOperation, "% is not a valid type for this SIMD operation.") \
140 T(IteratorResultNotAnObject, "Iterator result % is not an object") \
141 T(IteratorValueNotAnObject, "Iterator value % is not an entry object") \
142 T(LanguageID, "Language ID should be string or object.") \
143 T(MethodCalledOnWrongObject, \
144 "Method % called on a non-object or on a wrong type of object.") \
145 T(MethodInvokedOnNullOrUndefined, \
146 "Method invoked on undefined or null value.") \
147 T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \
148 T(NoAccess, "no access") \
Ben Murdochc5610432016-08-08 18:44:38 +0100149 T(NonCallableInInstanceOfCheck, \
150 "Right-hand side of 'instanceof' is not callable") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000151 T(NonCoercible, "Cannot match against 'undefined' or 'null'.") \
152 T(NonExtensibleProto, "% is not extensible") \
Ben Murdochda12d292016-06-02 14:46:10 +0100153 T(NonObjectInInstanceOfCheck, \
154 "Right-hand side of 'instanceof' is not an object") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000155 T(NonObjectPropertyLoad, "Cannot read property '%' of %") \
156 T(NonObjectPropertyStore, "Cannot set property '%' of %") \
157 T(NoSetterInCallback, "Cannot set property % of % which has only a getter") \
158 T(NotAnIterator, "% is not an iterator") \
159 T(NotAPromise, "% is not a promise") \
160 T(NotConstructor, "% is not a constructor") \
161 T(NotDateObject, "this is not a Date object.") \
162 T(NotIntlObject, "% is not an i18n object.") \
163 T(NotGeneric, "% is not generic") \
164 T(NotIterable, "% is not iterable") \
165 T(NotPropertyName, "% is not a valid property name") \
166 T(NotTypedArray, "this is not a typed array.") \
167 T(NotSharedTypedArray, "% is not a shared typed array.") \
168 T(NotIntegerSharedTypedArray, "% is not an integer shared typed array.") \
169 T(NotInt32SharedTypedArray, "% is not an int32 shared typed array.") \
170 T(ObjectGetterExpectingFunction, \
171 "Object.prototype.__defineGetter__: Expecting function") \
172 T(ObjectGetterCallable, "Getter must be a function: %") \
173 T(ObjectNotExtensible, "Can't add property %, object is not extensible") \
174 T(ObjectSetterExpectingFunction, \
175 "Object.prototype.__defineSetter__: Expecting function") \
176 T(ObjectSetterCallable, "Setter must be a function: %") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000177 T(OrdinaryFunctionCalledAsConstructor, \
178 "Function object that's not a constructor was created with new") \
179 T(PromiseCyclic, "Chaining cycle detected for promise %") \
180 T(PromiseExecutorAlreadyInvoked, \
181 "Promise executor has already been invoked with non-undefined arguments") \
Ben Murdochda12d292016-06-02 14:46:10 +0100182 T(PromiseNonCallable, "Promise resolve or reject function is not callable") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000183 T(PropertyDescObject, "Property description must be an object: %") \
184 T(PropertyNotFunction, \
185 "'%' returned for property '%' of object '%' is not a function") \
186 T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %") \
187 T(PrototypeParentNotAnObject, \
188 "Class extends value does not have valid prototype property %") \
189 T(ProxyConstructNonObject, \
190 "'construct' on proxy: trap returned non-object ('%')") \
191 T(ProxyDefinePropertyNonConfigurable, \
192 "'defineProperty' on proxy: trap returned truish for defining " \
193 "non-configurable property '%' which is either non-existant or " \
194 "configurable in the proxy target") \
195 T(ProxyDefinePropertyNonExtensible, \
196 "'defineProperty' on proxy: trap returned truish for adding property '%' " \
197 " to the non-extensible proxy target") \
198 T(ProxyDefinePropertyIncompatible, \
199 "'defineProperty' on proxy: trap returned truish for adding property '%' " \
200 " that is incompatible with the existing property in the proxy target") \
201 T(ProxyDeletePropertyNonConfigurable, \
202 "'deleteProperty' on proxy: trap returned truish for property '%' which " \
203 "is non-configurable in the proxy target") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000204 T(ProxyGetNonConfigurableData, \
205 "'get' on proxy: property '%' is a read-only and " \
206 "non-configurable data property on the proxy target but the proxy " \
207 "did not return its actual value (expected '%' but got '%')") \
208 T(ProxyGetNonConfigurableAccessor, \
209 "'get' on proxy: property '%' is a non-configurable accessor " \
210 "property on the proxy target and does not have a getter function, but " \
211 "the trap did not return 'undefined' (got '%')") \
212 T(ProxyGetOwnPropertyDescriptorIncompatible, \
213 "'getOwnPropertyDescriptor' on proxy: trap returned descriptor for " \
214 "property '%' that is incompatible with the existing property in the " \
215 "proxy target") \
216 T(ProxyGetOwnPropertyDescriptorInvalid, \
217 "'getOwnPropertyDescriptor' on proxy: trap returned neither object nor " \
218 "undefined for property '%'") \
219 T(ProxyGetOwnPropertyDescriptorNonConfigurable, \
220 "'getOwnPropertyDescriptor' on proxy: trap reported non-configurability " \
221 "for property '%' which is either non-existant or configurable in the " \
222 "proxy target") \
223 T(ProxyGetOwnPropertyDescriptorNonExtensible, \
224 "'getOwnPropertyDescriptor' on proxy: trap returned undefined for " \
225 "property '%' which exists in the non-extensible proxy target") \
226 T(ProxyGetOwnPropertyDescriptorUndefined, \
227 "'getOwnPropertyDescriptor' on proxy: trap returned undefined for " \
228 "property '%' which is non-configurable in the proxy target") \
229 T(ProxyGetPrototypeOfInvalid, \
230 "'getPrototypeOf' on proxy: trap returned neither object nor null") \
231 T(ProxyGetPrototypeOfNonExtensible, \
232 "'getPrototypeOf' on proxy: proxy target is non-extensible but the " \
233 "trap did not return its actual prototype") \
234 T(ProxyHandlerOrTargetRevoked, \
235 "Cannot create proxy with a revoked proxy as target or handler") \
236 T(ProxyHasNonConfigurable, \
237 "'has' on proxy: trap returned falsish for property '%' which exists in " \
238 "the proxy target as non-configurable") \
239 T(ProxyHasNonExtensible, \
240 "'has' on proxy: trap returned falsish for property '%' but the proxy " \
241 "target is not extensible") \
242 T(ProxyIsExtensibleInconsistent, \
243 "'isExtensible' on proxy: trap result does not reflect extensibility of " \
244 "proxy target (which is '%')") \
245 T(ProxyNonObject, \
246 "Cannot create proxy with a non-object as target or handler") \
247 T(ProxyOwnKeysMissing, \
248 "'ownKeys' on proxy: trap result did not include '%'") \
249 T(ProxyOwnKeysNonExtensible, \
250 "'ownKeys' on proxy: trap returned extra keys but proxy target is " \
251 "non-extensible") \
252 T(ProxyPreventExtensionsExtensible, \
253 "'preventExtensions' on proxy: trap returned truish but the proxy target " \
254 "is extensible") \
255 T(ProxyPrivate, "Cannot pass private property name to proxy trap") \
256 T(ProxyRevoked, "Cannot perform '%' on a proxy that has been revoked") \
257 T(ProxySetFrozenData, \
258 "'set' on proxy: trap returned truish for property '%' which exists in " \
259 "the proxy target as a non-configurable and non-writable data property " \
260 "with a different value") \
261 T(ProxySetFrozenAccessor, \
262 "'set' on proxy: trap returned truish for property '%' which exists in " \
263 "the proxy target as a non-configurable and non-writable accessor " \
264 "property without a setter") \
265 T(ProxySetPrototypeOfNonExtensible, \
266 "'setPrototypeOf' on proxy: trap returned truish for setting a new " \
267 "prototype on the non-extensible proxy target") \
268 T(ProxyTrapReturnedFalsish, "'%' on proxy: trap returned falsish") \
269 T(ProxyTrapReturnedFalsishFor, \
270 "'%' on proxy: trap returned falsish for property '%'") \
271 T(ReadGlobalReferenceThroughProxy, "Trying to access '%' through proxy") \
272 T(RedefineDisallowed, "Cannot redefine property: %") \
273 T(RedefineExternalArray, \
274 "Cannot redefine a property of an object with external array elements") \
275 T(ReduceNoInitial, "Reduce of empty array with no initial value") \
276 T(RegExpFlags, \
277 "Cannot supply flags when constructing one RegExp from another") \
278 T(RegExpNonObject, "% getter called on non-object %") \
279 T(RegExpNonRegExp, "% getter called on non-RegExp object") \
280 T(ReinitializeIntl, "Trying to re-initialize % object.") \
281 T(ResolvedOptionsCalledOnNonObject, \
282 "resolvedOptions method called on a non-object or on a object that is " \
283 "not Intl.%.") \
284 T(ResolverNotAFunction, "Promise resolver % is not a function") \
285 T(RestrictedFunctionProperties, \
286 "'caller' and 'arguments' are restricted function properties and cannot " \
287 "be accessed in this context.") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100288 T(ReturnMethodNotCallable, "The iterator's 'return' method is not callable") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000289 T(StaticPrototype, "Classes may not have static property named prototype") \
290 T(StrictCannotAssign, "Cannot assign to read only '%' in strict mode") \
291 T(StrictDeleteProperty, "Cannot delete property '%' of %") \
292 T(StrictPoisonPill, \
293 "'caller', 'callee', and 'arguments' properties may not be accessed on " \
294 "strict mode functions or the arguments objects for calls to them") \
295 T(StrictReadOnlyProperty, \
296 "Cannot assign to read only property '%' of % '%'") \
297 T(StrictCannotCreateProperty, "Cannot create property '%' on % '%'") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100298 T(SymbolIteratorInvalid, \
299 "Result of the Symbol.iterator method is not an object") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000300 T(SymbolKeyFor, "% is not a symbol") \
301 T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
302 T(SymbolToString, "Cannot convert a Symbol value to a string") \
303 T(SimdToNumber, "Cannot convert a SIMD value to a number") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100304 T(ThrowMethodMissing, "The iterator does not provide a 'throw' method.") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000305 T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \
306 T(ValueAndAccessor, \
307 "Invalid property descriptor. Cannot both specify accessors and a value " \
308 "or writable attribute, %") \
309 T(VarRedeclaration, "Identifier '%' has already been declared") \
310 T(WrongArgs, "%: Arguments list has wrong type") \
311 /* ReferenceError */ \
312 T(NonMethod, "'super' is referenced from non-method") \
313 T(NotDefined, "% is not defined") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000314 T(UnsupportedSuper, "Unsupported reference to 'super'") \
315 /* RangeError */ \
316 T(DateRange, "Provided date is not in valid range.") \
317 T(ExpectedTimezoneID, \
318 "Expected Area/Location(/Location)* for time zone, got %") \
319 T(ExpectedLocation, \
320 "Expected letters optionally connected with underscores or hyphens for " \
321 "a location, got %") \
322 T(InvalidArrayBufferLength, "Invalid array buffer length") \
323 T(ArrayBufferAllocationFailed, "Array buffer allocation failed") \
324 T(InvalidArrayLength, "Invalid array length") \
Ben Murdochda12d292016-06-02 14:46:10 +0100325 T(InvalidAtomicAccessIndex, "Invalid atomic access index") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000326 T(InvalidCodePoint, "Invalid code point %") \
327 T(InvalidCountValue, "Invalid count value") \
328 T(InvalidCurrencyCode, "Invalid currency code: %") \
329 T(InvalidDataViewAccessorOffset, \
330 "Offset is outside the bounds of the DataView") \
331 T(InvalidDataViewLength, "Invalid data view length") \
332 T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \
333 T(InvalidHint, "Invalid hint: %") \
334 T(InvalidLanguageTag, "Invalid language tag: %") \
335 T(InvalidWeakMapKey, "Invalid value used as weak map key") \
336 T(InvalidWeakSetValue, "Invalid value used in weak set") \
337 T(InvalidStringLength, "Invalid string length") \
338 T(InvalidTimeValue, "Invalid time value") \
339 T(InvalidTypedArrayAlignment, "% of % should be a multiple of %") \
340 T(InvalidTypedArrayLength, "Invalid typed array length") \
341 T(InvalidTypedArrayOffset, "Start offset is too large:") \
342 T(LetInLexicalBinding, "let is disallowed as a lexically bound name") \
343 T(LocaleMatcher, "Illegal value for localeMatcher:%") \
344 T(NormalizationForm, "The normalization form should be one of %.") \
345 T(NumberFormatRange, "% argument must be between 0 and 20") \
346 T(PropertyValueOutOfRange, "% value is out of range.") \
347 T(StackOverflow, "Maximum call stack size exceeded") \
348 T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
349 T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \
350 T(TypedArraySetNegativeOffset, "Start offset is negative") \
351 T(TypedArraySetSourceTooLarge, "Source is too large") \
352 T(UnsupportedTimeZone, "Unsupported time zone specified %") \
353 T(ValueOutOfRange, "Value % out of range for % options property %") \
354 /* SyntaxError */ \
355 T(BadGetterArity, "Getter must not have any formal parameters.") \
356 T(BadSetterArity, "Setter must have exactly one formal parameter.") \
357 T(ConstructorIsAccessor, "Class constructor may not be an accessor") \
358 T(ConstructorIsGenerator, "Class constructor may not be a generator") \
Ben Murdochc5610432016-08-08 18:44:38 +0100359 T(ConstructorIsAsync, "Class constructor may not be an async method") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000360 T(DerivedConstructorReturn, \
361 "Derived constructors may only return object or undefined") \
362 T(DuplicateConstructor, "A class may only have one constructor") \
363 T(DuplicateExport, "Duplicate export of '%'") \
364 T(DuplicateProto, \
365 "Duplicate __proto__ fields are not allowed in object literals") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100366 T(ForInOfLoopInitializer, \
367 "% loop variable declaration may not have an initializer.") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000368 T(ForInOfLoopMultiBindings, \
369 "Invalid left-hand side in % loop: Must have a single binding.") \
Ben Murdochc5610432016-08-08 18:44:38 +0100370 T(GeneratorInLegacyContext, \
371 "Generator declarations are not allowed in legacy contexts.") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000372 T(IllegalBreak, "Illegal break statement") \
373 T(IllegalContinue, "Illegal continue statement") \
374 T(IllegalLanguageModeDirective, \
375 "Illegal '%' directive in function with non-simple parameter list") \
376 T(IllegalReturn, "Illegal return statement") \
377 T(InvalidEscapedReservedWord, "Keyword must not contain escaped characters") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100378 T(InvalidEscapedMetaProperty, "'%' must not contain escaped characters") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000379 T(InvalidLhsInAssignment, "Invalid left-hand side in assignment") \
380 T(InvalidCoverInitializedName, "Invalid shorthand property initializer") \
381 T(InvalidDestructuringTarget, "Invalid destructuring assignment target") \
382 T(InvalidLhsInFor, "Invalid left-hand side in for-loop") \
383 T(InvalidLhsInPostfixOp, \
384 "Invalid left-hand side expression in postfix operation") \
385 T(InvalidLhsInPrefixOp, \
386 "Invalid left-hand side expression in prefix operation") \
387 T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \
Ben Murdochda12d292016-06-02 14:46:10 +0100388 T(InvalidOrUnexpectedToken, "Invalid or unexpected token") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100389 T(JsonParseUnexpectedEOS, "Unexpected end of JSON input") \
390 T(JsonParseUnexpectedToken, "Unexpected token % in JSON at position %") \
391 T(JsonParseUnexpectedTokenNumber, "Unexpected number in JSON at position %") \
392 T(JsonParseUnexpectedTokenString, "Unexpected string in JSON at position %") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000393 T(LabelRedeclaration, "Label '%' has already been declared") \
Ben Murdochda12d292016-06-02 14:46:10 +0100394 T(LabelledFunctionDeclaration, \
395 "Labelled function declaration not allowed as the body of a control flow " \
396 "structure") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000397 T(MalformedArrowFunParamList, "Malformed arrow function parameter list") \
398 T(MalformedRegExp, "Invalid regular expression: /%/: %") \
399 T(MalformedRegExpFlags, "Invalid regular expression flags") \
400 T(ModuleExportUndefined, "Export '%' is not defined in module") \
401 T(MultipleDefaultsInSwitch, \
402 "More than one default clause in switch statement") \
403 T(NewlineAfterThrow, "Illegal newline after throw") \
404 T(NoCatchOrFinally, "Missing catch or finally after try") \
405 T(NotIsvar, "builtin %%IS_VAR: not a variable") \
406 T(ParamAfterRest, "Rest parameter must be last formal parameter") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100407 T(InvalidRestParameter, \
408 "Rest parameter must be an identifier or destructuring pattern") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000409 T(PushPastSafeLength, \
410 "Pushing % elements on an array-like of length % " \
411 "is disallowed, as the total surpasses 2**53-1") \
412 T(ElementAfterRest, "Rest element must be last element in array") \
413 T(BadSetterRestParameter, \
414 "Setter function argument must not be a rest parameter") \
415 T(ParamDupe, "Duplicate parameter name not allowed in this context") \
416 T(ParenthesisInArgString, "Function arg string contains parenthesis") \
Ben Murdochda12d292016-06-02 14:46:10 +0100417 T(RuntimeWrongNumArgs, "Runtime function given wrong number of arguments") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000418 T(SingleFunctionLiteral, "Single function literal required") \
Ben Murdochda12d292016-06-02 14:46:10 +0100419 T(SloppyFunction, \
420 "In non-strict mode code, functions can only be declared at top level, " \
421 "inside a block, or as the body of an if statement.") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000422 T(SpeciesNotConstructor, \
423 "object.constructor[Symbol.species] is not a constructor") \
424 T(StrictDelete, "Delete of an unqualified identifier in strict mode.") \
425 T(StrictEvalArguments, "Unexpected eval or arguments in strict mode") \
426 T(StrictFunction, \
427 "In strict mode code, functions can only be declared at top level or " \
Ben Murdochda12d292016-06-02 14:46:10 +0100428 "inside a block.") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000429 T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \
430 T(StrictWith, "Strict mode code may not include a with statement") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000431 T(TemplateOctalLiteral, \
432 "Octal literals are not allowed in template strings.") \
433 T(ThisFormalParameter, "'this' is not a valid formal parameter name") \
Ben Murdochc5610432016-08-08 18:44:38 +0100434 T(AwaitBindingIdentifier, \
435 "'await' is not a valid identifier name in an async function") \
436 T(AwaitExpressionFormalParameter, \
437 "Illegal await-expression in formal parameters of async function") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000438 T(TooManyArguments, \
439 "Too many arguments in function call (only 65535 allowed)") \
440 T(TooManyParameters, \
441 "Too many parameters in function definition (only 65535 allowed)") \
442 T(TooManyVariables, "Too many variables declared (only 4194303 allowed)") \
443 T(TypedArrayTooShort, \
444 "Derived TypedArray constructor created an array which was too small") \
445 T(UnexpectedEOS, "Unexpected end of input") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100446 T(UnexpectedFunctionSent, \
447 "function.sent expression is not allowed outside a generator") \
Ben Murdochc5610432016-08-08 18:44:38 +0100448 T(UnexpectedInsideTailCall, "Unexpected expression inside tail call") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000449 T(UnexpectedReserved, "Unexpected reserved word") \
450 T(UnexpectedStrictReserved, "Unexpected strict mode reserved word") \
451 T(UnexpectedSuper, "'super' keyword unexpected here") \
Ben Murdochc5610432016-08-08 18:44:38 +0100452 T(UnexpectedSloppyTailCall, \
453 "Tail call expressions are not allowed in non-strict mode") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000454 T(UnexpectedNewTarget, "new.target expression is not allowed here") \
Ben Murdochc5610432016-08-08 18:44:38 +0100455 T(UnexpectedTailCall, "Tail call expression is not allowed here") \
456 T(UnexpectedTailCallInCatchBlock, \
457 "Tail call expression in catch block when finally block is also present") \
458 T(UnexpectedTailCallInForInOf, "Tail call expression in for-in/of body") \
459 T(UnexpectedTailCallInTryBlock, "Tail call expression in try block") \
460 T(UnexpectedTailCallOfEval, "Tail call of a direct eval is not allowed") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000461 T(UnexpectedTemplateString, "Unexpected template string") \
462 T(UnexpectedToken, "Unexpected token %") \
463 T(UnexpectedTokenIdentifier, "Unexpected identifier") \
464 T(UnexpectedTokenNumber, "Unexpected number") \
465 T(UnexpectedTokenString, "Unexpected string") \
466 T(UnexpectedTokenRegExp, "Unexpected regular expression") \
467 T(UnknownLabel, "Undefined label '%'") \
468 T(UnterminatedArgList, "missing ) after argument list") \
469 T(UnterminatedRegExp, "Invalid regular expression: missing /") \
470 T(UnterminatedTemplate, "Unterminated template literal") \
471 T(UnterminatedTemplateExpr, "Missing } in template expression") \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100472 T(FoundNonCallableHasInstance, "Found non-callable @@hasInstance") \
Ben Murdochda12d292016-06-02 14:46:10 +0100473 T(InvalidHexEscapeSequence, "Invalid hexadecimal escape sequence") \
474 T(InvalidUnicodeEscapeSequence, "Invalid Unicode escape sequence") \
475 T(UndefinedUnicodeCodePoint, "Undefined Unicode code-point") \
476 T(YieldInParameter, "Yield expression not allowed in formal parameter") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000477 /* EvalError */ \
478 T(CodeGenFromStrings, "%") \
479 /* URIError */ \
Ben Murdochc5610432016-08-08 18:44:38 +0100480 T(URIMalformed, "URI malformed") \
481 /* Wasm errors (currently Error) */ \
482 T(WasmTrapUnreachable, "unreachable") \
483 T(WasmTrapMemOutOfBounds, "memory access out of bounds") \
484 T(WasmTrapDivByZero, "divide by zero") \
485 T(WasmTrapDivUnrepresentable, "divide result unrepresentable") \
486 T(WasmTrapRemByZero, "remainder by zero") \
487 T(WasmTrapFloatUnrepresentable, "integer result unrepresentable") \
488 T(WasmTrapFuncInvalid, "invalid function") \
489 T(WasmTrapFuncSigMismatch, "function signature mismatch")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000490
491class MessageTemplate {
492 public:
493 enum Template {
494#define TEMPLATE(NAME, STRING) k##NAME,
495 MESSAGE_TEMPLATES(TEMPLATE)
496#undef TEMPLATE
497 kLastMessage
498 };
499
500 static const char* TemplateString(int template_index);
501
502 static MaybeHandle<String> FormatMessage(int template_index,
503 Handle<String> arg0,
504 Handle<String> arg1,
505 Handle<String> arg2);
506
507 static Handle<String> FormatMessage(Isolate* isolate, int template_index,
508 Handle<Object> arg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000509};
510
511
512// A message handler is a convenience interface for accessing the list
513// of message listeners registered in an environment
514class MessageHandler {
515 public:
Steve Blocka7e24c12009-10-30 11:49:00 +0000516 // Returns a message object for the API to use.
Steve Block1e0659c2011-05-24 12:43:12 +0100517 static Handle<JSMessageObject> MakeMessageObject(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000518 Isolate* isolate, MessageTemplate::Template type,
519 MessageLocation* location, Handle<Object> argument,
Steve Block1e0659c2011-05-24 12:43:12 +0100520 Handle<JSArray> stack_frames);
Steve Blocka7e24c12009-10-30 11:49:00 +0000521
522 // Report a formatted message (needs JS allocation).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000523 static void ReportMessage(Isolate* isolate, MessageLocation* loc,
524 Handle<JSMessageObject> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000525
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000526 static void DefaultMessageReport(Isolate* isolate, const MessageLocation* loc,
Steve Blocka7e24c12009-10-30 11:49:00 +0000527 Handle<Object> message_obj);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000528 static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000529 static base::SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
530 Handle<Object> data);
Steve Blocka7e24c12009-10-30 11:49:00 +0000531};
532
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000533
534} // namespace internal
535} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000536
537#endif // V8_MESSAGES_H_