| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package org.mozilla.javascript.tests; |
| 9 |
|
| 10 |
import junit.framework.TestCase; |
| 11 |
|
| 12 |
import org.mozilla.javascript.Context; |
| 13 |
import org.mozilla.javascript.Scriptable; |
| 14 |
import org.mozilla.javascript.ClassShutter; |
| 15 |
import org.mozilla.javascript.RhinoException; |
| 16 |
import org.mozilla.javascript.EvaluatorException; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public class ClassShutterExceptionTest extends TestCase { |
| 22 |
private static Context.ClassShutterSetter classShutterSetter; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
static class OpaqueShutter implements ClassShutter { |
| 28 |
public boolean visibleToScripts(String name) { |
| 29 |
return false; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
public void helper(String source) { |
| 34 |
Context cx = Context.enter(); |
| 35 |
Context.ClassShutterSetter setter = cx.getClassShutterSetter(); |
| 36 |
try { |
| 37 |
Scriptable globalScope = cx.initStandardObjects(); |
| 38 |
if (setter == null) { |
| 39 |
setter = classShutterSetter; |
| 40 |
} else { |
| 41 |
classShutterSetter = setter; |
| 42 |
} |
| 43 |
setter.setClassShutter(new OpaqueShutter()); |
| 44 |
cx.evaluateString(globalScope, source, "test source", 1, null); |
| 45 |
} finally { |
| 46 |
setter.setClassShutter(null); |
| 47 |
Context.exit(); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
public void testClassShutterException() { |
| 52 |
try { |
| 53 |
helper("java.lang.System.out.println('hi');"); |
| 54 |
fail(); |
| 55 |
} catch (RhinoException e) { |
| 56 |
|
| 57 |
return; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
public void testThrowingException() { |
| 62 |
|
| 63 |
|
| 64 |
helper("try { throw 3; } catch (e) { }"); |
| 65 |
} |
| 66 |
|
| 67 |
public void testThrowingEcmaError() { |
| 68 |
try { |
| 69 |
|
| 70 |
|
| 71 |
helper("friggin' syntax error!"); |
| 72 |
fail("Should have thrown an exception"); |
| 73 |
} catch (EvaluatorException e) { |
| 74 |
|
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
public void testThrowingEvaluatorException() { |
| 79 |
|
| 80 |
|
| 81 |
helper("try { eval('for;if;else'); } catch (e) { }"); |
| 82 |
} |
| 83 |
} |