Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: src/messages.js

Issue 10332172: messages.js: Add toString to CallSite (which describes a frame of the stack trace). (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: ? Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 var script = %MessageGetScript(message); 738 var script = %MessageGetScript(message);
739 var start_position = %MessageGetStartPosition(message); 739 var start_position = %MessageGetStartPosition(message);
740 var location = script.locationFromPosition(start_position, false); 740 var location = script.locationFromPosition(start_position, false);
741 if (location == null) return -1; 741 if (location == null) return -1;
742 location.restrict(); 742 location.restrict();
743 return start_position - location.start; 743 return start_position - location.start;
744 } 744 }
745 745
746 746
747 function GetStackTraceLine(recv, fun, pos, isGlobal) { 747 function GetStackTraceLine(recv, fun, pos, isGlobal) {
748 return FormatSourcePosition(new CallSite(recv, fun, pos)); 748 return new CallSite(recv, fun, pos).toString();
749 } 749 }
750 750
751 // ---------------------------------------------------------------------------- 751 // ----------------------------------------------------------------------------
752 // Error implementation 752 // Error implementation
753 753
754 // Defines accessors for a property that is calculated the first time 754 // Defines accessors for a property that is calculated the first time
755 // the property is read. 755 // the property is read.
756 function DefineOneShotAccessor(obj, name, fun) { 756 function DefineOneShotAccessor(obj, name, fun) {
757 // Note that the accessors consistently operate on 'obj', not 'this'. 757 // Note that the accessors consistently operate on 'obj', not 'this'.
758 // Since the object may occur in someone else's prototype chain we 758 // Since the object may occur in someone else's prototype chain we
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 } 912 }
913 913
914 function CallSiteIsConstructor() { 914 function CallSiteIsConstructor() {
915 var constructor = this.receiver ? this.receiver.constructor : null; 915 var constructor = this.receiver ? this.receiver.constructor : null;
916 if (!constructor) { 916 if (!constructor) {
917 return false; 917 return false;
918 } 918 }
919 return this.fun === constructor; 919 return this.fun === constructor;
920 } 920 }
921 921
922 function CallSiteToString() {
923 var fileName;
924 var fileLocation = "";
925 if (this.isNative()) {
926 fileLocation = "native";
927 } else if (this.isEval()) {
928 fileName = this.getScriptNameOrSourceURL();
929 if (!fileName) {
930 fileLocation = this.getEvalOrigin();
931 }
932 } else {
933 fileName = this.getFileName();
934 }
935
936 if (fileName) {
937 fileLocation += fileName;
938 var lineNumber = this.getLineNumber();
939 if (lineNumber != null) {
940 fileLocation += ":" + lineNumber;
941 var columnNumber = this.getColumnNumber();
942 if (columnNumber) {
943 fileLocation += ":" + columnNumber;
944 }
945 }
946 }
947
948 if (!fileLocation) {
949 fileLocation = "unknown source";
950 }
951 var line = "";
952 var functionName = this.getFunction().name;
953 var addPrefix = true;
954 var isConstructor = this.isConstructor();
955 var isMethodCall = !(this.isToplevel() || isConstructor);
956 if (isMethodCall) {
957 var methodName = this.getMethodName();
958 line += this.getTypeName() + ".";
959 if (functionName) {
960 line += functionName;
961 if (methodName && (methodName != functionName)) {
962 line += " [as " + methodName + "]";
963 }
964 } else {
965 line += methodName || "<anonymous>";
966 }
967 } else if (isConstructor) {
968 line += "new " + (functionName || "<anonymous>");
969 } else if (functionName) {
970 line += functionName;
971 } else {
972 line += fileLocation;
973 addPrefix = false;
974 }
975 if (addPrefix) {
976 line += " (" + fileLocation + ")";
977 }
978 return line;
979 }
980
922 SetUpLockedPrototype(CallSite, $Array("receiver", "fun", "pos"), $Array( 981 SetUpLockedPrototype(CallSite, $Array("receiver", "fun", "pos"), $Array(
923 "getThis", CallSiteGetThis, 982 "getThis", CallSiteGetThis,
924 "getTypeName", CallSiteGetTypeName, 983 "getTypeName", CallSiteGetTypeName,
925 "isToplevel", CallSiteIsToplevel, 984 "isToplevel", CallSiteIsToplevel,
926 "isEval", CallSiteIsEval, 985 "isEval", CallSiteIsEval,
927 "getEvalOrigin", CallSiteGetEvalOrigin, 986 "getEvalOrigin", CallSiteGetEvalOrigin,
928 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, 987 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL,
929 "getFunction", CallSiteGetFunction, 988 "getFunction", CallSiteGetFunction,
930 "getFunctionName", CallSiteGetFunctionName, 989 "getFunctionName", CallSiteGetFunctionName,
931 "getMethodName", CallSiteGetMethodName, 990 "getMethodName", CallSiteGetMethodName,
932 "getFileName", CallSiteGetFileName, 991 "getFileName", CallSiteGetFileName,
933 "getLineNumber", CallSiteGetLineNumber, 992 "getLineNumber", CallSiteGetLineNumber,
934 "getColumnNumber", CallSiteGetColumnNumber, 993 "getColumnNumber", CallSiteGetColumnNumber,
935 "isNative", CallSiteIsNative, 994 "isNative", CallSiteIsNative,
936 "getPosition", CallSiteGetPosition, 995 "getPosition", CallSiteGetPosition,
937 "isConstructor", CallSiteIsConstructor 996 "isConstructor", CallSiteIsConstructor,
997 "toString", CallSiteToString
938 )); 998 ));
939 999
940 1000
941 function FormatEvalOrigin(script) { 1001 function FormatEvalOrigin(script) {
942 var sourceURL = script.nameOrSourceURL(); 1002 var sourceURL = script.nameOrSourceURL();
943 if (sourceURL) { 1003 if (sourceURL) {
944 return sourceURL; 1004 return sourceURL;
945 } 1005 }
946 1006
947 var eval_origin = "eval at "; 1007 var eval_origin = "eval at ";
(...skipping 21 matching lines...) Expand all
969 eval_origin += ")"; 1029 eval_origin += ")";
970 } else { 1030 } else {
971 eval_origin += " (unknown source)"; 1031 eval_origin += " (unknown source)";
972 } 1032 }
973 } 1033 }
974 } 1034 }
975 1035
976 return eval_origin; 1036 return eval_origin;
977 } 1037 }
978 1038
979 function FormatSourcePosition(frame) {
980 var fileName;
981 var fileLocation = "";
982 if (frame.isNative()) {
983 fileLocation = "native";
984 } else if (frame.isEval()) {
985 fileName = frame.getScriptNameOrSourceURL();
986 if (!fileName) {
987 fileLocation = frame.getEvalOrigin();
988 }
989 } else {
990 fileName = frame.getFileName();
991 }
992
993 if (fileName) {
994 fileLocation += fileName;
995 var lineNumber = frame.getLineNumber();
996 if (lineNumber != null) {
997 fileLocation += ":" + lineNumber;
998 var columnNumber = frame.getColumnNumber();
999 if (columnNumber) {
1000 fileLocation += ":" + columnNumber;
1001 }
1002 }
1003 }
1004
1005 if (!fileLocation) {
1006 fileLocation = "unknown source";
1007 }
1008 var line = "";
1009 var functionName = frame.getFunction().name;
1010 var addPrefix = true;
1011 var isConstructor = frame.isConstructor();
1012 var isMethodCall = !(frame.isToplevel() || isConstructor);
1013 if (isMethodCall) {
1014 var methodName = frame.getMethodName();
1015 line += frame.getTypeName() + ".";
1016 if (functionName) {
1017 line += functionName;
1018 if (methodName && (methodName != functionName)) {
1019 line += " [as " + methodName + "]";
1020 }
1021 } else {
1022 line += methodName || "<anonymous>";
1023 }
1024 } else if (isConstructor) {
1025 line += "new " + (functionName || "<anonymous>");
1026 } else if (functionName) {
1027 line += functionName;
1028 } else {
1029 line += fileLocation;
1030 addPrefix = false;
1031 }
1032 if (addPrefix) {
1033 line += " (" + fileLocation + ")";
1034 }
1035 return line;
1036 }
1037
1038 function FormatStackTrace(error, frames) { 1039 function FormatStackTrace(error, frames) {
1039 var lines = []; 1040 var lines = [];
1040 try { 1041 try {
1041 lines.push(error.toString()); 1042 lines.push(error.toString());
1042 } catch (e) { 1043 } catch (e) {
1043 try { 1044 try {
1044 lines.push("<error: " + e + ">"); 1045 lines.push("<error: " + e + ">");
1045 } catch (ee) { 1046 } catch (ee) {
1046 lines.push("<error>"); 1047 lines.push("<error>");
1047 } 1048 }
1048 } 1049 }
1049 for (var i = 0; i < frames.length; i++) { 1050 for (var i = 0; i < frames.length; i++) {
1050 var frame = frames[i]; 1051 var frame = frames[i];
1051 var line; 1052 var line;
1052 try { 1053 try {
1053 line = FormatSourcePosition(frame); 1054 line = frame.toString();
1054 } catch (e) { 1055 } catch (e) {
1055 try { 1056 try {
1056 line = "<error: " + e + ">"; 1057 line = "<error: " + e + ">";
1057 } catch (ee) { 1058 } catch (ee) {
1058 // Any code that reaches this point is seriously nasty! 1059 // Any code that reaches this point is seriously nasty!
1059 line = "<error>"; 1060 line = "<error>";
1060 } 1061 }
1061 } 1062 }
1062 lines.push(" at " + line); 1063 lines.push(" at " + line);
1063 } 1064 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 throw e; 1234 throw e;
1234 } 1235 }
1235 } 1236 }
1236 1237
1237 1238
1238 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); 1239 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]);
1239 1240
1240 // Boilerplate for exceptions for stack overflows. Used from 1241 // Boilerplate for exceptions for stack overflows. Used from
1241 // Isolate::StackOverflow(). 1242 // Isolate::StackOverflow().
1242 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1243 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698