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.
5 // The infrastructure used for (localized) message reporting in V8.
7 // Note: there's a big unresolved issue about ownership of the data
8 // structures used by this framework.
10 #ifndef V8_MESSAGES_H_
11 #define V8_MESSAGES_H_
13 // Forward declaration of MessageLocation.
16 class MessageLocation;
17 } } // namespace v8::internal
23 v8::internal::Handle<v8::internal::JSArray> args,
24 const v8::internal::MessageLocation* loc) :
25 type_(type), args_(args), loc_(loc) { }
26 char* type() const { return type_; }
27 v8::internal::Handle<v8::internal::JSArray> args() const { return args_; }
28 const v8::internal::MessageLocation* loc() const { return loc_; }
31 v8::internal::Handle<v8::internal::JSArray> const args_;
32 const v8::internal::MessageLocation* loc_;
42 class MessageLocation {
44 MessageLocation(Handle<Script> script, int start_pos, int end_pos,
45 Handle<JSFunction> function = Handle<JSFunction>())
47 start_pos_(start_pos),
49 function_(function) {}
50 MessageLocation() : start_pos_(-1), end_pos_(-1) { }
52 Handle<Script> script() const { return script_; }
53 int start_pos() const { return start_pos_; }
54 int end_pos() const { return end_pos_; }
55 Handle<JSFunction> function() const { return function_; }
58 Handle<Script> script_;
61 Handle<JSFunction> function_;
67 CallSite(Handle<Object> receiver, Handle<JSFunction> fun, int pos)
68 : receiver_(receiver), fun_(fun), pos_(pos) {}
70 Handle<Object> GetFileName(Isolate* isolate);
71 Handle<Object> GetFunctionName(Isolate* isolate);
72 Handle<Object> GetScriptNameOrSourceUrl(Isolate* isolate);
73 Handle<Object> GetMethodName(Isolate* isolate);
74 // Return 1-based line number, including line offset.
75 int GetLineNumber(Isolate* isolate);
76 // Return 1-based column number, including column offset if first line.
77 int GetColumnNumber(Isolate* isolate);
78 bool IsNative(Isolate* isolate);
79 bool IsToplevel(Isolate* isolate);
80 bool IsEval(Isolate* isolate);
81 bool IsConstructor(Isolate* isolate);
84 Handle<Object> receiver_;
85 Handle<JSFunction> fun_;
90 #define MESSAGE_TEMPLATES(T) \
93 T(CyclicProto, "Cyclic __proto__ value") \
94 T(DebuggerLoading, "Error loading debugger") \
95 T(DefaultOptionsMissing, "Internal % error. Default options are missing.") \
96 T(UncaughtException, "Uncaught %") \
97 T(Unsupported, "Not supported") \
98 T(WrongServiceType, "Internal error, wrong service type: %") \
99 T(WrongValueType, "Internal error. Wrong value type.") \
101 T(ApplyNonFunction, \
102 "Function.prototype.apply was called on %, which is a % and not a " \
104 T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements") \
105 T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements") \
106 T(ArrayNotSubclassable, "Subclassing Arrays is not currently supported.") \
107 T(CalledNonCallable, "% is not a function") \
108 T(CalledOnNonObject, "% called on non-object") \
109 T(CalledOnNullOrUndefined, "% called on null or undefined") \
110 T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
111 T(CannotPreventExtExternalArray, \
112 "Cannot prevent extension of an object with external array elements") \
113 T(CircularStructure, "Converting circular structure to JSON") \
114 T(ConstAssign, "Assignment to constant variable.") \
115 T(ConstructorNonCallable, \
116 "Class constructors cannot be invoked without 'new'") \
117 T(ConstructorNotFunction, "Constructor % requires 'new'") \
118 T(CurrencyCode, "Currency code is required with currency style.") \
119 T(DataViewNotArrayBuffer, \
120 "First argument to DataView constructor must be an ArrayBuffer") \
121 T(DateType, "this is not a Date object.") \
122 T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \
123 T(DuplicateTemplateProperty, "Object template has duplicate property '%'") \
124 T(ExtendsValueGenerator, \
125 "Class extends value % may not be a generator function") \
126 T(ExtendsValueNotFunction, \
127 "Class extends value % is not a function or null") \
128 T(FirstArgumentNotRegExp, \
129 "First argument to % must not be a regular expression") \
130 T(FlagsGetterNonObject, \
131 "RegExp.prototype.flags getter called on non-object %") \
132 T(FunctionBind, "Bind must be called on a function") \
133 T(GeneratorRunning, "Generator is already running") \
134 T(IllegalInvocation, "Illegal invocation") \
135 T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
136 T(InstanceofFunctionExpected, \
137 "Expecting a function in instanceof check, but got %") \
138 T(InstanceofNonobjectProto, \
139 "Function has non-object prototype '%' in instanceof check") \
140 T(InvalidArgument, "invalid_argument") \
141 T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \
142 T(IteratorResultNotAnObject, "Iterator result % is not an object") \
143 T(IteratorValueNotAnObject, "Iterator value % is not an entry object") \
144 T(LanguageID, "Language ID should be string or object.") \
145 T(MethodCalledOnWrongObject, \
146 "Method % called on a non-object or on a wrong type of object.") \
147 T(MethodInvokedOnNullOrUndefined, \
148 "Method invoked on undefined or null value.") \
149 T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \
150 T(NoAccess, "no access") \
151 T(NonCoercible, "Cannot match against 'undefined' or 'null'.") \
152 T(NonExtensibleProto, "% is not extensible") \
153 T(NonObjectPropertyLoad, "Cannot read property '%' of %") \
154 T(NonObjectPropertyStore, "Cannot set property '%' of %") \
155 T(NoSetterInCallback, "Cannot set property % of % which has only a getter") \
156 T(NotAnIterator, "% is not an iterator") \
157 T(NotAPromise, "% is not a promise") \
158 T(NotConstructor, "% is not a constructor") \
159 T(NotDateObject, "this is not a Date object.") \
160 T(NotIntlObject, "% is not an i18n object.") \
161 T(NotGeneric, "% is not generic") \
162 T(NotIterable, "% is not iterable") \
163 T(NotTypedArray, "this is not a typed array.") \
164 T(NotSharedTypedArray, "% is not a shared typed array.") \
165 T(NotIntegerSharedTypedArray, "% is not an integer shared typed array.") \
166 T(ObjectGetterExpectingFunction, \
167 "Object.prototype.__defineGetter__: Expecting function") \
168 T(ObjectGetterCallable, "Getter must be a function: %") \
169 T(ObjectNotExtensible, "Can't add property %, object is not extensible") \
170 T(ObjectSetterExpectingFunction, \
171 "Object.prototype.__defineSetter__: Expecting function") \
172 T(ObjectSetterCallable, "Setter must be a function: %") \
173 T(ObserveCallbackFrozen, \
174 "Object.observe cannot deliver to a frozen function object") \
175 T(ObserveGlobalProxy, "% cannot be called on the global proxy object") \
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(PropertyDescObject, "Property description must be an object: %") \
189 T(PropertyNotFunction, "Property '%' of object % is not a function") \
190 T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %") \
191 T(PrototypeParentNotAnObject, \
192 "Class extends value does not have valid prototype property %") \
193 T(ProxyHandlerDeleteFailed, \
194 "Proxy handler % did not return a boolean value from 'delete' trap") \
195 T(ProxyHandlerNonObject, "Proxy.% called with non-object as handler") \
196 T(ProxyHandlerReturned, "Proxy handler % returned % from '%' trap") \
197 T(ProxyHandlerTrapMissing, "Proxy handler % has no '%' trap") \
198 T(ProxyHandlerTrapMustBeCallable, \
199 "Proxy handler %0 has non-callable '%' trap") \
200 T(ProxyNonObjectPropNames, "Trap '%' returned non-object %") \
201 T(ProxyProtoNonObject, "Proxy.create called with no-object as prototype") \
202 T(ProxyPropNotConfigurable, \
203 "Proxy handler % returned non-configurable descriptor for property '%' " \
205 T(ProxyRepeatedPropName, "Trap '%' returned repeated property name '%'") \
206 T(ProxyTrapFunctionExpected, \
207 "Proxy.createFunction called with non-function for '%' trap") \
208 T(RedefineDisallowed, "Cannot redefine property: %") \
209 T(RedefineExternalArray, \
210 "Cannot redefine a property of an object with external array elements") \
211 T(ReduceNoInitial, "Reduce of empty array with no initial value") \
213 "Cannot supply flags when constructing one RegExp from another") \
214 T(ReinitializeIntl, "Trying to re-initialize % object.") \
215 T(ResolvedOptionsCalledOnNonObject, \
216 "resolvedOptions method called on a non-object or on a object that is " \
218 T(ResolverNotAFunction, "Promise resolver % is not a function") \
219 T(RestrictedFunctionProperties, \
220 "'caller' and 'arguments' are restricted function properties and cannot " \
221 "be accessed in this context.") \
222 T(StaticPrototype, "Classes may not have static property named prototype") \
223 T(StrictCannotAssign, "Cannot assign to read only '% in strict mode") \
224 T(StrictDeleteProperty, "Cannot delete property '%' of %") \
225 T(StrictPoisonPill, \
226 "'caller', 'callee', and 'arguments' properties may not be accessed on " \
227 "strict mode functions or the arguments objects for calls to them") \
228 T(StrictReadOnlyProperty, "Cannot assign to read only property '%' of %") \
230 "In strong mode, calling a function with too few arguments is deprecated") \
231 T(StrongDeleteProperty, \
232 "Deleting property '%' of strong object '%' is deprecated") \
233 T(StrongExtendNull, "In strong mode, classes extending null are deprecated") \
234 T(StrongImplicitConversion, \
235 "In strong mode, implicit conversions are deprecated") \
236 T(StrongRedefineDisallowed, \
237 "On strong object %, redefining writable, non-configurable property '%' " \
238 "to be non-writable is deprecated") \
240 "On strong object %, redefining the internal prototype is deprecated") \
241 T(SymbolKeyFor, "% is not a symbol") \
242 T(SymbolToPrimitive, \
243 "Cannot convert a Symbol wrapper object to a primitive value") \
244 T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
245 T(SymbolToString, "Cannot convert a Symbol value to a string") \
246 T(SimdToNumber, "Cannot convert a SIMD value to a number") \
247 T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \
248 T(ValueAndAccessor, \
249 "Invalid property. A property cannot both have accessors and be " \
250 "writable or have a value, %") \
251 T(VarRedeclaration, "Identifier '%' has already been declared") \
252 T(WithExpression, "% has no properties") \
253 T(WrongArgs, "%: Arguments list has wrong type") \
254 /* ReferenceError */ \
255 T(NonMethod, "'super' is referenced from non-method") \
256 T(NotDefined, "% is not defined") \
257 T(StrongSuperCallMissing, \
258 "In strong mode, invoking the super constructor in a subclass is " \
260 T(StrongUnboundGlobal, \
261 "In strong mode, using an undeclared global variable '%' is not allowed") \
262 T(UnsupportedSuper, "Unsupported reference to 'super'") \
264 T(DateRange, "Provided date is not in valid range.") \
265 T(ExpectedLocation, "Expected Area/Location for time zone, got %") \
266 T(InvalidArrayBufferLength, "Invalid array buffer length") \
267 T(InvalidArrayLength, "Invalid array length") \
268 T(InvalidCodePoint, "Invalid code point %") \
269 T(InvalidCountValue, "Invalid count value") \
270 T(InvalidCurrencyCode, "Invalid currency code: %") \
271 T(InvalidDataViewAccessorOffset, \
272 "Offset is outside the bounds of the DataView") \
273 T(InvalidDataViewLength, "Invalid data view length") \
274 T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \
275 T(InvalidLanguageTag, "Invalid language tag: %") \
276 T(InvalidWeakMapKey, "Invalid value used as weak map key") \
277 T(InvalidWeakSetValue, "Invalid value used in weak set") \
278 T(InvalidStringLength, "Invalid string length") \
279 T(InvalidTimeValue, "Invalid time value") \
280 T(InvalidTypedArrayAlignment, "% of % should be a multiple of %") \
281 T(InvalidTypedArrayLength, "Invalid typed array length") \
282 T(InvalidTypedArrayOffset, "Start offset is too large:") \
283 T(LocaleMatcher, "Illegal value for localeMatcher:%") \
284 T(NormalizationForm, "The normalization form should be one of %.") \
285 T(NumberFormatRange, "% argument must be between 0 and 20") \
286 T(PropertyValueOutOfRange, "% value is out of range.") \
287 T(StackOverflow, "Maximum call stack size exceeded") \
288 T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
289 T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \
290 T(TypedArraySetNegativeOffset, "Start offset is negative") \
291 T(TypedArraySetSourceTooLarge, "Source is too large") \
292 T(UnsupportedTimeZone, "Unsupported time zone specified %") \
293 T(ValueOutOfRange, "Value % out of range for % options property %") \
295 T(BadGetterArity, "Getter must not have any formal parameters.") \
296 T(BadSetterArity, "Setter must have exactly one formal parameter.") \
297 T(ConstructorIsAccessor, "Class constructor may not be an accessor") \
298 T(ConstructorIsGenerator, "Class constructor may not be a generator") \
299 T(DerivedConstructorReturn, \
300 "Derived constructors may only return object or undefined") \
301 T(DuplicateConstructor, "A class may only have one constructor") \
302 T(DuplicateExport, "Duplicate export of '%'") \
304 "Duplicate __proto__ fields are not allowed in object literals") \
305 T(ForInLoopInitializer, \
306 "for-in loop variable declaration may not have an initializer.") \
307 T(ForInOfLoopMultiBindings, \
308 "Invalid left-hand side in % loop: Must have a single binding.") \
309 T(ForOfLoopInitializer, \
310 "for-of loop variable declaration may not have an initializer.") \
311 T(IllegalAccess, "Illegal access") \
312 T(IllegalBreak, "Illegal break statement") \
313 T(IllegalContinue, "Illegal continue statement") \
314 T(IllegalReturn, "Illegal return statement") \
315 T(InvalidLhsInAssignment, "Invalid left-hand side in assignment") \
316 T(InvalidLhsInFor, "Invalid left-hand side in for-loop") \
317 T(InvalidLhsInPostfixOp, \
318 "Invalid left-hand side expression in postfix operation") \
319 T(InvalidLhsInPrefixOp, \
320 "Invalid left-hand side expression in prefix operation") \
321 T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \
322 T(LabelRedeclaration, "Label '%' has already been declared") \
323 T(MalformedArrowFunParamList, "Malformed arrow function parameter list") \
324 T(MalformedRegExp, "Invalid regular expression: /%/: %") \
325 T(MalformedRegExpFlags, "Invalid regular expression flags") \
327 "Expected () to start arrow function, but got '%' instead of '=>'") \
328 T(ModuleExportUndefined, "Export '%' is not defined in module") \
329 T(MultipleDefaultsInSwitch, \
330 "More than one default clause in switch statement") \
331 T(NewlineAfterThrow, "Illegal newline after throw") \
332 T(NoCatchOrFinally, "Missing catch or finally after try") \
333 T(NotIsvar, "builtin %%IS_VAR: not a variable") \
334 T(ParamAfterRest, "Rest parameter must be last formal parameter") \
335 T(BadSetterRestParameter, \
336 "Setter function argument must not be a rest parameter") \
337 T(ParamDupe, "Duplicate parameter name not allowed in this context") \
338 T(ParenthesisInArgString, "Function arg string contains parenthesis") \
339 T(SingleFunctionLiteral, "Single function literal required") \
341 "Block-scoped declarations (let, const, function, class) not yet " \
342 "supported outside strict mode") \
343 T(StrictDelete, "Delete of an unqualified identifier in strict mode.") \
344 T(StrictEvalArguments, "Unexpected eval or arguments in strict mode") \
346 "In strict mode code, functions can only be declared at top level or " \
347 "immediately within another function.") \
348 T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \
349 T(StrictWith, "Strict mode code may not include a with statement") \
351 "In strong mode, 'arguments' is deprecated, use '...args' instead") \
352 T(StrongConstructorReturnMisplaced, \
353 "In strong mode, returning from a constructor before its super " \
354 "constructor invocation or all assignments to 'this' is deprecated") \
355 T(StrongConstructorReturnValue, \
356 "In strong mode, returning a value from a constructor is deprecated") \
357 T(StrongConstructorSuper, \
358 "In strong mode, 'super' can only be used to invoke the super " \
359 "constructor, and cannot be nested inside another statement or " \
361 T(StrongConstructorThis, \
362 "In strong mode, 'this' can only be used to initialize properties, and " \
363 "cannot be nested inside another statement or expression") \
365 "In strong mode, 'delete' is deprecated, use maps or sets instead") \
366 T(StrongDirectEval, "In strong mode, direct calls to eval are deprecated") \
368 "In strong mode, arrays with holes are deprecated, use maps instead") \
370 "In strong mode, empty sub-statements are deprecated, make them explicit " \
371 "with '{}' instead") \
373 "In strong mode, '==' and '!=' are deprecated, use '===' and '!==' " \
376 "In strong mode, 'for'-'in' loops are deprecated, use 'for'-'of' instead") \
377 T(StrongPropertyAccess, \
378 "In strong mode, accessing missing property '%' of % is deprecated") \
379 T(StrongSuperCallDuplicate, \
380 "In strong mode, invoking the super constructor multiple times is " \
382 T(StrongSuperCallMisplaced, \
383 "In strong mode, the super constructor must be invoked before any " \
384 "assignment to 'this'") \
385 T(StrongSwitchFallthrough, \
386 "In strong mode, switch fall-through is deprecated, terminate each case " \
387 "with 'break', 'continue', 'return' or 'throw'") \
389 "In strong mode, binding or assigning to 'undefined' is deprecated") \
390 T(StrongUseBeforeDeclaration, \
391 "In strong mode, declaring variable '%' before its use is required") \
393 "In strong mode, 'var' is deprecated, use 'let' or 'const' instead") \
394 T(TemplateOctalLiteral, \
395 "Octal literals are not allowed in template strings.") \
396 T(ThisFormalParameter, "'this' is not a valid formal parameter name") \
397 T(TooManyArguments, \
398 "Too many arguments in function call (only 65535 allowed)") \
399 T(TooManyParameters, \
400 "Too many parameters in function definition (only 65535 allowed)") \
401 T(TooManyVariables, "Too many variables declared (only 4194303 allowed)") \
402 T(UnexpectedEOS, "Unexpected end of input") \
403 T(UnexpectedReserved, "Unexpected reserved word") \
404 T(UnexpectedStrictReserved, "Unexpected strict mode reserved word") \
405 T(UnexpectedSuper, "'super' keyword unexpected here") \
406 T(UnexpectedNewTarget, "new.target expression is not allowed here") \
407 T(UnexpectedTemplateString, "Unexpected template string") \
408 T(UnexpectedToken, "Unexpected token %") \
409 T(UnexpectedTokenIdentifier, "Unexpected identifier") \
410 T(UnexpectedTokenNumber, "Unexpected number") \
411 T(UnexpectedTokenString, "Unexpected string") \
412 T(UnexpectedTokenRegExp, "Unexpected regular expression") \
413 T(UnknownLabel, "Undefined label '%'") \
414 T(UnterminatedArgList, "missing ) after argument list") \
415 T(UnterminatedRegExp, "Invalid regular expression: missing /") \
416 T(UnterminatedTemplate, "Unterminated template literal") \
417 T(UnterminatedTemplateExpr, "Missing } in template expression") \
419 T(CodeGenFromStrings, "%") \
421 T(URIMalformed, "URI malformed")
423 class MessageTemplate {
426 #define TEMPLATE(NAME, STRING) k##NAME,
427 MESSAGE_TEMPLATES(TEMPLATE)
432 static MaybeHandle<String> FormatMessage(int template_index,
435 Handle<String> arg2);
437 static Handle<String> FormatMessage(Isolate* isolate, int template_index,
442 // A message handler is a convenience interface for accessing the list
443 // of message listeners registered in an environment
444 class MessageHandler {
446 // Returns a message object for the API to use.
447 static Handle<JSMessageObject> MakeMessageObject(
448 Isolate* isolate, MessageTemplate::Template type, MessageLocation* loc,
449 Handle<Object> argument, Handle<JSArray> stack_frames);
451 // Report a formatted message (needs JS allocation).
452 static void ReportMessage(Isolate* isolate, MessageLocation* loc,
453 Handle<JSMessageObject> message);
455 static void DefaultMessageReport(Isolate* isolate, const MessageLocation* loc,
456 Handle<Object> message_obj);
457 static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
458 static base::SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
459 Handle<Object> data);
461 } } // namespace v8::internal
463 #endif // V8_MESSAGES_H_