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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/error-properties.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index 5310938a6612f75bdd6044b3715d48f879ad2273..d46f1dc427b2db7ef652d3ffb6c69ccfb4077ff9 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -1071,6 +1071,18 @@ function FormatRawStackTrace(error, raw_stack) {
}
}
+function GetTopFrame(raw_stack) {
+ for (var i = 0; i < raw_stack.length; i += 4) {
+ var recv = raw_stack[i];
+ var fun = raw_stack[i + 1];
+ var code = raw_stack[i + 2];
+ var pc = raw_stack[i + 3];
+ var pos = %FunctionGetPositionForOffset(code, pc);
+ var top_frame = new CallSite(recv, fun, pos);
+ if (!top_frame.isNative()) return top_frame;
+ }
+ return undefined;
+}
function captureStackTrace(obj, cons_opt) {
var stackTraceLimit = $Error.stackTraceLimit;
@@ -1084,6 +1096,17 @@ function captureStackTrace(obj, cons_opt) {
DefineOneShotAccessor(obj, 'stack', function (obj) {
return FormatRawStackTrace(obj, raw_stack);
});
+
+ DefineOneShotAccessor(obj, 'lineNumber', function (obj) {
+ var frame = GetTopFrame(raw_stack);
+ return frame ? frame.getLineNumber() : undefined;
+ });
+ DefineOneShotAccessor(obj, 'fileName', function (obj) {
+ var frame = GetTopFrame(raw_stack);
+ return frame ? (frame.isEval() ? frame.getEvalOrigin()
+ : frame.getFileName())
+ : undefined;
+ });
}
« 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