Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/tests/StackTraceExtensionTest.java

raw symbols SCIP
1 package org.mozilla.javascript.tests;
2
3 import org.junit.AfterClass;
4 import org.junit.BeforeClass;
5 import org.junit.Test;
6 import org.mozilla.javascript.Context;
7 import org.mozilla.javascript.ContextFactory;
8 import org.mozilla.javascript.RhinoException;
9 import org.mozilla.javascript.Scriptable;
10 import org.mozilla.javascript.StackStyle;
11 import org.mozilla.javascript.tools.shell.Global;
12
13 import java.io.FileReader;
14 import java.io.IOException;
15
16 import static org.junit.Assert.*;
17
18 public class StackTraceExtensionTest
19 {
20 @BeforeClass
21 public static void init()
22 {
23 RhinoException.setStackStyle(StackStyle.V8);
24 }
25
26 @AfterClass
27 public static void terminate()
28 {
29 RhinoException.setStackStyle(StackStyle.RHINO);
30 }
31
32 private void testTraces(int opt)
33 {
34 final ContextFactory factory = new ContextFactory() {
35 @Override
36 protected boolean hasFeature(Context cx, int featureIndex)
37 {
38 switch (featureIndex) {
39 case Context.FEATURE_LOCATION_INFORMATION_IN_ERROR:
40 return true;
41 default:
42 return super.hasFeature(cx, featureIndex);
43 }
44 }
45 };
46
47 Context cx = factory.enterContext();
48 try {
49 cx.setLanguageVersion(Context.VERSION_1_8);
50 cx.setOptimizationLevel(opt);
51 cx.setGeneratingDebug(true);
52
53 Global global = new Global(cx);
54 Scriptable root = cx.newObject(global);
55
56 FileReader rdr = new FileReader("testsrc/jstests/extensions/stack-traces.js");
57
58 try {
59 cx.evaluateReader(root, rdr, "stack-traces.js", 1, null);
60 } finally {
61 rdr.close();
62 }
63 } catch (IOException ioe) {
64 assertFalse("I/O Error: " + ioe, true);
65 } finally {
66 Context.exit();
67 }
68 }
69
70 @Test
71 public void testStackTrace0()
72 {
73 testTraces(0);
74 }
75
76 @Test
77 public void testStackTrace9()
78 {
79 testTraces(9);
80 }
81
82 @Test
83 public void testStackTraceInt()
84 {
85 testTraces(-1);
86 }
87 }