messages.h 30.8 KB
Newer Older
1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4 5 6 7 8 9 10 11 12

// The infrastructure used for (localized) message reporting in V8.
//
// Note: there's a big unresolved issue about ownership of the data
// structures used by this framework.

#ifndef V8_MESSAGES_H_
#define V8_MESSAGES_H_

13 14
#include "src/base/smart-pointers.h"
#include "src/list.h"
15

16 17
namespace v8 {
namespace internal {
18

19 20 21
// Forward declarations.
class JSMessageObject;
class LookupIterator;
22 23 24 25
class SourceInfo;

class MessageLocation {
 public:
26 27
  MessageLocation(Handle<Script> script, int start_pos, int end_pos,
                  Handle<JSFunction> function = Handle<JSFunction>())
28 29
      : script_(script),
        start_pos_(start_pos),
30 31
        end_pos_(end_pos),
        function_(function) {}
32
  MessageLocation() : start_pos_(-1), end_pos_(-1) { }
33 34 35 36

  Handle<Script> script() const { return script_; }
  int start_pos() const { return start_pos_; }
  int end_pos() const { return end_pos_; }
37
  Handle<JSFunction> function() const { return function_; }
38 39 40 41 42

 private:
  Handle<Script> script_;
  int start_pos_;
  int end_pos_;
43
  Handle<JSFunction> function_;
44 45 46
};


47 48 49 50 51 52 53 54
class CallSite {
 public:
  CallSite(Handle<Object> receiver, Handle<JSFunction> fun, int pos)
      : receiver_(receiver), fun_(fun), pos_(pos) {}

  Handle<Object> GetFileName(Isolate* isolate);
  Handle<Object> GetFunctionName(Isolate* isolate);
  Handle<Object> GetScriptNameOrSourceUrl(Isolate* isolate);
55
  Handle<Object> GetMethodName(Isolate* isolate);
56 57 58 59 60 61 62
  // Return 1-based line number, including line offset.
  int GetLineNumber(Isolate* isolate);
  // Return 1-based column number, including column offset if first line.
  int GetColumnNumber(Isolate* isolate);
  bool IsNative(Isolate* isolate);
  bool IsToplevel(Isolate* isolate);
  bool IsEval(Isolate* isolate);
63
  bool IsConstructor(Isolate* isolate);
64 65 66 67 68 69 70 71

 private:
  Handle<Object> receiver_;
  Handle<JSFunction> fun_;
  int pos_;
};


72 73
#define MESSAGE_TEMPLATES(T)                                                   \
  /* Error */                                                                  \
74
  T(None, "")                                                                  \
75
  T(CyclicProto, "Cyclic __proto__ value")                                     \
76
  T(DebuggerLoading, "Error loading debugger")                                 \
77
  T(DefaultOptionsMissing, "Internal % error. Default options are missing.")   \
78
  T(UncaughtException, "Uncaught %")                                           \
79 80 81
  T(Unsupported, "Not supported")                                              \
  T(WrongServiceType, "Internal error, wrong service type: %")                 \
  T(WrongValueType, "Internal error. Wrong value type.")                       \
82 83 84 85
  /* TypeError */                                                              \
  T(ApplyNonFunction,                                                          \
    "Function.prototype.apply was called on %, which is a % and not a "        \
    "function")                                                                \
86 87
  T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements")             \
  T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements")         \
88
  T(ArrayNotSubclassable, "Subclassing Arrays is not currently supported.")    \
89 90
  T(CalledNonCallable, "% is not a function")                                  \
  T(CalledOnNonObject, "% called on non-object")                               \
91
  T(CalledOnNullOrUndefined, "% called on null or undefined")                  \
92
  T(CannotConvertToPrimitive, "Cannot convert object to primitive value")      \
93 94 95 96
  T(CannotPreventExtExternalArray,                                             \
    "Cannot prevent extension of an object with external array elements")      \
  T(CircularStructure, "Converting circular structure to JSON")                \
  T(ConstAssign, "Assignment to constant variable.")                           \
97 98
  T(ConstructorNonCallable,                                                    \
    "Class constructors cannot be invoked without 'new'")                      \
99 100
  T(ConstructorNotFunction, "Constructor % requires 'new'")                    \
  T(CurrencyCode, "Currency code is required with currency style.")            \
101 102
  T(DataViewNotArrayBuffer,                                                    \
    "First argument to DataView constructor must be an ArrayBuffer")           \
103
  T(DateType, "this is not a Date object.")                                    \
104
  T(DefineDisallowed, "Cannot define property:%, object is not extensible.")   \
105 106 107 108 109
  T(DuplicateTemplateProperty, "Object template has duplicate property '%'")   \
  T(ExtendsValueGenerator,                                                     \
    "Class extends value % may not be a generator function")                   \
  T(ExtendsValueNotFunction,                                                   \
    "Class extends value % is not a function or null")                         \
110 111
  T(FirstArgumentNotRegExp,                                                    \
    "First argument to % must not be a regular expression")                    \
112 113
  T(FlagsGetterNonObject,                                                      \
    "RegExp.prototype.flags getter called on non-object %")                    \
114
  T(FunctionBind, "Bind must be called on a function")                         \
115
  T(GeneratorRunning, "Generator is already running")                          \
116
  T(IllegalInvocation, "Illegal invocation")                                   \
117 118 119 120 121
  T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %")  \
  T(InstanceofFunctionExpected,                                                \
    "Expecting a function in instanceof check, but got %")                     \
  T(InstanceofNonobjectProto,                                                  \
    "Function has non-object prototype '%' in instanceof check")               \
122
  T(InvalidArgument, "invalid_argument")                                       \
123
  T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %")   \
124 125
  T(IteratorResultNotAnObject, "Iterator result % is not an object")           \
  T(IteratorValueNotAnObject, "Iterator value % is not an entry object")       \
126 127 128 129 130 131
  T(LanguageID, "Language ID should be string or object.")                     \
  T(MethodCalledOnWrongObject,                                                 \
    "Method % called on a non-object or on a wrong type of object.")           \
  T(MethodInvokedOnNullOrUndefined,                                            \
    "Method invoked on undefined or null value.")                              \
  T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.")    \
132
  T(NoAccess, "no access")                                                     \
133
  T(NonCoercible, "Cannot match against 'undefined' or 'null'.")               \
134 135 136 137
  T(NonExtensibleProto, "% is not extensible")                                 \
  T(NonObjectPropertyLoad, "Cannot read property '%' of %")                    \
  T(NonObjectPropertyStore, "Cannot set property '%' of %")                    \
  T(NoSetterInCallback, "Cannot set property % of % which has only a getter")  \
138
  T(NotAnIterator, "% is not an iterator")                                     \
139
  T(NotAPromise, "% is not a promise")                                         \
140
  T(NotConstructor, "% is not a constructor")                                  \
141 142
  T(NotDateObject, "this is not a Date object.")                               \
  T(NotIntlObject, "% is not an i18n object.")                                 \
143 144
  T(NotGeneric, "% is not generic")                                            \
  T(NotIterable, "% is not iterable")                                          \
145
  T(NotTypedArray, "this is not a typed array.")                               \
binji's avatar
binji committed
146 147
  T(NotSharedTypedArray, "% is not a shared typed array.")                     \
  T(NotIntegerSharedTypedArray, "% is not an integer shared typed array.")     \
binji's avatar
binji committed
148
  T(NotInt32SharedTypedArray, "% is not an int32 shared typed array.")         \
149 150 151
  T(ObjectGetterExpectingFunction,                                             \
    "Object.prototype.__defineGetter__: Expecting function")                   \
  T(ObjectGetterCallable, "Getter must be a function: %")                      \
152
  T(ObjectNotExtensible, "Can't add property %, object is not extensible")     \
153 154 155
  T(ObjectSetterExpectingFunction,                                             \
    "Object.prototype.__defineSetter__: Expecting function")                   \
  T(ObjectSetterCallable, "Setter must be a function: %")                      \
156 157 158 159 160 161 162 163 164 165 166 167
  T(ObserveCallbackFrozen,                                                     \
    "Object.observe cannot deliver to a frozen function object")               \
  T(ObserveGlobalProxy, "% cannot be called on the global proxy object")       \
  T(ObserveInvalidAccept,                                                      \
    "Third argument to Object.observe must be an array of strings.")           \
  T(ObserveNonFunction, "Object.% cannot deliver to non-function")             \
  T(ObserveNonObject, "Object.% cannot % non-object")                          \
  T(ObserveNotifyNonNotifier, "notify called on non-notifier object")          \
  T(ObservePerformNonFunction, "Cannot perform non-function")                  \
  T(ObservePerformNonString, "Invalid non-string changeType")                  \
  T(ObserveTypeNonString,                                                      \
    "Invalid changeRecord with non-string 'type' property")                    \
168 169
  T(OrdinaryFunctionCalledAsConstructor,                                       \
    "Function object that's not a constructor was created with new")           \
170
  T(PromiseCyclic, "Chaining cycle detected for promise %")                    \
171 172 173
  T(PropertyDescObject, "Property description must be an object: %")           \
  T(PropertyNotFunction, "Property '%' of object % is not a function")         \
  T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %")    \
174 175 176 177
  T(PrototypeParentNotAnObject,                                                \
    "Class extends value does not have valid prototype property %")            \
  T(ProxyHandlerDeleteFailed,                                                  \
    "Proxy handler % did not return a boolean value from 'delete' trap")       \
178
  T(ProxyHandlerNonObject, "Proxy.% called with non-object as handler")        \
179 180 181 182 183
  T(ProxyHandlerReturned, "Proxy handler % returned % from '%' trap")          \
  T(ProxyHandlerTrapMissing, "Proxy handler % has no '%' trap")                \
  T(ProxyHandlerTrapMustBeCallable,                                            \
    "Proxy handler %0 has non-callable '%' trap")                              \
  T(ProxyNonObjectPropNames, "Trap '%' returned non-object %")                 \
184
  T(ProxyProtoNonObject, "Proxy.create called with no-object as prototype")    \
185 186 187
  T(ProxyPropNotConfigurable,                                                  \
    "Proxy handler % returned non-configurable descriptor for property '%' "   \
    "from '%' trap")                                                           \
188 189 190
  T(ProxyRepeatedPropName, "Trap '%' returned repeated property name '%'")     \
  T(ProxyTrapFunctionExpected,                                                 \
    "Proxy.createFunction called with non-function for '%' trap")              \
191
  T(RedefineDisallowed, "Cannot redefine property: %")                         \
192 193
  T(RedefineExternalArray,                                                     \
    "Cannot redefine a property of an object with external array elements")    \
194
  T(ReduceNoInitial, "Reduce of empty array with no initial value")            \
195 196
  T(RegExpFlags,                                                               \
    "Cannot supply flags when constructing one RegExp from another")           \
197 198 199 200
  T(ReinitializeIntl, "Trying to re-initialize % object.")                     \
  T(ResolvedOptionsCalledOnNonObject,                                          \
    "resolvedOptions method called on a non-object or on a object that is "    \
    "not Intl.%.")                                                             \
201
  T(ResolverNotAFunction, "Promise resolver % is not a function")              \
202 203 204 205 206 207 208 209 210 211 212 213
  T(RestrictedFunctionProperties,                                              \
    "'caller' and 'arguments' are restricted function properties and cannot "  \
    "be accessed in this context.")                                            \
  T(StaticPrototype, "Classes may not have static property named prototype")   \
  T(StrictCannotAssign, "Cannot assign to read only '% in strict mode")        \
  T(StrictDeleteProperty, "Cannot delete property '%' of %")                   \
  T(StrictPoisonPill,                                                          \
    "'caller', 'callee', and 'arguments' properties may not be accessed on "   \
    "strict mode functions or the arguments objects for calls to them")        \
  T(StrictReadOnlyProperty, "Cannot assign to read only property '%' of %")    \
  T(StrongArity,                                                               \
    "In strong mode, calling a function with too few arguments is deprecated") \
214
  T(StrongDeleteProperty,                                                      \
215
    "Deleting property '%' of strong object '%' is deprecated")                \
216
  T(StrongExtendNull, "In strong mode, classes extending null are deprecated") \
217 218
  T(StrongImplicitConversion,                                                  \
    "In strong mode, implicit conversions are deprecated")                     \
219 220 221
  T(StrongRedefineDisallowed,                                                  \
    "On strong object %, redefining writable, non-configurable property '%' "  \
    "to be non-writable is deprecated")                                        \
222 223
  T(StrongSetProto,                                                            \
    "On strong object %, redefining the internal prototype is deprecated")     \
224
  T(SymbolKeyFor, "% is not a symbol")                                         \
225 226
  T(SymbolToNumber, "Cannot convert a Symbol value to a number")               \
  T(SymbolToString, "Cannot convert a Symbol value to a string")               \
227
  T(SimdToNumber, "Cannot convert a SIMD value to a number")                   \
228 229 230 231
  T(UndefinedOrNullToObject, "Cannot convert undefined or null to object")     \
  T(ValueAndAccessor,                                                          \
    "Invalid property.  A property cannot both have accessors and be "         \
    "writable or have a value, %")                                             \
232
  T(VarRedeclaration, "Identifier '%' has already been declared")              \
233 234
  T(WithExpression, "% has no properties")                                     \
  T(WrongArgs, "%: Arguments list has wrong type")                             \
235 236 237
  /* ReferenceError */                                                         \
  T(NonMethod, "'super' is referenced from non-method")                        \
  T(NotDefined, "% is not defined")                                            \
238 239 240 241 242
  T(StrongSuperCallMissing,                                                    \
    "In strong mode, invoking the super constructor in a subclass is "         \
    "required")                                                                \
  T(StrongUnboundGlobal,                                                       \
    "In strong mode, using an undeclared global variable '%' is not allowed")  \
243
  T(UnsupportedSuper, "Unsupported reference to 'super'")                      \
244
  /* RangeError */                                                             \
245 246
  T(DateRange, "Provided date is not in valid range.")                         \
  T(ExpectedLocation, "Expected Area/Location for time zone, got %")           \
247 248
  T(InvalidArrayBufferLength, "Invalid array buffer length")                   \
  T(InvalidArrayLength, "Invalid array length")                                \
249 250
  T(InvalidCodePoint, "Invalid code point %")                                  \
  T(InvalidCountValue, "Invalid count value")                                  \
251
  T(InvalidCurrencyCode, "Invalid currency code: %")                           \
252 253 254 255
  T(InvalidDataViewAccessorOffset,                                             \
    "Offset is outside the bounds of the DataView")                            \
  T(InvalidDataViewLength, "Invalid data view length")                         \
  T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \
256
  T(InvalidLanguageTag, "Invalid language tag: %")                             \
257 258
  T(InvalidWeakMapKey, "Invalid value used as weak map key")                   \
  T(InvalidWeakSetValue, "Invalid value used in weak set")                     \
259
  T(InvalidStringLength, "Invalid string length")                              \
260
  T(InvalidTimeValue, "Invalid time value")                                    \
261 262 263
  T(InvalidTypedArrayAlignment, "% of % should be a multiple of %")            \
  T(InvalidTypedArrayLength, "Invalid typed array length")                     \
  T(InvalidTypedArrayOffset, "Start offset is too large:")                     \
264 265
  T(LocaleMatcher, "Illegal value for localeMatcher:%")                        \
  T(NormalizationForm, "The normalization form should be one of %.")           \
266
  T(NumberFormatRange, "% argument must be between 0 and 20")                  \
267
  T(PropertyValueOutOfRange, "% value is out of range.")                       \
268 269
  T(StackOverflow, "Maximum call stack size exceeded")                         \
  T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
270
  T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36")  \
271 272
  T(TypedArraySetNegativeOffset, "Start offset is negative")                   \
  T(TypedArraySetSourceTooLarge, "Source is too large")                        \
273 274
  T(UnsupportedTimeZone, "Unsupported time zone specified %")                  \
  T(ValueOutOfRange, "Value % out of range for % options property %")          \
275
  /* SyntaxError */                                                            \
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
  T(BadGetterArity, "Getter must not have any formal parameters.")             \
  T(BadSetterArity, "Setter must have exactly one formal parameter.")          \
  T(ConstructorIsAccessor, "Class constructor may not be an accessor")         \
  T(ConstructorIsGenerator, "Class constructor may not be a generator")        \
  T(DerivedConstructorReturn,                                                  \
    "Derived constructors may only return object or undefined")                \
  T(DuplicateConstructor, "A class may only have one constructor")             \
  T(DuplicateExport, "Duplicate export of '%'")                                \
  T(DuplicateProto,                                                            \
    "Duplicate __proto__ fields are not allowed in object literals")           \
  T(ForInLoopInitializer,                                                      \
    "for-in loop variable declaration may not have an initializer.")           \
  T(ForInOfLoopMultiBindings,                                                  \
    "Invalid left-hand side in % loop: Must have a single binding.")           \
  T(ForOfLoopInitializer,                                                      \
    "for-of loop variable declaration may not have an initializer.")           \
  T(IllegalAccess, "Illegal access")                                           \
  T(IllegalBreak, "Illegal break statement")                                   \
  T(IllegalContinue, "Illegal continue statement")                             \
  T(IllegalReturn, "Illegal return statement")                                 \
  T(InvalidLhsInAssignment, "Invalid left-hand side in assignment")            \
  T(InvalidLhsInFor, "Invalid left-hand side in for-loop")                     \
  T(InvalidLhsInPostfixOp,                                                     \
    "Invalid left-hand side expression in postfix operation")                  \
  T(InvalidLhsInPrefixOp,                                                      \
    "Invalid left-hand side expression in prefix operation")                   \
302
  T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'")    \
303 304
  T(LabelRedeclaration, "Label '%' has already been declared")                 \
  T(MalformedArrowFunParamList, "Malformed arrow function parameter list")     \
305
  T(MalformedRegExp, "Invalid regular expression: /%/: %")                     \
306
  T(MalformedRegExpFlags, "Invalid regular expression flags")                  \
307 308
  T(MissingArrow,                                                              \
    "Expected () to start arrow function, but got '%' instead of '=>'")        \
309 310 311 312 313 314 315
  T(ModuleExportUndefined, "Export '%' is not defined in module")              \
  T(MultipleDefaultsInSwitch,                                                  \
    "More than one default clause in switch statement")                        \
  T(NewlineAfterThrow, "Illegal newline after throw")                          \
  T(NoCatchOrFinally, "Missing catch or finally after try")                    \
  T(NotIsvar, "builtin %%IS_VAR: not a variable")                              \
  T(ParamAfterRest, "Rest parameter must be last formal parameter")            \
316 317
  T(BadSetterRestParameter,                                                    \
    "Setter function argument must not be a rest parameter")                   \
318
  T(ParamDupe, "Duplicate parameter name not allowed in this context")         \
319
  T(ParenthesisInArgString, "Function arg string contains parenthesis")        \
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
  T(SingleFunctionLiteral, "Single function literal required")                 \
  T(SloppyLexical,                                                             \
    "Block-scoped declarations (let, const, function, class) not yet "         \
    "supported outside strict mode")                                           \
  T(StrictDelete, "Delete of an unqualified identifier in strict mode.")       \
  T(StrictEvalArguments, "Unexpected eval or arguments in strict mode")        \
  T(StrictFunction,                                                            \
    "In strict mode code, functions can only be declared at top level or "     \
    "immediately within another function.")                                    \
  T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.")      \
  T(StrictWith, "Strict mode code may not include a with statement")           \
  T(StrongArguments,                                                           \
    "In strong mode, 'arguments' is deprecated, use '...args' instead")        \
  T(StrongConstructorReturnMisplaced,                                          \
    "In strong mode, returning from a constructor before its super "           \
    "constructor invocation or all assignments to 'this' is deprecated")       \
  T(StrongConstructorReturnValue,                                              \
    "In strong mode, returning a value from a constructor is deprecated")      \
  T(StrongConstructorSuper,                                                    \
    "In strong mode, 'super' can only be used to invoke the super "            \
    "constructor, and cannot be nested inside another statement or "           \
    "expression")                                                              \
  T(StrongConstructorThis,                                                     \
    "In strong mode, 'this' can only be used to initialize properties, and "   \
    "cannot be nested inside another statement or expression")                 \
  T(StrongDelete,                                                              \
    "In strong mode, 'delete' is deprecated, use maps or sets instead")        \
  T(StrongDirectEval, "In strong mode, direct calls to eval are deprecated")   \
  T(StrongEllision,                                                            \
    "In strong mode, arrays with holes are deprecated, use maps instead")      \
  T(StrongEmpty,                                                               \
    "In strong mode, empty sub-statements are deprecated, make them explicit " \
    "with '{}' instead")                                                       \
  T(StrongEqual,                                                               \
    "In strong mode, '==' and '!=' are deprecated, use '===' and '!==' "       \
    "instead")                                                                 \
  T(StrongForIn,                                                               \
    "In strong mode, 'for'-'in' loops are deprecated, use 'for'-'of' instead") \
358 359
  T(StrongPropertyAccess,                                                      \
    "In strong mode, accessing missing property '%' of % is deprecated")       \
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
  T(StrongSuperCallDuplicate,                                                  \
    "In strong mode, invoking the super constructor multiple times is "        \
    "deprecated")                                                              \
  T(StrongSuperCallMisplaced,                                                  \
    "In strong mode, the super constructor must be invoked before any "        \
    "assignment to 'this'")                                                    \
  T(StrongSwitchFallthrough,                                                   \
    "In strong mode, switch fall-through is deprecated, terminate each case "  \
    "with 'break', 'continue', 'return' or 'throw'")                           \
  T(StrongUndefined,                                                           \
    "In strong mode, binding or assigning to 'undefined' is deprecated")       \
  T(StrongUseBeforeDeclaration,                                                \
    "In strong mode, declaring variable '%' before its use is required")       \
  T(StrongVar,                                                                 \
    "In strong mode, 'var' is deprecated, use 'let' or 'const' instead")       \
  T(TemplateOctalLiteral,                                                      \
    "Octal literals are not allowed in template strings.")                     \
  T(ThisFormalParameter, "'this' is not a valid formal parameter name")        \
  T(TooManyArguments,                                                          \
    "Too many arguments in function call (only 65535 allowed)")                \
  T(TooManyParameters,                                                         \
    "Too many parameters in function definition (only 65535 allowed)")         \
  T(TooManyVariables, "Too many variables declared (only 4194303 allowed)")    \
383
  T(UnexpectedEOS, "Unexpected end of input")                                  \
384 385 386
  T(UnexpectedReserved, "Unexpected reserved word")                            \
  T(UnexpectedStrictReserved, "Unexpected strict mode reserved word")          \
  T(UnexpectedSuper, "'super' keyword unexpected here")                        \
387
  T(UnexpectedNewTarget, "new.target expression is not allowed here")          \
388
  T(UnexpectedTemplateString, "Unexpected template string")                    \
389
  T(UnexpectedToken, "Unexpected token %")                                     \
390
  T(UnexpectedTokenIdentifier, "Unexpected identifier")                        \
391 392
  T(UnexpectedTokenNumber, "Unexpected number")                                \
  T(UnexpectedTokenString, "Unexpected string")                                \
393
  T(UnexpectedTokenRegExp, "Unexpected regular expression")                    \
394 395 396 397 398
  T(UnknownLabel, "Undefined label '%'")                                       \
  T(UnterminatedArgList, "missing ) after argument list")                      \
  T(UnterminatedRegExp, "Invalid regular expression: missing /")               \
  T(UnterminatedTemplate, "Unterminated template literal")                     \
  T(UnterminatedTemplateExpr, "Missing } in template expression")              \
399
  /* EvalError */                                                              \
400 401 402
  T(CodeGenFromStrings, "%")                                                   \
  /* URIError */                                                               \
  T(URIMalformed, "URI malformed")
403 404 405 406 407 408 409 410 411 412 413 414 415 416

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

  static MaybeHandle<String> FormatMessage(int template_index,
                                           Handle<String> arg0,
                                           Handle<String> arg1,
                                           Handle<String> arg2);
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433

  static Handle<String> FormatMessage(Isolate* isolate, int template_index,
                                      Handle<Object> arg);
};


// A message handler is a convenience interface for accessing the list
// of message listeners registered in an environment
class MessageHandler {
 public:
  // Returns a message object for the API to use.
  static Handle<JSMessageObject> MakeMessageObject(
      Isolate* isolate, MessageTemplate::Template type, MessageLocation* loc,
      Handle<Object> argument, Handle<JSArray> stack_frames);

  // Report a formatted message (needs JS allocation).
  static void ReportMessage(Isolate* isolate, MessageLocation* loc,
434
                            Handle<JSMessageObject> message);
435 436 437 438

  static void DefaultMessageReport(Isolate* isolate, const MessageLocation* loc,
                                   Handle<Object> message_obj);
  static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
rmcilroy's avatar
rmcilroy committed
439 440
  static base::SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
                                                           Handle<Object> data);
441
};
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481


class ErrorToStringHelper {
 public:
  ErrorToStringHelper() : visited_(0) {}

  MUST_USE_RESULT MaybeHandle<String> Stringify(Isolate* isolate,
                                                Handle<JSObject> error);

 private:
  class VisitedScope {
   public:
    VisitedScope(ErrorToStringHelper* helper, Handle<JSObject> error)
        : helper_(helper), has_visited_(false) {
      for (const Handle<JSObject>& visited : helper->visited_) {
        if (visited.is_identical_to(error)) {
          has_visited_ = true;
          break;
        }
      }
      helper->visited_.Add(error);
    }
    ~VisitedScope() { helper_->visited_.RemoveLast(); }
    bool has_visited() { return has_visited_; }

   private:
    ErrorToStringHelper* helper_;
    bool has_visited_;
  };

  static bool ShadowsInternalError(Isolate* isolate,
                                   LookupIterator* property_lookup,
                                   LookupIterator* internal_error_lookup);

  static MUST_USE_RESULT MaybeHandle<String> GetStringifiedProperty(
      Isolate* isolate, LookupIterator* property_lookup,
      Handle<String> default_value);

  List<Handle<JSObject> > visited_;
};
482 483 484
} }  // namespace v8::internal

#endif  // V8_MESSAGES_H_