Add test cases for stacks
diff --git a/testsrc/jstests/extensions/stack-traces-rhino.js b/testsrc/jstests/extensions/stack-traces-rhino.js
index a1b218b..213a5d4 100644
--- a/testsrc/jstests/extensions/stack-traces-rhino.js
+++ b/testsrc/jstests/extensions/stack-traces-rhino.js
@@ -14,6 +14,7 @@
 }
 function nestedCapture(o, f) {
   Error.captureStackTrace(o, f);
+  Error.captureStackTrace(o, f);
 }
 function parentCapture(o, f) {
   nestedCapture(o, f);
@@ -29,16 +30,26 @@
   return msg.split('\n').length - 1;
 }
 
+// Test that a new Error contains at least one line
+// of stack trace.
+let err = new Error('Testing new error');
+assertEquals(err.message, 'Testing new error');
+assertEquals(1, countLines(err.stack));
+
 // Test that toString contains the error but not the stack
-// and test that the stack contains the file name
+// and test that the stack contains the file name. The file name
+// is only present if debug mode is on for code generation.
 try {
   throw new Error('Test 1');
 } catch (e) {
   assertFalse(e.stack == undefined);
   assertTrue(/Test 1/.test(e.toString()));
-  assertFalse(/stack-traces-rhino.js/.test(e.toString()));
   assertFalse(/Test 1/.test(e.stack));
-  assertTrue(/stack-traces-rhino.js/.test(e.stack));
+
+  if (ExpectFileNames) {
+    assertFalse(/stack-traces-rhino.js/.test(e.toString()));
+    assertTrue(/stack-traces-rhino.js/.test(e.stack));
+  }
 }
 
 // Assert that the function name is nested inside a nested stack trace
diff --git a/testsrc/org/mozilla/javascript/tests/StackTraceExtensionRhinoTest.java b/testsrc/org/mozilla/javascript/tests/StackTraceExtensionRhinoTest.java
index e003fbf..799cbc3 100644
--- a/testsrc/org/mozilla/javascript/tests/StackTraceExtensionRhinoTest.java
+++ b/testsrc/org/mozilla/javascript/tests/StackTraceExtensionRhinoTest.java
@@ -11,14 +11,14 @@
 import org.mozilla.javascript.tools.shell.Global;
 
 public class StackTraceExtensionRhinoTest {
-    private void testTraces(int opt) {
+    private void testTraces(int opt, boolean debug) {
         final ContextFactory factory =
                 new ContextFactory() {
                     @Override
                     protected boolean hasFeature(Context cx, int featureIndex) {
                         switch (featureIndex) {
                             case Context.FEATURE_LOCATION_INFORMATION_IN_ERROR:
-                                return true;
+                                return debug;
                             default:
                                 return super.hasFeature(cx, featureIndex);
                         }
@@ -29,13 +29,16 @@
         try {
             cx.setLanguageVersion(Context.VERSION_1_8);
             cx.setOptimizationLevel(opt);
-            cx.setGeneratingDebug(true);
+            cx.setGeneratingDebug(debug);
 
             Global global = new Global(cx);
             Scriptable root = cx.newObject(global);
 
             FileReader rdr = new FileReader("testsrc/jstests/extensions/stack-traces-rhino.js");
 
+            // Expect file names to be present in stack only if debug is on
+            global.put("ExpectFileNames", global, debug);
+
             try {
                 cx.evaluateReader(root, rdr, "stack-traces-rhino.js", 1, null);
             } finally {
@@ -49,17 +52,32 @@
     }
 
     @Test
+    public void testStackTrace0Debug() {
+        testTraces(0, true);
+    }
+
+    @Test
     public void testStackTrace0() {
-        testTraces(0);
+        testTraces(0, false);
     }
 
     @Test
     public void testStackTrace9() {
-        testTraces(9);
+        testTraces(9, false);
+    }
+
+    @Test
+    public void testStackTrace9Debug() {
+        testTraces(9, true);
     }
 
     @Test
     public void testStackTraceInt() {
-        testTraces(-1);
+        testTraces(-1, false);
+    }
+
+    @Test
+    public void testStackTraceIntDebug() {
+        testTraces(-1, true);
     }
 }