8019365: Error stack format

Reviewed-by: hannesw
This commit is contained in:
Athijegannathan Sundararajan 2013-06-28 19:36:26 +05:30
parent a089899deb
commit 0eb7f23c99
6 changed files with 23 additions and 15 deletions

View File

@ -172,12 +172,13 @@ public abstract class NashornException extends RuntimeException {
final StringBuilder buf = new StringBuilder();
final StackTraceElement[] frames = getScriptFrames((Throwable)exception);
for (final StackTraceElement st : frames) {
buf.append("\tat ");
buf.append(st.getMethodName());
buf.append(" @ ");
buf.append(" (");
buf.append(st.getFileName());
buf.append(':');
buf.append(st.getLineNumber());
buf.append('\n');
buf.append(")\n");
}
final int len = buf.length();
// remove trailing '\n'

View File

@ -129,7 +129,7 @@ public final class NativeError extends ScriptObject {
Global.checkObject(errorObj);
final ScriptObject sobj = (ScriptObject)errorObj;
final ECMAException exp = new ECMAException(sobj, null);
sobj.set("stack", NashornException.getScriptStackString(exp), false);
sobj.set("stack", getScriptStackString(sobj, exp), false);
return UNDEFINED;
}
@ -288,7 +288,7 @@ public final class NativeError extends ScriptObject {
final Object exception = ECMAException.getException(sobj);
if (exception instanceof Throwable) {
return NashornException.getScriptStackString((Throwable)exception);
return getScriptStackString(sobj, (Throwable)exception);
} else {
return "";
}
@ -362,4 +362,8 @@ public final class NativeError extends ScriptObject {
throw new MethodHandleFactory.LookupException(e);
}
}
private static String getScriptStackString(final ScriptObject sobj, final Throwable exp) {
return JSType.toString(sobj) + "\n" + NashornException.getScriptStackString(exp);
}
}

View File

@ -1,3 +1,4 @@
MyError @ test/script/basic/JDK-8014781.js:32
func @ test/script/basic/JDK-8014781.js:36
<program> @ test/script/basic/JDK-8014781.js:39
[object Object]
at MyError (test/script/basic/JDK-8014781.js:32)
at func (test/script/basic/JDK-8014781.js:36)
at <program> (test/script/basic/JDK-8014781.js:39)

View File

@ -1,4 +1,5 @@
func @ test/script/basic/JDK-8017950.js:33
f @ test/script/basic/JDK-8017950.js:40
g @ test/script/basic/JDK-8017950.js:44
<program> @ test/script/basic/JDK-8017950.js:47
Error
at func (test/script/basic/JDK-8017950.js:33)
at f (test/script/basic/JDK-8017950.js:40)
at g (test/script/basic/JDK-8017950.js:44)
at <program> (test/script/basic/JDK-8017950.js:47)

View File

@ -30,7 +30,7 @@
function func1() { func2() }
function func2() { throw new Error() }
function func2() { throw new Error("failed!") }
try {
func1()

View File

@ -1,3 +1,4 @@
func2 @ test/script/basic/JDK-8019226.js:33
func1 @ test/script/basic/JDK-8019226.js:31
<program> @ test/script/basic/JDK-8019226.js:36
Error: failed!
at func2 (test/script/basic/JDK-8019226.js:33)
at func1 (test/script/basic/JDK-8019226.js:31)
at <program> (test/script/basic/JDK-8019226.js:36)