OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 // ------------------------------------------------------------------- | 5 // ------------------------------------------------------------------- |
6 | 6 |
7 var kMessages = { | 7 var kMessages = { |
8 // Error | 8 // Error |
9 cyclic_proto: ["Cyclic __proto__ value"], | 9 cyclic_proto: ["Cyclic __proto__ value"], |
10 code_gen_from_strings: ["%0"], | 10 code_gen_from_strings: ["%0"], |
(...skipping 21 matching lines...) Expand all Loading... |
32 newline_after_throw: ["Illegal newline after throw"], | 32 newline_after_throw: ["Illegal newline after throw"], |
33 label_redeclaration: ["Label '", "%0", "' has already been declared"
], | 33 label_redeclaration: ["Label '", "%0", "' has already been declared"
], |
34 var_redeclaration: ["Identifier '", "%0", "' has already been decl
ared"], | 34 var_redeclaration: ["Identifier '", "%0", "' has already been decl
ared"], |
35 duplicate_template_property: ["Object template has duplicate property '", "%
0", "'"], | 35 duplicate_template_property: ["Object template has duplicate property '", "%
0", "'"], |
36 no_catch_or_finally: ["Missing catch or finally after try"], | 36 no_catch_or_finally: ["Missing catch or finally after try"], |
37 unknown_label: ["Undefined label '", "%0", "'"], | 37 unknown_label: ["Undefined label '", "%0", "'"], |
38 uncaught_exception: ["Uncaught ", "%0"], | 38 uncaught_exception: ["Uncaught ", "%0"], |
39 stack_trace: ["Stack Trace:\n", "%0"], | 39 stack_trace: ["Stack Trace:\n", "%0"], |
40 called_non_callable: ["%0", " is not a function"], | 40 called_non_callable: ["%0", " is not a function"], |
41 undefined_method: ["Object ", "%1", " has no method '", "%0", "'"
], | 41 undefined_method: ["Object ", "%1", " has no method '", "%0", "'"
], |
42 property_not_function: ["Property '", "%0", "' of object ", "%1", " is
not a function"], | |
43 cannot_convert_to_primitive: ["Cannot convert object to primitive value"], | 42 cannot_convert_to_primitive: ["Cannot convert object to primitive value"], |
44 not_constructor: ["%0", " is not a constructor"], | 43 not_constructor: ["%0", " is not a constructor"], |
45 not_defined: ["%0", " is not defined"], | 44 not_defined: ["%0", " is not defined"], |
46 non_method: ["'super' is referenced from non-method"], | 45 non_method: ["'super' is referenced from non-method"], |
47 unsupported_super: ["Unsupported reference to 'super'"], | 46 unsupported_super: ["Unsupported reference to 'super'"], |
48 non_object_property_load: ["Cannot read property '", "%0", "' of ", "%1"]
, | 47 non_object_property_load: ["Cannot read property '", "%0", "' of ", "%1"]
, |
49 non_object_property_store: ["Cannot set property '", "%0", "' of ", "%1"], | 48 non_object_property_store: ["Cannot set property '", "%0", "' of ", "%1"], |
50 with_expression: ["%0", " has no properties"], | |
51 illegal_invocation: ["Illegal invocation"], | 49 illegal_invocation: ["Illegal invocation"], |
52 no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1", "
which has only a getter"], | 50 no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1", "
which has only a getter"], |
53 apply_non_function: ["Function.prototype.apply was called on ", "%0
", ", which is a ", "%1", " and not a function"], | 51 apply_non_function: ["Function.prototype.apply was called on ", "%0
", ", which is a ", "%1", " and not a function"], |
54 apply_wrong_args: ["Function.prototype.apply: Arguments list has
wrong type"], | 52 apply_wrong_args: ["Function.prototype.apply: Arguments list has
wrong type"], |
55 reflect_apply_wrong_args: ["Reflect.apply: Arguments list has wrong type"
], | 53 reflect_apply_wrong_args: ["Reflect.apply: Arguments list has wrong type"
], |
56 reflect_construct_wrong_args: ["Reflect.construct: Arguments list has wrong t
ype"], | 54 reflect_construct_wrong_args: ["Reflect.construct: Arguments list has wrong t
ype"], |
57 flags_getter_non_object: ["RegExp.prototype.flags getter called on non-o
bject ", "%0"], | 55 flags_getter_non_object: ["RegExp.prototype.flags getter called on non-o
bject ", "%0"], |
58 invalid_in_operator_use: ["Cannot use 'in' operator to search for '", "%
0", "' in ", "%1"], | 56 invalid_in_operator_use: ["Cannot use 'in' operator to search for '", "%
0", "' in ", "%1"], |
59 instanceof_function_expected: ["Expecting a function in instanceof check, but
got ", "%0"], | 57 instanceof_function_expected: ["Expecting a function in instanceof check, but
got ", "%0"], |
60 instanceof_nonobject_proto: ["Function has non-object prototype '", "%0", "
' in instanceof check"], | 58 instanceof_nonobject_proto: ["Function has non-object prototype '", "%0", "
' in instanceof check"], |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return ToStringCheckErrorObject(obj); | 316 return ToStringCheckErrorObject(obj); |
319 } | 317 } |
320 | 318 |
321 | 319 |
322 function MakeGenericError(constructor, type, args) { | 320 function MakeGenericError(constructor, type, args) { |
323 if (IS_UNDEFINED(args)) args = []; | 321 if (IS_UNDEFINED(args)) args = []; |
324 return new constructor(FormatMessage(type, args)); | 322 return new constructor(FormatMessage(type, args)); |
325 } | 323 } |
326 | 324 |
327 | 325 |
| 326 function MakeGenericError2(constructor, type, arg0, arg1, arg2) { |
| 327 return new constructor(FormatMessage(type, arg0, arg1, arg2)); |
| 328 } |
| 329 |
| 330 |
328 /** | 331 /** |
329 * Set up the Script function and constructor. | 332 * Set up the Script function and constructor. |
330 */ | 333 */ |
331 %FunctionSetInstanceClassName(Script, 'Script'); | 334 %FunctionSetInstanceClassName(Script, 'Script'); |
332 %AddNamedProperty(Script.prototype, 'constructor', Script, | 335 %AddNamedProperty(Script.prototype, 'constructor', Script, |
333 DONT_ENUM | DONT_DELETE | READ_ONLY); | 336 DONT_ENUM | DONT_DELETE | READ_ONLY); |
334 %SetCode(Script, function(x) { | 337 %SetCode(Script, function(x) { |
335 // Script objects can only be created by the VM. | 338 // Script objects can only be created by the VM. |
336 throw new $Error("Not supported"); | 339 throw new $Error("Not supported"); |
337 }); | 340 }); |
338 | 341 |
339 | 342 |
340 // Helper functions; called from the runtime system. | 343 // Helper functions; called from the runtime system. |
341 function FormatMessage(type, args) { | 344 function FormatMessage(type, arg0, arg1, arg2) { |
| 345 if (IS_NUMBER(type)) { |
| 346 var arg0 = NoSideEffectToString(arg0); |
| 347 var arg1 = NoSideEffectToString(arg1); |
| 348 var arg2 = NoSideEffectToString(arg2); |
| 349 try { |
| 350 return %FormatMessageString(type, arg0, arg1, arg2); |
| 351 } catch (e) { |
| 352 return ""; |
| 353 } |
| 354 } |
| 355 // TODO(yangguo): remove this code path once we migrated all messages. |
342 var format = kMessages[type]; | 356 var format = kMessages[type]; |
343 if (!format) return "<unknown message " + type + ">"; | 357 if (!format) return "<unknown message " + type + ">"; |
344 return FormatString(format, args); | 358 return FormatString(format, arg0); |
345 } | 359 } |
346 | 360 |
347 | 361 |
348 function GetLineNumber(message) { | 362 function GetLineNumber(message) { |
349 var start_position = %MessageGetStartPosition(message); | 363 var start_position = %MessageGetStartPosition(message); |
350 if (start_position == -1) return kNoLineNumberInfo; | 364 if (start_position == -1) return kNoLineNumberInfo; |
351 var script = %MessageGetScript(message); | 365 var script = %MessageGetScript(message); |
352 var location = script.locationFromPosition(start_position, true); | 366 var location = script.locationFromPosition(start_position, true); |
353 if (location == null) return kNoLineNumberInfo; | 367 if (location == null) return kNoLineNumberInfo; |
354 return location.line + 1; | 368 return location.line + 1; |
355 } | 369 } |
356 | 370 |
357 | 371 |
358 // Returns the source code line containing the given source | 372 // Returns the source code line containing the given source |
359 // position, or the empty string if the position is invalid. | 373 // position, or the empty string if the position is invalid. |
360 function GetSourceLine(message) { | 374 function GetSourceLine(message) { |
361 var script = %MessageGetScript(message); | 375 var script = %MessageGetScript(message); |
362 var start_position = %MessageGetStartPosition(message); | 376 var start_position = %MessageGetStartPosition(message); |
363 var location = script.locationFromPosition(start_position, true); | 377 var location = script.locationFromPosition(start_position, true); |
364 if (location == null) return ""; | 378 if (location == null) return ""; |
365 return location.sourceText(); | 379 return location.sourceText(); |
366 } | 380 } |
367 | 381 |
368 | 382 |
369 function MakeTypeError(type, args) { | 383 function MakeTypeError(type, args) { |
370 return MakeGenericError($TypeError, type, args); | 384 return MakeGenericError($TypeError, type, args); |
371 } | 385 } |
372 | 386 |
373 | 387 |
| 388 // TODO(yangguo): rename this once we migrated all messages. |
| 389 function MakeTypeError2(type, arg0, arg1, arg2) { |
| 390 return MakeGenericError2($TypeError, type, arg0, arg1, arg2); |
| 391 } |
| 392 |
| 393 |
374 function MakeRangeError(type, args) { | 394 function MakeRangeError(type, args) { |
375 return MakeGenericError($RangeError, type, args); | 395 return MakeGenericError($RangeError, type, args); |
376 } | 396 } |
377 | 397 |
378 | 398 |
379 function MakeSyntaxError(type, args) { | 399 function MakeSyntaxError(type, args) { |
380 return MakeGenericError($SyntaxError, type, args); | 400 return MakeGenericError($SyntaxError, type, args); |
381 } | 401 } |
382 | 402 |
383 | 403 |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 function SetUpStackOverflowBoilerplate() { | 1310 function SetUpStackOverflowBoilerplate() { |
1291 var boilerplate = MakeRangeError('stack_overflow', []); | 1311 var boilerplate = MakeRangeError('stack_overflow', []); |
1292 | 1312 |
1293 %DefineAccessorPropertyUnchecked( | 1313 %DefineAccessorPropertyUnchecked( |
1294 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); | 1314 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); |
1295 | 1315 |
1296 return boilerplate; | 1316 return boilerplate; |
1297 } | 1317 } |
1298 | 1318 |
1299 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1319 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |