| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 346 } |
| 347 | 347 |
| 348 | 348 |
| 349 // Returns the source code line containing the given source | 349 // Returns the source code line containing the given source |
| 350 // position, or the empty string if the position is invalid. | 350 // position, or the empty string if the position is invalid. |
| 351 function GetSourceLine(message) { | 351 function GetSourceLine(message) { |
| 352 var script = %MessageGetScript(message); | 352 var script = %MessageGetScript(message); |
| 353 var start_position = %MessageGetStartPosition(message); | 353 var start_position = %MessageGetStartPosition(message); |
| 354 var location = script.locationFromPosition(start_position, true); | 354 var location = script.locationFromPosition(start_position, true); |
| 355 if (location == null) return ""; | 355 if (location == null) return ""; |
| 356 location.restrict(); | |
| 357 return location.sourceText(); | 356 return location.sourceText(); |
| 358 } | 357 } |
| 359 | 358 |
| 360 | 359 |
| 361 function MakeTypeError(type, args) { | 360 function MakeTypeError(type, args) { |
| 362 return MakeGenericError($TypeError, type, args); | 361 return MakeGenericError($TypeError, type, args); |
| 363 } | 362 } |
| 364 | 363 |
| 365 | 364 |
| 366 function MakeRangeError(type, args) { | 365 function MakeRangeError(type, args) { |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 */ | 646 */ |
| 648 function SourceLocation(script, position, line, column, start, end) { | 647 function SourceLocation(script, position, line, column, start, end) { |
| 649 this.script = script; | 648 this.script = script; |
| 650 this.position = position; | 649 this.position = position; |
| 651 this.line = line; | 650 this.line = line; |
| 652 this.column = column; | 651 this.column = column; |
| 653 this.start = start; | 652 this.start = start; |
| 654 this.end = end; | 653 this.end = end; |
| 655 } | 654 } |
| 656 | 655 |
| 657 var kLineLengthLimit = 78; | |
| 658 | |
| 659 /** | |
| 660 * Restrict source location start and end positions to make the source slice | |
| 661 * no more that a certain number of characters wide. | |
| 662 * @param {number} opt_limit The with limit of the source text with a default | |
| 663 * of 78 | |
| 664 * @param {number} opt_before The number of characters to prefer before the | |
| 665 * position with a default value of 10 less that the limit | |
| 666 */ | |
| 667 function SourceLocationRestrict(opt_limit, opt_before) { | |
| 668 // Find the actual limit to use. | |
| 669 var limit; | |
| 670 var before; | |
| 671 if (!IS_UNDEFINED(opt_limit)) { | |
| 672 limit = opt_limit; | |
| 673 } else { | |
| 674 limit = kLineLengthLimit; | |
| 675 } | |
| 676 if (!IS_UNDEFINED(opt_before)) { | |
| 677 before = opt_before; | |
| 678 } else { | |
| 679 // If no before is specified center for small limits and perfer more source | |
| 680 // before the the position that after for longer limits. | |
| 681 if (limit <= 20) { | |
| 682 before = $floor(limit / 2); | |
| 683 } else { | |
| 684 before = limit - 10; | |
| 685 } | |
| 686 } | |
| 687 if (before >= limit) { | |
| 688 before = limit - 1; | |
| 689 } | |
| 690 | |
| 691 // If the [start, end[ interval is too big we restrict | |
| 692 // it in one or both ends. We make sure to always produce | |
| 693 // restricted intervals of maximum allowed size. | |
| 694 if (this.end - this.start > limit) { | |
| 695 var start_limit = this.position - before; | |
| 696 var end_limit = this.position + limit - before; | |
| 697 if (this.start < start_limit && end_limit < this.end) { | |
| 698 this.start = start_limit; | |
| 699 this.end = end_limit; | |
| 700 } else if (this.start < start_limit) { | |
| 701 this.start = this.end - limit; | |
| 702 } else { | |
| 703 this.end = this.start + limit; | |
| 704 } | |
| 705 } | |
| 706 } | |
| 707 | |
| 708 | 656 |
| 709 /** | 657 /** |
| 710 * Get the source text for a SourceLocation | 658 * Get the source text for a SourceLocation |
| 711 * @return {String} | 659 * @return {String} |
| 712 * Source text for this location. | 660 * Source text for this location. |
| 713 */ | 661 */ |
| 714 function SourceLocationSourceText() { | 662 function SourceLocationSourceText() { |
| 715 return %_CallFunction(this.script.source, | 663 return %_CallFunction(this.script.source, |
| 716 this.start, | 664 this.start, |
| 717 this.end, | 665 this.end, |
| 718 $stringSubstring); | 666 $stringSubstring); |
| 719 } | 667 } |
| 720 | 668 |
| 721 | 669 |
| 722 SetUpLockedPrototype(SourceLocation, | 670 SetUpLockedPrototype(SourceLocation, |
| 723 $Array("script", "position", "line", "column", "start", "end"), | 671 $Array("script", "position", "line", "column", "start", "end"), |
| 724 $Array( | 672 $Array( |
| 725 "restrict", SourceLocationRestrict, | |
| 726 "sourceText", SourceLocationSourceText | 673 "sourceText", SourceLocationSourceText |
| 727 ) | 674 ) |
| 728 ); | 675 ); |
| 729 | 676 |
| 730 | 677 |
| 731 /** | 678 /** |
| 732 * Class for a source slice. A source slice is a part of a script source with | 679 * Class for a source slice. A source slice is a part of a script source with |
| 733 * the following properties: | 680 * the following properties: |
| 734 * script : script object for the source | 681 * script : script object for the source |
| 735 * from_line : line number for the first line in the slice | 682 * from_line : line number for the first line in the slice |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 ); | 719 ); |
| 773 | 720 |
| 774 | 721 |
| 775 // Returns the offset of the given position within the containing | 722 // Returns the offset of the given position within the containing |
| 776 // line. | 723 // line. |
| 777 function GetPositionInLine(message) { | 724 function GetPositionInLine(message) { |
| 778 var script = %MessageGetScript(message); | 725 var script = %MessageGetScript(message); |
| 779 var start_position = %MessageGetStartPosition(message); | 726 var start_position = %MessageGetStartPosition(message); |
| 780 var location = script.locationFromPosition(start_position, false); | 727 var location = script.locationFromPosition(start_position, false); |
| 781 if (location == null) return -1; | 728 if (location == null) return -1; |
| 782 location.restrict(); | |
| 783 return start_position - location.start; | 729 return start_position - location.start; |
| 784 } | 730 } |
| 785 | 731 |
| 786 | 732 |
| 787 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 733 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
| 788 return new CallSite(recv, fun, pos, false).toString(); | 734 return new CallSite(recv, fun, pos, false).toString(); |
| 789 } | 735 } |
| 790 | 736 |
| 791 // ---------------------------------------------------------------------------- | 737 // ---------------------------------------------------------------------------- |
| 792 // Error implementation | 738 // Error implementation |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 function SetUpStackOverflowBoilerplate() { | 1274 function SetUpStackOverflowBoilerplate() { |
| 1329 var boilerplate = MakeRangeError('stack_overflow', []); | 1275 var boilerplate = MakeRangeError('stack_overflow', []); |
| 1330 | 1276 |
| 1331 %DefineAccessorPropertyUnchecked( | 1277 %DefineAccessorPropertyUnchecked( |
| 1332 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); | 1278 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); |
| 1333 | 1279 |
| 1334 return boilerplate; | 1280 return boilerplate; |
| 1335 } | 1281 } |
| 1336 | 1282 |
| 1337 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1283 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
| OLD | NEW |