8019365: Error stack format
authorsundar
Fri, 28 Jun 2013 19:36:26 +0530
changeset 18624 6f7039271a0c
parent 18621 9e756415f82b
child 18625 13558072545a
8019365: Error stack format Reviewed-by: hannesw
nashorn/src/jdk/nashorn/api/scripting/NashornException.java
nashorn/src/jdk/nashorn/internal/objects/NativeError.java
nashorn/test/script/basic/JDK-8014781.js.EXPECTED
nashorn/test/script/basic/JDK-8017950.js.EXPECTED
nashorn/test/script/basic/JDK-8019226.js
nashorn/test/script/basic/JDK-8019226.js.EXPECTED
--- a/nashorn/src/jdk/nashorn/api/scripting/NashornException.java	Thu Jun 27 13:24:50 2013 +0530
+++ b/nashorn/src/jdk/nashorn/api/scripting/NashornException.java	Fri Jun 28 19:36:26 2013 +0530
@@ -172,12 +172,13 @@
         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'
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java	Thu Jun 27 13:24:50 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java	Fri Jun 28 19:36:26 2013 +0530
@@ -129,7 +129,7 @@
         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 @@
 
         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 @@
             throw new MethodHandleFactory.LookupException(e);
         }
     }
+
+    private static String getScriptStackString(final ScriptObject sobj, final Throwable exp) {
+        return JSType.toString(sobj) + "\n" + NashornException.getScriptStackString(exp);
+    }
 }
--- a/nashorn/test/script/basic/JDK-8014781.js.EXPECTED	Thu Jun 27 13:24:50 2013 +0530
+++ b/nashorn/test/script/basic/JDK-8014781.js.EXPECTED	Fri Jun 28 19:36:26 2013 +0530
@@ -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)
--- a/nashorn/test/script/basic/JDK-8017950.js.EXPECTED	Thu Jun 27 13:24:50 2013 +0530
+++ b/nashorn/test/script/basic/JDK-8017950.js.EXPECTED	Fri Jun 28 19:36:26 2013 +0530
@@ -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)
--- a/nashorn/test/script/basic/JDK-8019226.js	Thu Jun 27 13:24:50 2013 +0530
+++ b/nashorn/test/script/basic/JDK-8019226.js	Fri Jun 28 19:36:26 2013 +0530
@@ -30,7 +30,7 @@
 
 function func1() { func2() }
 
-function func2() { throw new Error() }
+function func2() { throw new Error("failed!") }
 
 try {
     func1()
--- a/nashorn/test/script/basic/JDK-8019226.js.EXPECTED	Thu Jun 27 13:24:50 2013 +0530
+++ b/nashorn/test/script/basic/JDK-8019226.js.EXPECTED	Fri Jun 28 19:36:26 2013 +0530
@@ -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)