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

Side by Side Diff: src/messages.js

Issue 11678006: Revert r13188, r13194, r13256 (Deferred formatting of error stack trace during GC). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 12 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 | Annotate | Revision Log
« no previous file with comments | « src/mark-compact.cc ('k') | src/runtime.h » ('j') | 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 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 // See if we can find a unique property on the receiver that holds 813 // See if we can find a unique property on the receiver that holds
814 // this function. 814 // this function.
815 var ownName = this.fun.name; 815 var ownName = this.fun.name;
816 if (ownName && this.receiver && 816 if (ownName && this.receiver &&
817 (%_CallFunction(this.receiver, 817 (%_CallFunction(this.receiver,
818 ownName, 818 ownName,
819 ObjectLookupGetter) === this.fun || 819 ObjectLookupGetter) === this.fun ||
820 %_CallFunction(this.receiver, 820 %_CallFunction(this.receiver,
821 ownName, 821 ownName,
822 ObjectLookupSetter) === this.fun || 822 ObjectLookupSetter) === this.fun ||
823 %GetDataProperty(this.receiver, ownName) === this.fun)) { 823 this.receiver[ownName] === this.fun)) {
824 // To handle DontEnum properties we guess that the method has 824 // To handle DontEnum properties we guess that the method has
825 // the same name as the function. 825 // the same name as the function.
826 return ownName; 826 return ownName;
827 } 827 }
828 var name = null; 828 var name = null;
829 for (var prop in this.receiver) { 829 for (var prop in this.receiver) {
830 if (%_CallFunction(this.receiver, prop, ObjectLookupGetter) === this.fun || 830 if (%_CallFunction(this.receiver, prop, ObjectLookupGetter) === this.fun ||
831 %_CallFunction(this.receiver, prop, ObjectLookupSetter) === this.fun || 831 %_CallFunction(this.receiver, prop, ObjectLookupSetter) === this.fun ||
832 %GetDataProperty(this.receiver, prop) === this.fun) { 832 (!%_CallFunction(this.receiver, prop, ObjectLookupGetter) &&
833 this.receiver[prop] === this.fun)) {
833 // If we find more than one match bail out to avoid confusion. 834 // If we find more than one match bail out to avoid confusion.
834 if (name) { 835 if (name) {
835 return null; 836 return null;
836 } 837 }
837 name = prop; 838 name = prop;
838 } 839 }
839 } 840 }
840 if (name) { 841 if (name) {
841 return name; 842 return name;
842 } 843 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 926
926 var line = ""; 927 var line = "";
927 var functionName = this.getFunctionName(); 928 var functionName = this.getFunctionName();
928 var addSuffix = true; 929 var addSuffix = true;
929 var isConstructor = this.isConstructor(); 930 var isConstructor = this.isConstructor();
930 var isMethodCall = !(this.isToplevel() || isConstructor); 931 var isMethodCall = !(this.isToplevel() || isConstructor);
931 if (isMethodCall) { 932 if (isMethodCall) {
932 var typeName = GetTypeName(this, true); 933 var typeName = GetTypeName(this, true);
933 var methodName = this.getMethodName(); 934 var methodName = this.getMethodName();
934 if (functionName) { 935 if (functionName) {
935 if (typeName && 936 if (typeName && functionName.indexOf(typeName) != 0) {
936 %_CallFunction(functionName, typeName, StringIndexOf) != 0) {
937 line += typeName + "."; 937 line += typeName + ".";
938 } 938 }
939 line += functionName; 939 line += functionName;
940 if (methodName && 940 if (methodName && functionName.lastIndexOf("." + methodName) !=
941 (%_CallFunction(functionName, "." + methodName, StringIndexOf) != 941 functionName.length - methodName.length - 1) {
942 functionName.length - methodName.length - 1)) {
943 line += " [as " + methodName + "]"; 942 line += " [as " + methodName + "]";
944 } 943 }
945 } else { 944 } else {
946 line += typeName + "." + (methodName || "<anonymous>"); 945 line += typeName + "." + (methodName || "<anonymous>");
947 } 946 }
948 } else if (isConstructor) { 947 } else if (isConstructor) {
949 line += "new " + (functionName || "<anonymous>"); 948 line += "new " + (functionName || "<anonymous>");
950 } else if (functionName) { 949 } else if (functionName) {
951 line += functionName; 950 line += functionName;
952 } else { 951 } else {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 eval_origin += ")"; 1009 eval_origin += ")";
1011 } else { 1010 } else {
1012 eval_origin += " (unknown source)"; 1011 eval_origin += " (unknown source)";
1013 } 1012 }
1014 } 1013 }
1015 } 1014 }
1016 1015
1017 return eval_origin; 1016 return eval_origin;
1018 } 1017 }
1019 1018
1020 1019 function FormatStackTrace(error, frames) {
1021 function FormatErrorString(error) { 1020 var lines = [];
1022 try { 1021 try {
1023 return %_CallFunction(error, ErrorToString); 1022 lines.push(error.toString());
1024 } catch (e) { 1023 } catch (e) {
1025 try { 1024 try {
1026 return "<error: " + e + ">"; 1025 lines.push("<error: " + e + ">");
1027 } catch (ee) { 1026 } catch (ee) {
1028 return "<error>"; 1027 lines.push("<error>");
1029 } 1028 }
1030 } 1029 }
1031 }
1032
1033
1034 function GetStackFrames(raw_stack) {
1035 var frames = new InternalArray();
1036 for (var i = 0; i < raw_stack.length; i += 4) {
1037 var recv = raw_stack[i];
1038 var fun = raw_stack[i + 1];
1039 var code = raw_stack[i + 2];
1040 var pc = raw_stack[i + 3];
1041 var pos = %FunctionGetPositionForOffset(code, pc);
1042 frames.push(new CallSite(recv, fun, pos));
1043 }
1044 return frames;
1045 }
1046
1047
1048 function FormatStackTrace(error_string, frames) {
1049 var lines = new InternalArray();
1050 lines.push(error_string);
1051 for (var i = 0; i < frames.length; i++) { 1030 for (var i = 0; i < frames.length; i++) {
1052 var frame = frames[i]; 1031 var frame = frames[i];
1053 var line; 1032 var line;
1054 try { 1033 try {
1055 line = frame.toString(); 1034 line = frame.toString();
1056 } catch (e) { 1035 } catch (e) {
1057 try { 1036 try {
1058 line = "<error: " + e + ">"; 1037 line = "<error: " + e + ">";
1059 } catch (ee) { 1038 } catch (ee) {
1060 // Any code that reaches this point is seriously nasty! 1039 // Any code that reaches this point is seriously nasty!
1061 line = "<error>"; 1040 line = "<error>";
1062 } 1041 }
1063 } 1042 }
1064 lines.push(" at " + line); 1043 lines.push(" at " + line);
1065 } 1044 }
1066 return %_CallFunction(lines, "\n", ArrayJoin); 1045 return lines.join("\n");
1067 } 1046 }
1068 1047
1048 function FormatRawStackTrace(error, raw_stack) {
1049 var frames = [ ];
1050 for (var i = 0; i < raw_stack.length; i += 4) {
1051 var recv = raw_stack[i];
1052 var fun = raw_stack[i + 1];
1053 var code = raw_stack[i + 2];
1054 var pc = raw_stack[i + 3];
1055 var pos = %FunctionGetPositionForOffset(code, pc);
1056 frames.push(new CallSite(recv, fun, pos));
1057 }
1058 if (IS_FUNCTION($Error.prepareStackTrace)) {
1059 return $Error.prepareStackTrace(error, frames);
1060 } else {
1061 return FormatStackTrace(error, frames);
1062 }
1063 }
1069 1064
1070 function GetTypeName(obj, requireConstructor) { 1065 function GetTypeName(obj, requireConstructor) {
1071 var constructor = obj.receiver.constructor; 1066 var constructor = obj.receiver.constructor;
1072 if (!constructor) { 1067 if (!constructor) {
1073 return requireConstructor ? null : 1068 return requireConstructor ? null :
1074 %_CallFunction(obj.receiver, ObjectToString); 1069 %_CallFunction(obj.receiver, ObjectToString);
1075 } 1070 }
1076 var constructorName = constructor.name; 1071 var constructorName = constructor.name;
1077 if (!constructorName) { 1072 if (!constructorName) {
1078 return requireConstructor ? null : 1073 return requireConstructor ? null :
1079 %_CallFunction(obj.receiver, ObjectToString); 1074 %_CallFunction(obj.receiver, ObjectToString);
1080 } 1075 }
1081 return constructorName; 1076 return constructorName;
1082 } 1077 }
1083 1078
1084
1085 // Flag to prevent recursive call of Error.prepareStackTrace.
1086 var formatting_custom_stack_trace = false;
1087
1088
1089 function captureStackTrace(obj, cons_opt) { 1079 function captureStackTrace(obj, cons_opt) {
1090 var stackTraceLimit = $Error.stackTraceLimit; 1080 var stackTraceLimit = $Error.stackTraceLimit;
1091 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; 1081 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return;
1092 if (stackTraceLimit < 0 || stackTraceLimit > 10000) { 1082 if (stackTraceLimit < 0 || stackTraceLimit > 10000) {
1093 stackTraceLimit = 10000; 1083 stackTraceLimit = 10000;
1094 } 1084 }
1095 var stack = %CollectStackTrace(obj, 1085 var raw_stack = %CollectStackTrace(obj,
1096 cons_opt ? cons_opt : captureStackTrace, 1086 cons_opt ? cons_opt : captureStackTrace,
1097 stackTraceLimit); 1087 stackTraceLimit);
1098
1099 // Don't be lazy if the error stack formatting is custom (observable).
1100 if (IS_FUNCTION($Error.prepareStackTrace) && !formatting_custom_stack_trace) {
1101 var array = [];
1102 %MoveArrayContents(GetStackFrames(stack), array);
1103 formatting_custom_stack_trace = true;
1104 try {
1105 obj.stack = $Error.prepareStackTrace(obj, array);
1106 } catch (e) {
1107 throw e; // The custom formatting function threw. Rethrow.
1108 } finally {
1109 formatting_custom_stack_trace = false;
1110 }
1111 return;
1112 }
1113
1114 var error_string = FormatErrorString(obj);
1115 // Note that 'obj' and 'this' maybe different when called on objects that 1088 // Note that 'obj' and 'this' maybe different when called on objects that
1116 // have the error object on its prototype chain. The getter replaces itself 1089 // have the error object on its prototype chain. The getter replaces itself
1117 // with a data property as soon as the stack trace has been formatted. 1090 // with a data property as soon as the stack trace has been formatted.
1118 // The getter must not change the object layout as it may be called after GC.
1119 var getter = function() { 1091 var getter = function() {
1120 if (IS_STRING(stack)) return stack; 1092 var value = FormatRawStackTrace(obj, raw_stack);
1121 // Stack is still a raw array awaiting to be formatted. 1093 %DefineOrRedefineDataProperty(obj, 'stack', value, NONE);
1122 stack = FormatStackTrace(error_string, GetStackFrames(stack)); 1094 return value;
1123 // Release context value.
1124 error_string = void 0;
1125 return stack;
1126 }; 1095 };
1127 %MarkOneShotGetter(getter);
1128
1129 // The 'stack' property of the receiver is set as data property. If 1096 // The 'stack' property of the receiver is set as data property. If
1130 // the receiver is the same as holder, this accessor pair is replaced. 1097 // the receiver is the same as holder, this accessor pair is replaced.
1131 var setter = function(v) { 1098 var setter = function(v) {
1132 %DefineOrRedefineDataProperty(this, 'stack', v, NONE); 1099 %DefineOrRedefineDataProperty(this, 'stack', v, NONE);
1133 }; 1100 };
1134 1101
1135 %DefineOrRedefineAccessorProperty(obj, 'stack', getter, setter, DONT_ENUM); 1102 %DefineOrRedefineAccessorProperty(obj, 'stack', getter, setter, DONT_ENUM);
1136 } 1103 }
1137 1104
1138 1105
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 // Boilerplate for exceptions for stack overflows. Used from 1232 // Boilerplate for exceptions for stack overflows. Used from
1266 // Isolate::StackOverflow(). 1233 // Isolate::StackOverflow().
1267 function SetUpStackOverflowBoilerplate() { 1234 function SetUpStackOverflowBoilerplate() {
1268 var boilerplate = MakeRangeError('stack_overflow', []); 1235 var boilerplate = MakeRangeError('stack_overflow', []);
1269 1236
1270 // The raw stack trace is stored as hidden property of the copy of this 1237 // The raw stack trace is stored as hidden property of the copy of this
1271 // boilerplate error object. Note that the receiver 'this' may not be that 1238 // boilerplate error object. Note that the receiver 'this' may not be that
1272 // error object copy, but can be found on the prototype chain of 'this'. 1239 // error object copy, but can be found on the prototype chain of 'this'.
1273 // When the stack trace is formatted, this accessor property is replaced by 1240 // When the stack trace is formatted, this accessor property is replaced by
1274 // a data property. 1241 // a data property.
1275 var error_string = boilerplate.name + ": " + boilerplate.message;
1276
1277 // The getter must not change the object layout as it may be called after GC.
1278 function getter() { 1242 function getter() {
1279 var holder = this; 1243 var holder = this;
1280 while (!IS_ERROR(holder)) { 1244 while (!IS_ERROR(holder)) {
1281 holder = %GetPrototype(holder); 1245 holder = %GetPrototype(holder);
1282 if (holder == null) return MakeSyntaxError('illegal_access', []); 1246 if (holder == null) return MakeSyntaxError('illegal_access', []);
1283 } 1247 }
1284 var stack = %GetOverflowedStackTrace(holder); 1248 var raw_stack = %GetOverflowedRawStackTrace(holder);
1285 if (IS_STRING(stack)) return stack; 1249 var result = IS_ARRAY(raw_stack) ? FormatRawStackTrace(holder, raw_stack)
1286 if (IS_ARRAY(stack)) { 1250 : void 0;
1287 var result = FormatStackTrace(error_string, GetStackFrames(stack)); 1251 %DefineOrRedefineDataProperty(holder, 'stack', result, NONE);
1288 %SetOverflowedStackTrace(holder, result); 1252 return result;
1289 return result;
1290 }
1291 return void 0;
1292 } 1253 }
1293 %MarkOneShotGetter(getter);
1294 1254
1295 // The 'stack' property of the receiver is set as data property. If 1255 // The 'stack' property of the receiver is set as data property. If
1296 // the receiver is the same as holder, this accessor pair is replaced. 1256 // the receiver is the same as holder, this accessor pair is replaced.
1297 function setter(v) { 1257 function setter(v) {
1298 %DefineOrRedefineDataProperty(this, 'stack', v, NONE); 1258 %DefineOrRedefineDataProperty(this, 'stack', v, NONE);
1299 // Release the stack trace that is stored as hidden property, if exists.
1300 %SetOverflowedStackTrace(this, void 0);
1301 } 1259 }
1302 1260
1303 %DefineOrRedefineAccessorProperty( 1261 %DefineOrRedefineAccessorProperty(
1304 boilerplate, 'stack', getter, setter, DONT_ENUM); 1262 boilerplate, 'stack', getter, setter, DONT_ENUM);
1305 1263
1306 return boilerplate; 1264 return boilerplate;
1307 } 1265 }
1308 1266
1309 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); 1267 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate();
OLDNEW
« no previous file with comments | « src/mark-compact.cc ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698