return FormatEvalOrigin(script);
};
+CallSite.prototype.getScriptNameOrSourceURL = function () {
+ var script = %FunctionGetScript(this.fun);
+ return script ? script.nameOrSourceURL() : null;
+};
+
CallSite.prototype.getFunction = function () {
return this.fun;
};
};
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 {
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);
};
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";
}
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();
} 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++) {
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]"]);