Debian Codegraph @

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

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.javascript.tests;
6
7 import java.io.InputStreamReader;
8
9 import junit.framework.TestCase;
10
11 import org.mozilla.javascript.Callable;
12 import org.mozilla.javascript.Context;
13 import org.mozilla.javascript.Script;
14 import org.mozilla.javascript.Scriptable;
15 import org.mozilla.javascript.ScriptableObject;
16
17 public class Bug482203Test extends TestCase {
18
19 public void testJsApi() throws Exception {
20 Context cx = Context.enter();
21 try {
22 cx.setOptimizationLevel(-1);
23 Script script = cx.compileReader(new InputStreamReader(
24 Bug482203Test.class.getResourceAsStream("Bug482203.js")),
25 "", 1, null);
26 Scriptable scope = cx.initStandardObjects();
27 script.exec(cx, scope);
28 int counter = 0;
29 for(;;)
30 {
31 Object cont = ScriptableObject.getProperty(scope, "c");
32 if(cont == null)
33 {
34 break;
35 }
36 counter++;
37 ((Callable)cont).call(cx, scope, scope, new Object[] { null });
38 }
39 assertEquals(counter, 5);
40 assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result"));
41 } finally {
42 Context.exit();
43 }
44 }
45
46 public void testJavaApi() throws Exception {
47 Context cx = Context.enter();
48 try {
49 cx.setOptimizationLevel(-1);
50 Script script = cx.compileReader(new InputStreamReader(
51 Bug482203Test.class.getResourceAsStream("Bug482203.js")),
52 "", 1, null);
53 Scriptable scope = cx.initStandardObjects();
54 cx.executeScriptWithContinuations(script, scope);
55 int counter = 0;
56 for(;;)
57 {
58 Object cont = ScriptableObject.getProperty(scope, "c");
59 if(cont == null)
60 {
61 break;
62 }
63 counter++;
64 cx.resumeContinuation(cont, scope, null);
65 }
66 assertEquals(counter, 5);
67 assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result"));
68 } finally {
69 Context.exit();
70 }
71 }
72 }