Debian Codegraph @

rhino/examples/RunScript2.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 * RunScript2: Like RunScript, but reflects the System.out into JavaScript.
11 *
12 * @author Norris Boyd
13 */
14 public class RunScript2 {
15 public static void main(String args[])
16 {
17 Context cx = Context.enter();
18 try {
19 Scriptable scope = cx.initStandardObjects();
20
21 // Add a global variable "out" that is a JavaScript reflection
22 // of System.out
23 Object jsOut = Context.javaToJS(System.out, scope);
24 ScriptableObject.putProperty(scope, "out", jsOut);
25
26 String s = "";
27 for (int i=0; i < args.length; i++) {
28 s += args[i];
29 }
30 Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
31 System.err.println(Context.toString(result));
32 } finally {
33 Context.exit();
34 }
35 }
36
37 }
38