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 StringBuilder buf = new StringBuilder();
final StackTraceElement[] frames = getScriptFrames((Throwable)exception); final StackTraceElement[] frames = getScriptFrames((Throwable)exception);
for (final StackTraceElement st : frames) { for (final StackTraceElement st : frames) {
buf.append("\tat ");
buf.append(st.getMethodName()); buf.append(st.getMethodName());
buf.append(" @ "); buf.append(" (");
buf.append(st.getFileName()); buf.append(st.getFileName());
buf.append(':'); buf.append(':');
buf.append(st.getLineNumber()); buf.append(st.getLineNumber());
buf.append('\n'); buf.append(")\n");
} }
final int len = buf.length(); final int len = buf.length();
// remove trailing '\n' // remove trailing '\n'

View File

@ -129,7 +129,7 @@ public final class NativeError extends ScriptObject {
Global.checkObject(errorObj); Global.checkObject(errorObj);
final ScriptObject sobj = (ScriptObject)errorObj; final ScriptObject sobj = (ScriptObject)errorObj;
final ECMAException exp = new ECMAException(sobj, null); final ECMAException exp = new ECMAException(sobj, null);
sobj.set("stack", NashornException.getScriptStackString(exp), false); sobj.set("stack", getScriptStackString(sobj, exp), false);
return UNDEFINED; return UNDEFINED;
} }
@ -288,7 +288,7 @@ public final class NativeError extends ScriptObject {
final Object exception = ECMAException.getException(sobj); final Object exception = ECMAException.getException(sobj);
if (exception instanceof Throwable) { if (exception instanceof Throwable) {
return NashornException.getScriptStackString((Throwable)exception); return getScriptStackString(sobj, (Throwable)exception);
} else { } else {
return ""; return "";
} }
@ -362,4 +362,8 @@ public final class NativeError extends ScriptObject {
throw new MethodHandleFactory.LookupException(e); 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 [object Object]
func @ test/script/basic/JDK-8014781.js:36 at MyError (test/script/basic/JDK-8014781.js:32)
<program> @ test/script/basic/JDK-8014781.js:39 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 Error
f @ test/script/basic/JDK-8017950.js:40 at func (test/script/basic/JDK-8017950.js:33)
g @ test/script/basic/JDK-8017950.js:44 at f (test/script/basic/JDK-8017950.js:40)
<program> @ test/script/basic/JDK-8017950.js:47 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 func1() { func2() }
function func2() { throw new Error() } function func2() { throw new Error("failed!") }
try { try {
func1() func1()

View File

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