OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 this.receiver = receiver; | 781 this.receiver = receiver; |
782 this.fun = fun; | 782 this.fun = fun; |
783 this.pos = pos; | 783 this.pos = pos; |
784 } | 784 } |
785 | 785 |
786 function CallSiteGetThis() { | 786 function CallSiteGetThis() { |
787 return this.receiver; | 787 return this.receiver; |
788 } | 788 } |
789 | 789 |
790 function CallSiteGetTypeName() { | 790 function CallSiteGetTypeName() { |
791 var constructor = this.receiver.constructor; | 791 return GetTypeName(this, false); |
792 if (!constructor) { | |
793 return %_CallFunction(this.receiver, ObjectToString); | |
794 } | |
795 var constructorName = constructor.name; | |
796 if (!constructorName) { | |
797 return %_CallFunction(this.receiver, ObjectToString); | |
798 } | |
799 return constructorName; | |
800 } | 792 } |
801 | 793 |
802 function CallSiteIsToplevel() { | 794 function CallSiteIsToplevel() { |
803 if (this.receiver == null) { | 795 if (this.receiver == null) { |
804 return true; | 796 return true; |
805 } | 797 } |
806 return IS_GLOBAL(this.receiver); | 798 return IS_GLOBAL(this.receiver); |
807 } | 799 } |
808 | 800 |
809 function CallSiteIsEval() { | 801 function CallSiteIsEval() { |
(...skipping 13 matching lines...) Expand all Loading... |
823 | 815 |
824 function CallSiteGetFunction() { | 816 function CallSiteGetFunction() { |
825 return this.fun; | 817 return this.fun; |
826 } | 818 } |
827 | 819 |
828 function CallSiteGetFunctionName() { | 820 function CallSiteGetFunctionName() { |
829 // See if the function knows its own name | 821 // See if the function knows its own name |
830 var name = this.fun.name; | 822 var name = this.fun.name; |
831 if (name) { | 823 if (name) { |
832 return name; | 824 return name; |
833 } else { | 825 } |
834 return %FunctionGetInferredName(this.fun); | 826 name = %FunctionGetInferredName(this.fun); |
| 827 if (name) { |
| 828 return name; |
835 } | 829 } |
836 // Maybe this is an evaluation? | 830 // Maybe this is an evaluation? |
837 var script = %FunctionGetScript(this.fun); | 831 var script = %FunctionGetScript(this.fun); |
838 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) { | 832 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) { |
839 return "eval"; | 833 return "eval"; |
840 } | 834 } |
841 return null; | 835 return null; |
842 } | 836 } |
843 | 837 |
844 function CallSiteGetMethodName() { | 838 function CallSiteGetMethodName() { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 if (columnNumber) { | 939 if (columnNumber) { |
946 fileLocation += ":" + columnNumber; | 940 fileLocation += ":" + columnNumber; |
947 } | 941 } |
948 } | 942 } |
949 } | 943 } |
950 | 944 |
951 if (!fileLocation) { | 945 if (!fileLocation) { |
952 fileLocation = "unknown source"; | 946 fileLocation = "unknown source"; |
953 } | 947 } |
954 var line = ""; | 948 var line = ""; |
955 var functionName = this.getFunction().name; | 949 var functionName = this.getFunctionName(); |
956 var addPrefix = true; | 950 var addSuffix = true; |
957 var isConstructor = this.isConstructor(); | 951 var isConstructor = this.isConstructor(); |
958 var isMethodCall = !(this.isToplevel() || isConstructor); | 952 var isMethodCall = !(this.isToplevel() || isConstructor); |
959 if (isMethodCall) { | 953 if (isMethodCall) { |
| 954 var typeName = GetTypeName(this, true); |
960 var methodName = this.getMethodName(); | 955 var methodName = this.getMethodName(); |
961 line += this.getTypeName() + "."; | |
962 if (functionName) { | 956 if (functionName) { |
| 957 if (typeName && functionName.indexOf(typeName) != 0) { |
| 958 line += typeName + "."; |
| 959 } |
963 line += functionName; | 960 line += functionName; |
964 if (methodName && (methodName != functionName)) { | 961 if (methodName && functionName.lastIndexOf("." + methodName) != |
| 962 functionName.length - methodName.length - 1) { |
965 line += " [as " + methodName + "]"; | 963 line += " [as " + methodName + "]"; |
966 } | 964 } |
967 } else { | 965 } else { |
968 line += methodName || "<anonymous>"; | 966 line += typeName + "." + (methodName || "<anonymous>"); |
969 } | 967 } |
970 } else if (isConstructor) { | 968 } else if (isConstructor) { |
971 line += "new " + (functionName || "<anonymous>"); | 969 line += "new " + (functionName || "<anonymous>"); |
972 } else if (functionName) { | 970 } else if (functionName) { |
973 line += functionName; | 971 line += functionName; |
974 } else { | 972 } else { |
975 line += fileLocation; | 973 line += fileLocation; |
976 addPrefix = false; | 974 addSuffix = false; |
977 } | 975 } |
978 if (addPrefix) { | 976 if (addSuffix) { |
979 line += " (" + fileLocation + ")"; | 977 line += " (" + fileLocation + ")"; |
980 } | 978 } |
981 return line; | 979 return line; |
982 } | 980 } |
983 | 981 |
984 SetUpLockedPrototype(CallSite, $Array("receiver", "fun", "pos"), $Array( | 982 SetUpLockedPrototype(CallSite, $Array("receiver", "fun", "pos"), $Array( |
985 "getThis", CallSiteGetThis, | 983 "getThis", CallSiteGetThis, |
986 "getTypeName", CallSiteGetTypeName, | 984 "getTypeName", CallSiteGetTypeName, |
987 "isToplevel", CallSiteIsToplevel, | 985 "isToplevel", CallSiteIsToplevel, |
988 "isEval", CallSiteIsEval, | 986 "isEval", CallSiteIsEval, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 var pos = %FunctionGetPositionForOffset(code, pc); | 1076 var pos = %FunctionGetPositionForOffset(code, pc); |
1079 frames.push(new CallSite(recv, fun, pos)); | 1077 frames.push(new CallSite(recv, fun, pos)); |
1080 } | 1078 } |
1081 if (IS_FUNCTION($Error.prepareStackTrace)) { | 1079 if (IS_FUNCTION($Error.prepareStackTrace)) { |
1082 return $Error.prepareStackTrace(error, frames); | 1080 return $Error.prepareStackTrace(error, frames); |
1083 } else { | 1081 } else { |
1084 return FormatStackTrace(error, frames); | 1082 return FormatStackTrace(error, frames); |
1085 } | 1083 } |
1086 } | 1084 } |
1087 | 1085 |
| 1086 function GetTypeName(obj, requireConstructor) { |
| 1087 var constructor = obj.receiver.constructor; |
| 1088 if (!constructor) { |
| 1089 return requireConstructor ? null : |
| 1090 %_CallFunction(obj.receiver, ObjectToString); |
| 1091 } |
| 1092 var constructorName = constructor.name; |
| 1093 if (!constructorName) { |
| 1094 return requireConstructor ? null : |
| 1095 %_CallFunction(obj.receiver, ObjectToString); |
| 1096 } |
| 1097 return constructorName; |
| 1098 } |
1088 | 1099 |
1089 function captureStackTrace(obj, cons_opt) { | 1100 function captureStackTrace(obj, cons_opt) { |
1090 var stackTraceLimit = $Error.stackTraceLimit; | 1101 var stackTraceLimit = $Error.stackTraceLimit; |
1091 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; | 1102 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; |
1092 if (stackTraceLimit < 0 || stackTraceLimit > 10000) { | 1103 if (stackTraceLimit < 0 || stackTraceLimit > 10000) { |
1093 stackTraceLimit = 10000; | 1104 stackTraceLimit = 10000; |
1094 } | 1105 } |
1095 var raw_stack = %CollectStackTrace(obj, | 1106 var raw_stack = %CollectStackTrace(obj, |
1096 cons_opt ? cons_opt : captureStackTrace, | 1107 cons_opt ? cons_opt : captureStackTrace, |
1097 stackTraceLimit); | 1108 stackTraceLimit); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 throw e; | 1248 throw e; |
1238 } | 1249 } |
1239 } | 1250 } |
1240 | 1251 |
1241 | 1252 |
1242 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); | 1253 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
1243 | 1254 |
1244 // Boilerplate for exceptions for stack overflows. Used from | 1255 // Boilerplate for exceptions for stack overflows. Used from |
1245 // Isolate::StackOverflow(). | 1256 // Isolate::StackOverflow(). |
1246 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1257 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |