Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/messages.h

Issue 1130133003: Migrate error messages, part 12. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@messages_11
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/isolate.cc ('k') | src/messages.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The infrastructure used for (localized) message reporting in V8. 5 // The infrastructure used for (localized) message reporting in V8.
6 // 6 //
7 // Note: there's a big unresolved issue about ownership of the data 7 // Note: there's a big unresolved issue about ownership of the data
8 // structures used by this framework. 8 // structures used by this framework.
9 9
10 #ifndef V8_MESSAGES_H_ 10 #ifndef V8_MESSAGES_H_
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 Handle<JSFunction> function() const { return function_; } 55 Handle<JSFunction> function() const { return function_; }
56 56
57 private: 57 private:
58 Handle<Script> script_; 58 Handle<Script> script_;
59 int start_pos_; 59 int start_pos_;
60 int end_pos_; 60 int end_pos_;
61 Handle<JSFunction> function_; 61 Handle<JSFunction> function_;
62 }; 62 };
63 63
64 64
65 // A message handler is a convenience interface for accessing the list
66 // of message listeners registered in an environment
67 class MessageHandler {
68 public:
69 // Returns a message object for the API to use.
70 static Handle<JSMessageObject> MakeMessageObject(
71 Isolate* isolate,
72 const char* type,
73 MessageLocation* loc,
74 Vector< Handle<Object> > args,
75 Handle<JSArray> stack_frames);
76
77 // Report a formatted message (needs JS allocation).
78 static void ReportMessage(Isolate* isolate,
79 MessageLocation* loc,
80 Handle<Object> message);
81
82 static void DefaultMessageReport(Isolate* isolate,
83 const MessageLocation* loc,
84 Handle<Object> message_obj);
85 static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
86 static SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
87 Handle<Object> data);
88 };
89
90
91 class CallSite { 65 class CallSite {
92 public: 66 public:
93 CallSite(Handle<Object> receiver, Handle<JSFunction> fun, int pos) 67 CallSite(Handle<Object> receiver, Handle<JSFunction> fun, int pos)
94 : receiver_(receiver), fun_(fun), pos_(pos) {} 68 : receiver_(receiver), fun_(fun), pos_(pos) {}
95 69
96 Handle<Object> GetFileName(Isolate* isolate); 70 Handle<Object> GetFileName(Isolate* isolate);
97 Handle<Object> GetFunctionName(Isolate* isolate); 71 Handle<Object> GetFunctionName(Isolate* isolate);
98 Handle<Object> GetScriptNameOrSourceUrl(Isolate* isolate); 72 Handle<Object> GetScriptNameOrSourceUrl(Isolate* isolate);
99 Handle<Object> GetMethodName(Isolate* isolate); 73 Handle<Object> GetMethodName(Isolate* isolate);
100 // Return 1-based line number, including line offset. 74 // Return 1-based line number, including line offset.
101 int GetLineNumber(Isolate* isolate); 75 int GetLineNumber(Isolate* isolate);
102 // Return 1-based column number, including column offset if first line. 76 // Return 1-based column number, including column offset if first line.
103 int GetColumnNumber(Isolate* isolate); 77 int GetColumnNumber(Isolate* isolate);
104 bool IsNative(Isolate* isolate); 78 bool IsNative(Isolate* isolate);
105 bool IsToplevel(Isolate* isolate); 79 bool IsToplevel(Isolate* isolate);
106 bool IsEval(Isolate* isolate); 80 bool IsEval(Isolate* isolate);
107 bool IsConstructor(Isolate* isolate); 81 bool IsConstructor(Isolate* isolate);
108 82
109 private: 83 private:
110 Handle<Object> receiver_; 84 Handle<Object> receiver_;
111 Handle<JSFunction> fun_; 85 Handle<JSFunction> fun_;
112 int pos_; 86 int pos_;
113 }; 87 };
114 88
115 89
116 #define MESSAGE_TEMPLATES(T) \ 90 #define MESSAGE_TEMPLATES(T) \
117 /* Error */ \ 91 /* Error */ \
92 T(None, "") \
118 T(CyclicProto, "Cyclic __proto__ value") \ 93 T(CyclicProto, "Cyclic __proto__ value") \
94 T(DebuggerLoading, "Error loading debugger") \
119 T(DefaultOptionsMissing, "Internal % error. Default options are missing.") \ 95 T(DefaultOptionsMissing, "Internal % error. Default options are missing.") \
96 T(UncaughtException, "Uncaught %") \
120 T(Unsupported, "Not supported") \ 97 T(Unsupported, "Not supported") \
121 T(WrongServiceType, "Internal error, wrong service type: %") \ 98 T(WrongServiceType, "Internal error, wrong service type: %") \
122 T(WrongValueType, "Internal error. Wrong value type.") \ 99 T(WrongValueType, "Internal error. Wrong value type.") \
123 /* TypeError */ \ 100 /* TypeError */ \
124 T(ApplyNonFunction, \ 101 T(ApplyNonFunction, \
125 "Function.prototype.apply was called on %, which is a % and not a " \ 102 "Function.prototype.apply was called on %, which is a % and not a " \
126 "function") \ 103 "function") \
127 T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements") \ 104 T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements") \
128 T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements") \ 105 T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements") \
129 T(ArrayNotSubclassable, "Subclassing Arrays is not currently supported.") \ 106 T(ArrayNotSubclassable, "Subclassing Arrays is not currently supported.") \
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \ 234 T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \
258 T(ValueAndAccessor, \ 235 T(ValueAndAccessor, \
259 "Invalid property. A property cannot both have accessors and be " \ 236 "Invalid property. A property cannot both have accessors and be " \
260 "writable or have a value, %") \ 237 "writable or have a value, %") \
261 T(VarRedeclaration, "Identifier '%' has already been declared") \ 238 T(VarRedeclaration, "Identifier '%' has already been declared") \
262 T(WithExpression, "% has no properties") \ 239 T(WithExpression, "% has no properties") \
263 T(WrongArgs, "%: Arguments list has wrong type") \ 240 T(WrongArgs, "%: Arguments list has wrong type") \
264 /* ReferenceError */ \ 241 /* ReferenceError */ \
265 T(NonMethod, "'super' is referenced from non-method") \ 242 T(NonMethod, "'super' is referenced from non-method") \
266 T(NotDefined, "% is not defined") \ 243 T(NotDefined, "% is not defined") \
244 T(StrongSuperCallMissing, \
245 "In strong mode, invoking the super constructor in a subclass is " \
246 "required") \
247 T(StrongUnboundGlobal, \
248 "In strong mode, using an undeclared global variable '%' is not allowed") \
267 T(UnsupportedSuper, "Unsupported reference to 'super'") \ 249 T(UnsupportedSuper, "Unsupported reference to 'super'") \
268 /* RangeError */ \ 250 /* RangeError */ \
269 T(ArrayLengthOutOfRange, "defineProperty() array length out of range") \ 251 T(ArrayLengthOutOfRange, "defineProperty() array length out of range") \
270 T(DateRange, "Provided date is not in valid range.") \ 252 T(DateRange, "Provided date is not in valid range.") \
271 T(ExpectedLocation, "Expected Area/Location for time zone, got %") \ 253 T(ExpectedLocation, "Expected Area/Location for time zone, got %") \
272 T(InvalidArrayBufferLength, "Invalid array buffer length") \ 254 T(InvalidArrayBufferLength, "Invalid array buffer length") \
273 T(InvalidArrayLength, "Invalid array length") \ 255 T(InvalidArrayLength, "Invalid array length") \
274 T(InvalidCodePoint, "Invalid code point %") \ 256 T(InvalidCodePoint, "Invalid code point %") \
275 T(InvalidCountValue, "Invalid count value") \ 257 T(InvalidCountValue, "Invalid count value") \
276 T(InvalidCurrencyCode, "Invalid currency code: %") \ 258 T(InvalidCurrencyCode, "Invalid currency code: %") \
(...skipping 14 matching lines...) Expand all
291 T(NumberFormatRange, "% argument must be between 0 and 20") \ 273 T(NumberFormatRange, "% argument must be between 0 and 20") \
292 T(PropertyValueOutOfRange, "% value is out of range.") \ 274 T(PropertyValueOutOfRange, "% value is out of range.") \
293 T(StackOverflow, "Maximum call stack size exceeded") \ 275 T(StackOverflow, "Maximum call stack size exceeded") \
294 T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \ 276 T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
295 T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \ 277 T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \
296 T(TypedArraySetNegativeOffset, "Start offset is negative") \ 278 T(TypedArraySetNegativeOffset, "Start offset is negative") \
297 T(TypedArraySetSourceTooLarge, "Source is too large") \ 279 T(TypedArraySetSourceTooLarge, "Source is too large") \
298 T(UnsupportedTimeZone, "Unsupported time zone specified %") \ 280 T(UnsupportedTimeZone, "Unsupported time zone specified %") \
299 T(ValueOutOfRange, "Value % out of range for % options property %") \ 281 T(ValueOutOfRange, "Value % out of range for % options property %") \
300 /* SyntaxError */ \ 282 /* SyntaxError */ \
283 T(BadGetterArity, "Getter must not have any formal parameters.") \
284 T(BadSetterArity, "Setter must have exactly one formal parameter.") \
285 T(ConstructorIsAccessor, "Class constructor may not be an accessor") \
286 T(ConstructorIsGenerator, "Class constructor may not be a generator") \
287 T(DerivedConstructorReturn, \
288 "Derived constructors may only return object or undefined") \
289 T(DuplicateArrawFunFormalParam, \
290 "Arrow function may not have duplicate parameter names") \
291 T(DuplicateConstructor, "A class may only have one constructor") \
292 T(DuplicateExport, "Duplicate export of '%'") \
293 T(DuplicateProto, \
294 "Duplicate __proto__ fields are not allowed in object literals") \
295 T(ForInLoopInitializer, \
296 "for-in loop variable declaration may not have an initializer.") \
297 T(ForInOfLoopMultiBindings, \
298 "Invalid left-hand side in % loop: Must have a single binding.") \
299 T(ForOfLoopInitializer, \
300 "for-of loop variable declaration may not have an initializer.") \
301 T(IllegalAccess, "Illegal access") \
302 T(IllegalBreak, "Illegal break statement") \
303 T(IllegalContinue, "Illegal continue statement") \
304 T(IllegalReturn, "Illegal return statement") \
305 T(InvalidLhsInAssignment, "Invalid left-hand side in assignment") \
306 T(InvalidLhsInFor, "Invalid left-hand side in for-loop") \
307 T(InvalidLhsInPostfixOp, \
308 "Invalid left-hand side expression in postfix operation") \
309 T(InvalidLhsInPrefixOp, \
310 "Invalid left-hand side expression in prefix operation") \
301 T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \ 311 T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \
312 T(LabelRedeclaration, "Label '%' has already been declared") \
313 T(MalformedArrowFunParamList, "Malformed arrow function parameter list") \
302 T(MalformedRegExp, "Invalid regular expression: /%/: %") \ 314 T(MalformedRegExp, "Invalid regular expression: /%/: %") \
315 T(MalformedRegExpFlags, "Invalid regular expression flags") \
316 T(ModuleExportUndefined, "Export '%' is not defined in module") \
317 T(MultipleDefaultsInSwitch, \
318 "More than one default clause in switch statement") \
319 T(NewlineAfterThrow, "Illegal newline after throw") \
320 T(NoCatchOrFinally, "Missing catch or finally after try") \
321 T(NotIsvar, "builtin %%IS_VAR: not a variable") \
322 T(ParamAfterRest, "Rest parameter must be last formal parameter") \
303 T(ParenthesisInArgString, "Function arg string contains parenthesis") \ 323 T(ParenthesisInArgString, "Function arg string contains parenthesis") \
324 T(SingleFunctionLiteral, "Single function literal required") \
325 T(SloppyLexical, \
326 "Block-scoped declarations (let, const, function, class) not yet " \
327 "supported outside strict mode") \
328 T(StrictDelete, "Delete of an unqualified identifier in strict mode.") \
329 T(StrictEvalArguments, "Unexpected eval or arguments in strict mode") \
330 T(StrictFunction, \
331 "In strict mode code, functions can only be declared at top level or " \
332 "immediately within another function.") \
333 T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \
334 T(StrictParamDupe, \
335 "Strict mode function may not have duplicate parameter names") \
336 T(StrictWith, "Strict mode code may not include a with statement") \
337 T(StrongArguments, \
338 "In strong mode, 'arguments' is deprecated, use '...args' instead") \
339 T(StrongConstructorReturnMisplaced, \
340 "In strong mode, returning from a constructor before its super " \
341 "constructor invocation or all assignments to 'this' is deprecated") \
342 T(StrongConstructorReturnValue, \
343 "In strong mode, returning a value from a constructor is deprecated") \
344 T(StrongConstructorSuper, \
345 "In strong mode, 'super' can only be used to invoke the super " \
346 "constructor, and cannot be nested inside another statement or " \
347 "expression") \
348 T(StrongConstructorThis, \
349 "In strong mode, 'this' can only be used to initialize properties, and " \
350 "cannot be nested inside another statement or expression") \
351 T(StrongDelete, \
352 "In strong mode, 'delete' is deprecated, use maps or sets instead") \
353 T(StrongDirectEval, "In strong mode, direct calls to eval are deprecated") \
354 T(StrongEllision, \
355 "In strong mode, arrays with holes are deprecated, use maps instead") \
356 T(StrongEmpty, \
357 "In strong mode, empty sub-statements are deprecated, make them explicit " \
358 "with '{}' instead") \
359 T(StrongEqual, \
360 "In strong mode, '==' and '!=' are deprecated, use '===' and '!==' " \
361 "instead") \
362 T(StrongForIn, \
363 "In strong mode, 'for'-'in' loops are deprecated, use 'for'-'of' instead") \
364 T(StrongSuperCallDuplicate, \
365 "In strong mode, invoking the super constructor multiple times is " \
366 "deprecated") \
367 T(StrongSuperCallMisplaced, \
368 "In strong mode, the super constructor must be invoked before any " \
369 "assignment to 'this'") \
370 T(StrongSwitchFallthrough, \
371 "In strong mode, switch fall-through is deprecated, terminate each case " \
372 "with 'break', 'continue', 'return' or 'throw'") \
373 T(StrongUndefined, \
374 "In strong mode, binding or assigning to 'undefined' is deprecated") \
375 T(StrongUseBeforeDeclaration, \
376 "In strong mode, declaring variable '%' before its use is required") \
377 T(StrongVar, \
378 "In strong mode, 'var' is deprecated, use 'let' or 'const' instead") \
379 T(TemplateOctalLiteral, \
380 "Octal literals are not allowed in template strings.") \
381 T(ThisFormalParameter, "'this' is not a valid formal parameter name") \
382 T(TooManyArguments, \
383 "Too many arguments in function call (only 65535 allowed)") \
384 T(TooManyParameters, \
385 "Too many parameters in function definition (only 65535 allowed)") \
386 T(TooManyVariables, "Too many variables declared (only 4194303 allowed)") \
304 T(UnexpectedEOS, "Unexpected end of input") \ 387 T(UnexpectedEOS, "Unexpected end of input") \
388 T(UnexpectedReserved, "Unexpected reserved word") \
389 T(UnexpectedStrictReserved, "Unexpected strict mode reserved word") \
390 T(UnexpectedSuper, "'super' keyword unexpected here") \
391 T(UnexpectedTemplateString, "Unexpected template string") \
305 T(UnexpectedToken, "Unexpected token %") \ 392 T(UnexpectedToken, "Unexpected token %") \
393 T(UnexpectedTokenIdentifier, "Unexpected identifier") \
306 T(UnexpectedTokenNumber, "Unexpected number") \ 394 T(UnexpectedTokenNumber, "Unexpected number") \
307 T(UnexpectedTokenString, "Unexpected string") \ 395 T(UnexpectedTokenString, "Unexpected string") \
396 T(UnknownLabel, "Undefined label '%'") \
397 T(UnterminatedArgList, "missing ) after argument list") \
398 T(UnterminatedRegExp, "Invalid regular expression: missing /") \
399 T(UnterminatedTemplate, "Unterminated template literal") \
400 T(UnterminatedTemplateExpr, "Missing } in template expression") \
308 /* EvalError */ \ 401 /* EvalError */ \
309 T(CodeGenFromStrings, "%") \ 402 T(CodeGenFromStrings, "%") \
310 /* URIError */ \ 403 /* URIError */ \
311 T(URIMalformed, "URI malformed") 404 T(URIMalformed, "URI malformed")
312 405
313 class MessageTemplate { 406 class MessageTemplate {
314 public: 407 public:
315 enum Template { 408 enum Template {
316 #define TEMPLATE(NAME, STRING) k##NAME, 409 #define TEMPLATE(NAME, STRING) k##NAME,
317 MESSAGE_TEMPLATES(TEMPLATE) 410 MESSAGE_TEMPLATES(TEMPLATE)
318 #undef TEMPLATE 411 #undef TEMPLATE
319 kLastMessage 412 kLastMessage
320 }; 413 };
321 414
322 static MaybeHandle<String> FormatMessage(int template_index, 415 static MaybeHandle<String> FormatMessage(int template_index,
323 Handle<String> arg0, 416 Handle<String> arg0,
324 Handle<String> arg1, 417 Handle<String> arg1,
325 Handle<String> arg2); 418 Handle<String> arg2);
419
420 static Handle<String> FormatMessage(Isolate* isolate, int template_index,
421 Handle<Object> arg);
422 };
423
424
425 // A message handler is a convenience interface for accessing the list
426 // of message listeners registered in an environment
427 class MessageHandler {
428 public:
429 // Returns a message object for the API to use.
430 static Handle<JSMessageObject> MakeMessageObject(
431 Isolate* isolate, MessageTemplate::Template type, MessageLocation* loc,
432 Handle<Object> argument, Handle<JSArray> stack_frames);
433
434 // Report a formatted message (needs JS allocation).
435 static void ReportMessage(Isolate* isolate, MessageLocation* loc,
436 Handle<Object> message);
437
438 static void DefaultMessageReport(Isolate* isolate, const MessageLocation* loc,
439 Handle<Object> message_obj);
440 static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
441 static SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
442 Handle<Object> data);
326 }; 443 };
327 } } // namespace v8::internal 444 } } // namespace v8::internal
328 445
329 #endif // V8_MESSAGES_H_ 446 #endif // V8_MESSAGES_H_
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/messages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698