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