Revision: 5498
Author: yu...@chromium.org
Date: Mon Sep 20 08:55:28 2010
Log: Use //@ sourceURL when formatting stack trace
BUG=672
Review URL: http://codereview.chromium.org/3444011
http://code.google.com/p/v8/source/detail?r=5498
Modified:
/branches/bleeding_edge/src/messages.js
/branches/bleeding_edge/test/mjsunit/stack-traces.js
=======================================
--- /branches/bleeding_edge/src/messages.js Mon Sep 6 02:10:11 2010
+++ /branches/bleeding_edge/src/messages.js Mon Sep 20 08:55:28 2010
@@ -684,6 +684,11 @@
return FormatEvalOrigin(script);
};
+CallSite.prototype.getScriptNameOrSourceURL = function () {
+ var script = %FunctionGetScript(this.fun);
+ return script ? script.nameOrSourceURL() : null;
+};
+
CallSite.prototype.getFunction = function () {
return this.fun;
};
@@ -775,7 +780,11 @@
};
function FormatEvalOrigin(script) {
- var eval_origin = "";
+ var sourceURL = script.nameOrSourceURL();
+ if (sourceURL)
+ return sourceURL;
+
+ var eval_origin = "eval at ";
if (script.eval_from_function_name) {
eval_origin += script.eval_from_function_name;
} else {
@@ -786,9 +795,9 @@
if (eval_from_script) {
if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) {
// eval script originated from another eval.
- eval_origin += " (eval at " + FormatEvalOrigin(eval_from_script)
+ ")";
+ eval_origin += " (" + FormatEvalOrigin(eval_from_script) + ")";
} else {
- // eval script originated from "real" scource.
+ // eval script originated from "real" source.
if (eval_from_script.name) {
eval_origin += " (" + eval_from_script.name;
var location =
eval_from_script.locationFromPosition(script.eval_from_script_position,
true);
@@ -807,25 +816,30 @@
};
function FormatSourcePosition(frame) {
+ var fileName;
var fileLocation = "";
if (frame.isNative()) {
fileLocation = "native";
} else if (frame.isEval()) {
- fileLocation = "eval at " + frame.getEvalOrigin();
+ fileName = frame.getScriptNameOrSourceURL();
+ if (!fileName)
+ fileLocation = frame.getEvalOrigin();
} else {
- var fileName = frame.getFileName();
- if (fileName) {
- fileLocation += fileName;
- var lineNumber = frame.getLineNumber();
- if (lineNumber != null) {
- fileLocation += ":" + lineNumber;
- var columnNumber = frame.getColumnNumber();
- if (columnNumber) {
- fileLocation += ":" + columnNumber;
- }
+ fileName = frame.getFileName();
+ }
+
+ if (fileName) {
+ fileLocation += fileName;
+ var lineNumber = frame.getLineNumber();
+ if (lineNumber != null) {
+ fileLocation += ":" + lineNumber;
+ var columnNumber = frame.getColumnNumber();
+ if (columnNumber) {
+ fileLocation += ":" + columnNumber;
}
}
}
+
if (!fileLocation) {
fileLocation = "unknown source";
}
=======================================
--- /branches/bleeding_edge/test/mjsunit/stack-traces.js Fri Aug 14
04:24:32 2009
+++ /branches/bleeding_edge/test/mjsunit/stack-traces.js Mon Sep 20
08:55:28 2010
@@ -62,6 +62,16 @@
var x = "FAIL";
eval("function Outer() { eval('function Inner() { eval(x); }'); Inner();
}; Outer();");
}
+
+function testEvalWithSourceURL() {
+ eval("function Doo() { FAIL; }; Doo();\n//@ sourceURL=res://name");
+}
+
+function testNestedEvalWithSourceURL() {
+ var x = "FAIL";
+ var innerEval = 'function Inner() { eval(x); }\n//@
sourceURL=res://inner-eval';
+ eval("function Outer() { eval(innerEval); Inner(); }; Outer();\n//@
sourceURL=res://outer-eval");
+}
function testValue() {
Number.prototype.causeError = function () { FAIL; };
@@ -110,7 +120,7 @@
} catch (e) {
for (var i = 0; i < expected.length; i++) {
assertTrue(e.stack.indexOf(expected[i]) != -1,
- name + " doesn't contain expected[" + i + "]");
+ name + " doesn't contain expected[" + i + "] stack = " +
e.stack);
}
if (unexpected) {
for (var i = 0; i < unexpected.length; i++) {
@@ -190,6 +200,11 @@
testTrace("testImplicitConversion", testImplicitConversion, ["at
Nirk.valueOf"]);
testTrace("testEval", testEval, ["at Doo (eval at testEval"]);
testTrace("testNestedEval", testNestedEval, ["eval at Inner (eval at
Outer"]);
+testTrace("testEvalWithSourceURL", testEvalWithSourceURL,
+ [ "at Doo (res://name:1:18)" ]);
+testTrace("testNestedEvalWithSourceURL", testNestedEvalWithSourceURL,
+ [" at Inner (res://inner-eval:1:20)",
+ " at Outer (res://outer-eval:1:37)"]);
testTrace("testValue", testValue, ["at Number.causeError"]);
testTrace("testConstructor", testConstructor, ["new Plonk"]);
testTrace("testRenamedMethod", testRenamedMethod, ["Wookie.a$b$c$d [as
d]"]);
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev