Commit b2f444f6 authored by yurys@chromium.org's avatar yurys@chromium.org

Use //@ sourceURL when formatting stack trace

BUG=672
Review URL: http://codereview.chromium.org/3444011

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5498 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ceb9d79d
...@@ -684,6 +684,11 @@ CallSite.prototype.getEvalOrigin = function () { ...@@ -684,6 +684,11 @@ CallSite.prototype.getEvalOrigin = function () {
return FormatEvalOrigin(script); return FormatEvalOrigin(script);
}; };
CallSite.prototype.getScriptNameOrSourceURL = function () {
var script = %FunctionGetScript(this.fun);
return script ? script.nameOrSourceURL() : null;
};
CallSite.prototype.getFunction = function () { CallSite.prototype.getFunction = function () {
return this.fun; return this.fun;
}; };
...@@ -775,7 +780,11 @@ CallSite.prototype.isConstructor = function () { ...@@ -775,7 +780,11 @@ CallSite.prototype.isConstructor = function () {
}; };
function FormatEvalOrigin(script) { 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) { if (script.eval_from_function_name) {
eval_origin += script.eval_from_function_name; eval_origin += script.eval_from_function_name;
} else { } else {
...@@ -786,9 +795,9 @@ function FormatEvalOrigin(script) { ...@@ -786,9 +795,9 @@ function FormatEvalOrigin(script) {
if (eval_from_script) { if (eval_from_script) {
if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) { if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) {
// eval script originated from another eval. // eval script originated from another eval.
eval_origin += " (eval at " + FormatEvalOrigin(eval_from_script) + ")"; eval_origin += " (" + FormatEvalOrigin(eval_from_script) + ")";
} else { } else {
// eval script originated from "real" scource. // eval script originated from "real" source.
if (eval_from_script.name) { if (eval_from_script.name) {
eval_origin += " (" + eval_from_script.name; eval_origin += " (" + eval_from_script.name;
var location = eval_from_script.locationFromPosition(script.eval_from_script_position, true); var location = eval_from_script.locationFromPosition(script.eval_from_script_position, true);
...@@ -807,25 +816,30 @@ function FormatEvalOrigin(script) { ...@@ -807,25 +816,30 @@ function FormatEvalOrigin(script) {
}; };
function FormatSourcePosition(frame) { function FormatSourcePosition(frame) {
var fileName;
var fileLocation = ""; var fileLocation = "";
if (frame.isNative()) { if (frame.isNative()) {
fileLocation = "native"; fileLocation = "native";
} else if (frame.isEval()) { } else if (frame.isEval()) {
fileLocation = "eval at " + frame.getEvalOrigin(); fileName = frame.getScriptNameOrSourceURL();
if (!fileName)
fileLocation = frame.getEvalOrigin();
} else { } else {
var fileName = frame.getFileName(); fileName = frame.getFileName();
if (fileName) { }
fileLocation += fileName;
var lineNumber = frame.getLineNumber(); if (fileName) {
if (lineNumber != null) { fileLocation += fileName;
fileLocation += ":" + lineNumber; var lineNumber = frame.getLineNumber();
var columnNumber = frame.getColumnNumber(); if (lineNumber != null) {
if (columnNumber) { fileLocation += ":" + lineNumber;
fileLocation += ":" + columnNumber; var columnNumber = frame.getColumnNumber();
} if (columnNumber) {
fileLocation += ":" + columnNumber;
} }
} }
} }
if (!fileLocation) { if (!fileLocation) {
fileLocation = "unknown source"; fileLocation = "unknown source";
} }
......
...@@ -63,6 +63,16 @@ function testNestedEval() { ...@@ -63,6 +63,16 @@ function testNestedEval() {
eval("function Outer() { eval('function Inner() { eval(x); }'); Inner(); }; Outer();"); 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() { function testValue() {
Number.prototype.causeError = function () { FAIL; }; Number.prototype.causeError = function () { FAIL; };
(1).causeError(); (1).causeError();
...@@ -110,7 +120,7 @@ function testTrace(name, fun, expected, unexpected) { ...@@ -110,7 +120,7 @@ function testTrace(name, fun, expected, unexpected) {
} catch (e) { } catch (e) {
for (var i = 0; i < expected.length; i++) { for (var i = 0; i < expected.length; i++) {
assertTrue(e.stack.indexOf(expected[i]) != -1, assertTrue(e.stack.indexOf(expected[i]) != -1,
name + " doesn't contain expected[" + i + "]"); name + " doesn't contain expected[" + i + "] stack = " + e.stack);
} }
if (unexpected) { if (unexpected) {
for (var i = 0; i < unexpected.length; i++) { for (var i = 0; i < unexpected.length; i++) {
...@@ -190,6 +200,11 @@ testTrace("testMethodNameInference", testMethodNameInference, ["at Foo.bar"]); ...@@ -190,6 +200,11 @@ testTrace("testMethodNameInference", testMethodNameInference, ["at Foo.bar"]);
testTrace("testImplicitConversion", testImplicitConversion, ["at Nirk.valueOf"]); testTrace("testImplicitConversion", testImplicitConversion, ["at Nirk.valueOf"]);
testTrace("testEval", testEval, ["at Doo (eval at testEval"]); testTrace("testEval", testEval, ["at Doo (eval at testEval"]);
testTrace("testNestedEval", testNestedEval, ["eval at Inner (eval at Outer"]); 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("testValue", testValue, ["at Number.causeError"]);
testTrace("testConstructor", testConstructor, ["new Plonk"]); testTrace("testConstructor", testConstructor, ["new Plonk"]);
testTrace("testRenamedMethod", testRenamedMethod, ["Wookie.a$b$c$d [as d]"]); testTrace("testRenamedMethod", testRenamedMethod, ["Wookie.a$b$c$d [as d]"]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment