Debian Codegraph @

rhino/examples/CounterTest.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 import org.mozilla.javascript.*;
8
9 /**
10 * An example illustrating how to create a JavaScript object and retrieve
11 * properties and call methods.
12 * <p>
13 * Output should be:
14 * <pre>
15 * count = 0
16 * count = 1
17 * resetCount
18 * count = 0
19 * </pre>
20 */
21 public class CounterTest {
22
23 public static void main(String[] args) throws Exception
24 {
25 Context cx = Context.enter();
26 try {
27 Scriptable scope = cx.initStandardObjects();
28 ScriptableObject.defineClass(scope, Counter.class);
29
30 Scriptable testCounter = cx.newObject(scope, "Counter");
31
32 Object count = ScriptableObject.getProperty(testCounter, "count");
33 System.out.println("count = " + count);
34
35 count = ScriptableObject.getProperty(testCounter, "count");
36 System.out.println("count = " + count);
37
38 ScriptableObject.callMethod(testCounter,
39 "resetCount",
40 new Object[0]);
41 System.out.println("resetCount");
42
43 count = ScriptableObject.getProperty(testCounter, "count");
44 System.out.println("count = " + count);
45 } finally {
46 Context.exit();
47 }
48 }
49
50 }