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

Side by Side Diff: src/messages.js

Issue 9323075: Add properties fileName and lineNumber to the Error object. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: remove columnNumber Created 8 years, 10 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 | « no previous file | test/mjsunit/error-properties.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 var pos = %FunctionGetPositionForOffset(code, pc); 1064 var pos = %FunctionGetPositionForOffset(code, pc);
1065 frames.push(new CallSite(recv, fun, pos)); 1065 frames.push(new CallSite(recv, fun, pos));
1066 } 1066 }
1067 if (IS_FUNCTION($Error.prepareStackTrace)) { 1067 if (IS_FUNCTION($Error.prepareStackTrace)) {
1068 return $Error.prepareStackTrace(error, frames); 1068 return $Error.prepareStackTrace(error, frames);
1069 } else { 1069 } else {
1070 return FormatStackTrace(error, frames); 1070 return FormatStackTrace(error, frames);
1071 } 1071 }
1072 } 1072 }
1073 1073
1074 function GetTopFrame(raw_stack) {
1075 for (var i = 0; i < raw_stack.length; i += 4) {
1076 var recv = raw_stack[i];
1077 var fun = raw_stack[i + 1];
1078 var code = raw_stack[i + 2];
1079 var pc = raw_stack[i + 3];
1080 var pos = %FunctionGetPositionForOffset(code, pc);
1081 var top_frame = new CallSite(recv, fun, pos);
1082 if (!top_frame.isNative()) return top_frame;
1083 }
1084 return undefined;
1085 }
1074 1086
1075 function captureStackTrace(obj, cons_opt) { 1087 function captureStackTrace(obj, cons_opt) {
1076 var stackTraceLimit = $Error.stackTraceLimit; 1088 var stackTraceLimit = $Error.stackTraceLimit;
1077 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; 1089 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return;
1078 if (stackTraceLimit < 0 || stackTraceLimit > 10000) { 1090 if (stackTraceLimit < 0 || stackTraceLimit > 10000) {
1079 stackTraceLimit = 10000; 1091 stackTraceLimit = 10000;
1080 } 1092 }
1081 var raw_stack = %CollectStackTrace(cons_opt 1093 var raw_stack = %CollectStackTrace(cons_opt
1082 ? cons_opt 1094 ? cons_opt
1083 : captureStackTrace, stackTraceLimit); 1095 : captureStackTrace, stackTraceLimit);
1084 DefineOneShotAccessor(obj, 'stack', function (obj) { 1096 DefineOneShotAccessor(obj, 'stack', function (obj) {
1085 return FormatRawStackTrace(obj, raw_stack); 1097 return FormatRawStackTrace(obj, raw_stack);
1086 }); 1098 });
1099
1100 DefineOneShotAccessor(obj, 'lineNumber', function (obj) {
1101 var frame = GetTopFrame(raw_stack);
1102 return frame ? frame.getLineNumber() : undefined;
1103 });
1104 DefineOneShotAccessor(obj, 'fileName', function (obj) {
1105 var frame = GetTopFrame(raw_stack);
1106 return frame ? (frame.isEval() ? frame.getEvalOrigin()
1107 : frame.getFileName())
1108 : undefined;
1109 });
1087 } 1110 }
1088 1111
1089 1112
1090 function SetUpError() { 1113 function SetUpError() {
1091 // Define special error type constructors. 1114 // Define special error type constructors.
1092 1115
1093 function DefineError(f) { 1116 function DefineError(f) {
1094 // Store the error function in both the global object 1117 // Store the error function in both the global object
1095 // and the runtime object. The function is fetched 1118 // and the runtime object. The function is fetched
1096 // from the runtime object when throwing errors from 1119 // from the runtime object when throwing errors from
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 throw e; 1230 throw e;
1208 } 1231 }
1209 } 1232 }
1210 1233
1211 1234
1212 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); 1235 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]);
1213 1236
1214 // Boilerplate for exceptions for stack overflows. Used from 1237 // Boilerplate for exceptions for stack overflows. Used from
1215 // Isolate::StackOverflow(). 1238 // Isolate::StackOverflow().
1216 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1239 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/error-properties.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698