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

Side by Side Diff: src/messages.js

Issue 11649037: Fix several bugs in error stack trace formatting. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: changed GetScriptWrapper fix. Created 8 years 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/heap.cc ('k') | test/mjsunit/stack-traces.js » ('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 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } 1075 }
1076 var constructorName = constructor.name; 1076 var constructorName = constructor.name;
1077 if (!constructorName) { 1077 if (!constructorName) {
1078 return requireConstructor ? null : 1078 return requireConstructor ? null :
1079 %_CallFunction(obj.receiver, ObjectToString); 1079 %_CallFunction(obj.receiver, ObjectToString);
1080 } 1080 }
1081 return constructorName; 1081 return constructorName;
1082 } 1082 }
1083 1083
1084 1084
1085 // Flag to prevent recursive call of Error.prepareStackTrace.
1086 var formatting_custom_stack_trace = false;
1087
1088
1085 function captureStackTrace(obj, cons_opt) { 1089 function captureStackTrace(obj, cons_opt) {
1086 var stackTraceLimit = $Error.stackTraceLimit; 1090 var stackTraceLimit = $Error.stackTraceLimit;
1087 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; 1091 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return;
1088 if (stackTraceLimit < 0 || stackTraceLimit > 10000) { 1092 if (stackTraceLimit < 0 || stackTraceLimit > 10000) {
1089 stackTraceLimit = 10000; 1093 stackTraceLimit = 10000;
1090 } 1094 }
1091 var stack = %CollectStackTrace(obj, 1095 var stack = %CollectStackTrace(obj,
1092 cons_opt ? cons_opt : captureStackTrace, 1096 cons_opt ? cons_opt : captureStackTrace,
1093 stackTraceLimit); 1097 stackTraceLimit);
1094 1098
1095 // Don't be lazy if the error stack formatting is custom (observable). 1099 // Don't be lazy if the error stack formatting is custom (observable).
1096 if (IS_FUNCTION($Error.prepareStackTrace)) { 1100 if (IS_FUNCTION($Error.prepareStackTrace) && !formatting_custom_stack_trace) {
1097 var custom_stacktrace_fun = $Error.prepareStackTrace;
1098 // Use default error formatting for the case that custom formatting throws.
1099 $Error.prepareStackTrace = null;
1100 var array = []; 1101 var array = [];
1101 %MoveArrayContents(GetStackFrames(stack), array); 1102 %MoveArrayContents(GetStackFrames(stack), array);
1102 obj.stack = custom_stacktrace_fun(obj, array); 1103 formatting_custom_stack_trace = true;
1103 $Error.prepareStackTrace = custom_stacktrace_fun; 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 }
1104 return; 1111 return;
1105 } 1112 }
1106 1113
1107 var error_string = FormatErrorString(obj); 1114 var error_string = FormatErrorString(obj);
1108 // Note that 'obj' and 'this' maybe different when called on objects that 1115 // Note that 'obj' and 'this' maybe different when called on objects that
1109 // have the error object on its prototype chain. The getter replaces itself 1116 // have the error object on its prototype chain. The getter replaces itself
1110 // with a data property as soon as the stack trace has been formatted. 1117 // with a data property as soon as the stack trace has been formatted.
1111 // The getter must not change the object layout as it may be called after GC. 1118 // The getter must not change the object layout as it may be called after GC.
1112 var getter = function() { 1119 var getter = function() {
1113 if (IS_STRING(stack)) return stack; 1120 if (IS_STRING(stack)) return stack;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 %SetOverflowedStackTrace(this, void 0); 1300 %SetOverflowedStackTrace(this, void 0);
1294 } 1301 }
1295 1302
1296 %DefineOrRedefineAccessorProperty( 1303 %DefineOrRedefineAccessorProperty(
1297 boilerplate, 'stack', getter, setter, DONT_ENUM); 1304 boilerplate, 'stack', getter, setter, DONT_ENUM);
1298 1305
1299 return boilerplate; 1306 return boilerplate;
1300 } 1307 }
1301 1308
1302 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); 1309 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate();
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | test/mjsunit/stack-traces.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698