OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 return IS_GLOBAL(this.receiver); | 622 return IS_GLOBAL(this.receiver); |
623 }; | 623 }; |
624 | 624 |
625 CallSite.prototype.isEval = function () { | 625 CallSite.prototype.isEval = function () { |
626 var script = %FunctionGetScript(this.fun); | 626 var script = %FunctionGetScript(this.fun); |
627 return script && script.compilation_type == 1; | 627 return script && script.compilation_type == 1; |
628 }; | 628 }; |
629 | 629 |
630 CallSite.prototype.getEvalOrigin = function () { | 630 CallSite.prototype.getEvalOrigin = function () { |
631 var script = %FunctionGetScript(this.fun); | 631 var script = %FunctionGetScript(this.fun); |
632 if (!script || script.compilation_type != 1) | 632 return FormatEvalOrigin(script); |
633 return null; | |
634 return new CallSite(null, script.eval_from_function, | |
635 script.eval_from_position); | |
636 }; | 633 }; |
637 | 634 |
638 CallSite.prototype.getFunction = function () { | 635 CallSite.prototype.getFunction = function () { |
639 return this.fun; | 636 return this.fun; |
640 }; | 637 }; |
641 | 638 |
642 CallSite.prototype.getFunctionName = function () { | 639 CallSite.prototype.getFunctionName = function () { |
643 // See if the function knows its own name | 640 // See if the function knows its own name |
644 var name = this.fun.name; | 641 var name = this.fun.name; |
645 if (name) { | 642 if (name) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 }; | 690 }; |
694 | 691 |
695 CallSite.prototype.getColumnNumber = function () { | 692 CallSite.prototype.getColumnNumber = function () { |
696 if (this.pos == -1) | 693 if (this.pos == -1) |
697 return null; | 694 return null; |
698 var script = %FunctionGetScript(this.fun); | 695 var script = %FunctionGetScript(this.fun); |
699 var location = null; | 696 var location = null; |
700 if (script) { | 697 if (script) { |
701 location = script.locationFromPosition(this.pos, true); | 698 location = script.locationFromPosition(this.pos, true); |
702 } | 699 } |
703 return location ? location.column : null; | 700 return location ? location.column + 1: null; |
704 }; | 701 }; |
705 | 702 |
706 CallSite.prototype.isNative = function () { | 703 CallSite.prototype.isNative = function () { |
707 var script = %FunctionGetScript(this.fun); | 704 var script = %FunctionGetScript(this.fun); |
708 return script ? (script.type == 0) : false; | 705 return script ? (script.type == 0) : false; |
709 }; | 706 }; |
710 | 707 |
711 CallSite.prototype.getPosition = function () { | 708 CallSite.prototype.getPosition = function () { |
712 return this.pos; | 709 return this.pos; |
713 }; | 710 }; |
714 | 711 |
715 CallSite.prototype.isConstructor = function () { | 712 CallSite.prototype.isConstructor = function () { |
716 var constructor = this.receiver ? this.receiver.constructor : null; | 713 var constructor = this.receiver ? this.receiver.constructor : null; |
717 if (!constructor) | 714 if (!constructor) |
718 return false; | 715 return false; |
719 return this.fun === constructor; | 716 return this.fun === constructor; |
720 }; | 717 }; |
721 | 718 |
| 719 function FormatEvalOrigin(script) { |
| 720 var eval_origin = ""; |
| 721 if (script.eval_from_function_name) { |
| 722 eval_origin += script.eval_from_function_name; |
| 723 } else { |
| 724 eval_origin += "<anonymous>"; |
| 725 } |
| 726 |
| 727 var eval_from_script = script.eval_from_script; |
| 728 if (eval_from_script) { |
| 729 if (eval_from_script.compilation_type == 1) { |
| 730 // eval script originated from another eval. |
| 731 eval_origin += " (eval at " + FormatEvalOrigin(eval_from_script) + ")"; |
| 732 } else { |
| 733 // eval script originated from "real" scource. |
| 734 if (eval_from_script.name) { |
| 735 eval_origin += " (" + eval_from_script.name; |
| 736 var location = eval_from_script.locationFromPosition(script.eval_from_sc
ript_position, true); |
| 737 if (location) { |
| 738 eval_origin += ":" + (location.line + 1); |
| 739 eval_origin += ":" + (location.column + 1); |
| 740 } |
| 741 eval_origin += ")" |
| 742 } else { |
| 743 eval_origin += " (unknown source)"; |
| 744 } |
| 745 } |
| 746 } |
| 747 |
| 748 return eval_origin; |
| 749 }; |
| 750 |
722 function FormatSourcePosition(frame) { | 751 function FormatSourcePosition(frame) { |
723 var fileLocation = ""; | 752 var fileLocation = ""; |
724 if (frame.isNative()) { | 753 if (frame.isNative()) { |
725 fileLocation = "native"; | 754 fileLocation = "native"; |
726 } else if (frame.isEval()) { | 755 } else if (frame.isEval()) { |
727 fileLocation = "eval at " + FormatSourcePosition(frame.getEvalOrigin()); | 756 fileLocation = "eval at " + frame.getEvalOrigin(); |
728 } else { | 757 } else { |
729 var fileName = frame.getFileName(); | 758 var fileName = frame.getFileName(); |
730 if (fileName) { | 759 if (fileName) { |
731 fileLocation += fileName; | 760 fileLocation += fileName; |
732 var lineNumber = frame.getLineNumber(); | 761 var lineNumber = frame.getLineNumber(); |
733 if (lineNumber != null) { | 762 if (lineNumber != null) { |
734 fileLocation += ":" + lineNumber; | 763 fileLocation += ":" + lineNumber; |
735 var columnNumber = frame.getColumnNumber(); | 764 var columnNumber = frame.getColumnNumber(); |
736 if (columnNumber) { | 765 if (columnNumber) { |
737 fileLocation += ":" + columnNumber; | 766 fileLocation += ":" + columnNumber; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); | 921 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); |
893 } | 922 } |
894 var message = this.message; | 923 var message = this.message; |
895 return this.name + (message ? (": " + message) : ""); | 924 return this.name + (message ? (": " + message) : ""); |
896 }, DONT_ENUM); | 925 }, DONT_ENUM); |
897 | 926 |
898 | 927 |
899 // Boilerplate for exceptions for stack overflows. Used from | 928 // Boilerplate for exceptions for stack overflows. Used from |
900 // Top::StackOverflow(). | 929 // Top::StackOverflow(). |
901 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 930 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |