| 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(); |
| 355 return location.sourceText(); | 356 return location.sourceText(); |
| 356 } | 357 } |
| 357 | 358 |
| 358 | 359 |
| 359 function MakeTypeError(type, args) { | 360 function MakeTypeError(type, args) { |
| 360 return MakeGenericError($TypeError, type, args); | 361 return MakeGenericError($TypeError, type, args); |
| 361 } | 362 } |
| 362 | 363 |
| 363 | 364 |
| 364 function MakeRangeError(type, args) { | 365 function MakeRangeError(type, args) { |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 */ | 646 */ |
| 646 function SourceLocation(script, position, line, column, start, end) { | 647 function SourceLocation(script, position, line, column, start, end) { |
| 647 this.script = script; | 648 this.script = script; |
| 648 this.position = position; | 649 this.position = position; |
| 649 this.line = line; | 650 this.line = line; |
| 650 this.column = column; | 651 this.column = column; |
| 651 this.start = start; | 652 this.start = start; |
| 652 this.end = end; | 653 this.end = end; |
| 653 } | 654 } |
| 654 | 655 |
| 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 |
| 655 | 707 |
| 656 /** | 708 /** |
| 657 * Get the source text for a SourceLocation | 709 * Get the source text for a SourceLocation |
| 658 * @return {String} | 710 * @return {String} |
| 659 * Source text for this location. | 711 * Source text for this location. |
| 660 */ | 712 */ |
| 661 function SourceLocationSourceText() { | 713 function SourceLocationSourceText() { |
| 662 return %_CallFunction(this.script.source, | 714 return %_CallFunction(this.script.source, |
| 663 this.start, | 715 this.start, |
| 664 this.end, | 716 this.end, |
| 665 $stringSubstring); | 717 $stringSubstring); |
| 666 } | 718 } |
| 667 | 719 |
| 668 | 720 |
| 669 SetUpLockedPrototype(SourceLocation, | 721 SetUpLockedPrototype(SourceLocation, |
| 670 $Array("script", "position", "line", "column", "start", "end"), | 722 $Array("script", "position", "line", "column", "start", "end"), |
| 671 $Array( | 723 $Array( |
| 724 "restrict", SourceLocationRestrict, |
| 672 "sourceText", SourceLocationSourceText | 725 "sourceText", SourceLocationSourceText |
| 673 ) | 726 ) |
| 674 ); | 727 ); |
| 675 | 728 |
| 676 | 729 |
| 677 /** | 730 /** |
| 678 * Class for a source slice. A source slice is a part of a script source with | 731 * Class for a source slice. A source slice is a part of a script source with |
| 679 * the following properties: | 732 * the following properties: |
| 680 * script : script object for the source | 733 * script : script object for the source |
| 681 * from_line : line number for the first line in the slice | 734 * from_line : line number for the first line in the slice |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 ); | 771 ); |
| 719 | 772 |
| 720 | 773 |
| 721 // Returns the offset of the given position within the containing | 774 // Returns the offset of the given position within the containing |
| 722 // line. | 775 // line. |
| 723 function GetPositionInLine(message) { | 776 function GetPositionInLine(message) { |
| 724 var script = %MessageGetScript(message); | 777 var script = %MessageGetScript(message); |
| 725 var start_position = %MessageGetStartPosition(message); | 778 var start_position = %MessageGetStartPosition(message); |
| 726 var location = script.locationFromPosition(start_position, false); | 779 var location = script.locationFromPosition(start_position, false); |
| 727 if (location == null) return -1; | 780 if (location == null) return -1; |
| 781 location.restrict(); |
| 728 return start_position - location.start; | 782 return start_position - location.start; |
| 729 } | 783 } |
| 730 | 784 |
| 731 | 785 |
| 732 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 786 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
| 733 return new CallSite(recv, fun, pos, false).toString(); | 787 return new CallSite(recv, fun, pos, false).toString(); |
| 734 } | 788 } |
| 735 | 789 |
| 736 // ---------------------------------------------------------------------------- | 790 // ---------------------------------------------------------------------------- |
| 737 // Error implementation | 791 // Error implementation |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 function SetUpStackOverflowBoilerplate() { | 1327 function SetUpStackOverflowBoilerplate() { |
| 1274 var boilerplate = MakeRangeError('stack_overflow', []); | 1328 var boilerplate = MakeRangeError('stack_overflow', []); |
| 1275 | 1329 |
| 1276 %DefineAccessorPropertyUnchecked( | 1330 %DefineAccessorPropertyUnchecked( |
| 1277 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); | 1331 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); |
| 1278 | 1332 |
| 1279 return boilerplate; | 1333 return boilerplate; |
| 1280 } | 1334 } |
| 1281 | 1335 |
| 1282 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1336 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
| OLD | NEW |