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 () {
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 @@ CallSite.prototype.isConstructor = function () {
};
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 @@ function FormatEvalOrigin(script) {
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 FormatEvalOrigin(script) {
};
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";
}
......
......@@ -63,6 +63,16 @@ function testNestedEval() {
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; };
(1).causeError();
......@@ -110,7 +120,7 @@ function testTrace(name, fun, expected, unexpected) {
} 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("testMethodNameInference", testMethodNameInference, ["at Foo.bar"]);
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]"]);
......
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