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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 CallSite.prototype.isEval = function () { | 677 CallSite.prototype.isEval = function () { |
678 var script = %FunctionGetScript(this.fun); | 678 var script = %FunctionGetScript(this.fun); |
679 return script && script.compilation_type == COMPILATION_TYPE_EVAL; | 679 return script && script.compilation_type == COMPILATION_TYPE_EVAL; |
680 }; | 680 }; |
681 | 681 |
682 CallSite.prototype.getEvalOrigin = function () { | 682 CallSite.prototype.getEvalOrigin = function () { |
683 var script = %FunctionGetScript(this.fun); | 683 var script = %FunctionGetScript(this.fun); |
684 return FormatEvalOrigin(script); | 684 return FormatEvalOrigin(script); |
685 }; | 685 }; |
686 | 686 |
| 687 CallSite.prototype.getScriptNameOrSourceURL = function () { |
| 688 var script = %FunctionGetScript(this.fun); |
| 689 return script ? script.nameOrSourceURL() : null; |
| 690 }; |
| 691 |
687 CallSite.prototype.getFunction = function () { | 692 CallSite.prototype.getFunction = function () { |
688 return this.fun; | 693 return this.fun; |
689 }; | 694 }; |
690 | 695 |
691 CallSite.prototype.getFunctionName = function () { | 696 CallSite.prototype.getFunctionName = function () { |
692 // See if the function knows its own name | 697 // See if the function knows its own name |
693 var name = this.fun.name; | 698 var name = this.fun.name; |
694 if (name) { | 699 if (name) { |
695 return name; | 700 return name; |
696 } else { | 701 } else { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 }; | 773 }; |
769 | 774 |
770 CallSite.prototype.isConstructor = function () { | 775 CallSite.prototype.isConstructor = function () { |
771 var constructor = this.receiver ? this.receiver.constructor : null; | 776 var constructor = this.receiver ? this.receiver.constructor : null; |
772 if (!constructor) | 777 if (!constructor) |
773 return false; | 778 return false; |
774 return this.fun === constructor; | 779 return this.fun === constructor; |
775 }; | 780 }; |
776 | 781 |
777 function FormatEvalOrigin(script) { | 782 function FormatEvalOrigin(script) { |
778 var eval_origin = ""; | 783 var sourceURL = script.nameOrSourceURL(); |
| 784 if (sourceURL) |
| 785 return sourceURL; |
| 786 |
| 787 var eval_origin = "eval at "; |
779 if (script.eval_from_function_name) { | 788 if (script.eval_from_function_name) { |
780 eval_origin += script.eval_from_function_name; | 789 eval_origin += script.eval_from_function_name; |
781 } else { | 790 } else { |
782 eval_origin += "<anonymous>"; | 791 eval_origin += "<anonymous>"; |
783 } | 792 } |
784 | 793 |
785 var eval_from_script = script.eval_from_script; | 794 var eval_from_script = script.eval_from_script; |
786 if (eval_from_script) { | 795 if (eval_from_script) { |
787 if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) { | 796 if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) { |
788 // eval script originated from another eval. | 797 // eval script originated from another eval. |
789 eval_origin += " (eval at " + FormatEvalOrigin(eval_from_script) + ")"; | 798 eval_origin += " (" + FormatEvalOrigin(eval_from_script) + ")"; |
790 } else { | 799 } else { |
791 // eval script originated from "real" scource. | 800 // eval script originated from "real" scource. |
792 if (eval_from_script.name) { | 801 if (eval_from_script.name) { |
793 eval_origin += " (" + eval_from_script.name; | 802 eval_origin += " (" + eval_from_script.name; |
794 var location = eval_from_script.locationFromPosition(script.eval_from_sc
ript_position, true); | 803 var location = eval_from_script.locationFromPosition(script.eval_from_sc
ript_position, true); |
795 if (location) { | 804 if (location) { |
796 eval_origin += ":" + (location.line + 1); | 805 eval_origin += ":" + (location.line + 1); |
797 eval_origin += ":" + (location.column + 1); | 806 eval_origin += ":" + (location.column + 1); |
798 } | 807 } |
799 eval_origin += ")" | 808 eval_origin += ")" |
800 } else { | 809 } else { |
801 eval_origin += " (unknown source)"; | 810 eval_origin += " (unknown source)"; |
802 } | 811 } |
803 } | 812 } |
804 } | 813 } |
805 | 814 |
806 return eval_origin; | 815 return eval_origin; |
807 }; | 816 }; |
808 | 817 |
809 function FormatSourcePosition(frame) { | 818 function FormatSourcePosition(frame) { |
| 819 var fileName; |
810 var fileLocation = ""; | 820 var fileLocation = ""; |
811 if (frame.isNative()) { | 821 if (frame.isNative()) { |
812 fileLocation = "native"; | 822 fileLocation = "native"; |
813 } else if (frame.isEval()) { | 823 } else if (frame.isEval()) { |
814 fileLocation = "eval at " + frame.getEvalOrigin(); | 824 fileName = frame.getScriptNameOrSourceURL(); |
| 825 if (!fileName) |
| 826 fileLocation = frame.getEvalOrigin(); |
815 } else { | 827 } else { |
816 var fileName = frame.getFileName(); | 828 fileName = frame.getFileName(); |
817 if (fileName) { | 829 } |
818 fileLocation += fileName; | 830 |
819 var lineNumber = frame.getLineNumber(); | 831 if (fileName) { |
820 if (lineNumber != null) { | 832 fileLocation += fileName; |
821 fileLocation += ":" + lineNumber; | 833 var lineNumber = frame.getLineNumber(); |
822 var columnNumber = frame.getColumnNumber(); | 834 if (lineNumber != null) { |
823 if (columnNumber) { | 835 fileLocation += ":" + lineNumber; |
824 fileLocation += ":" + columnNumber; | 836 var columnNumber = frame.getColumnNumber(); |
825 } | 837 if (columnNumber) { |
| 838 fileLocation += ":" + columnNumber; |
826 } | 839 } |
827 } | 840 } |
828 } | 841 } |
| 842 |
829 if (!fileLocation) { | 843 if (!fileLocation) { |
830 fileLocation = "unknown source"; | 844 fileLocation = "unknown source"; |
831 } | 845 } |
832 var line = ""; | 846 var line = ""; |
833 var functionName = frame.getFunction().name; | 847 var functionName = frame.getFunction().name; |
834 var addPrefix = true; | 848 var addPrefix = true; |
835 var isConstructor = frame.isConstructor(); | 849 var isConstructor = frame.isConstructor(); |
836 var isMethodCall = !(frame.isToplevel() || isConstructor); | 850 var isMethodCall = !(frame.isToplevel() || isConstructor); |
837 if (isMethodCall) { | 851 if (isMethodCall) { |
838 var methodName = frame.getMethodName(); | 852 var methodName = frame.getMethodName(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); | 993 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); |
980 } | 994 } |
981 var message = this.message; | 995 var message = this.message; |
982 return this.name + (message ? (": " + message) : ""); | 996 return this.name + (message ? (": " + message) : ""); |
983 }, DONT_ENUM); | 997 }, DONT_ENUM); |
984 | 998 |
985 | 999 |
986 // Boilerplate for exceptions for stack overflows. Used from | 1000 // Boilerplate for exceptions for stack overflows. Used from |
987 // Top::StackOverflow(). | 1001 // Top::StackOverflow(). |
988 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1002 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |