From 9a39b3b9491219588c0c4e8bd04fbdf6d46e9cf2 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Mon, 7 Jun 2004 10:35:22 +0000 Subject: [PATCH] Switch to using Context.javaToJS instead of Context.toObject git-svn-id: svn://10.0.0.236/trunk@157503 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/rhino/docs/tutorial.html | 5 ++--- mozilla/js/rhino/examples/File.java | 4 ++-- mozilla/js/rhino/examples/RunScript2.java | 5 ++--- mozilla/js/rhino/examples/RunScript3.java | 1 - 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/mozilla/js/rhino/docs/tutorial.html b/mozilla/js/rhino/docs/tutorial.html index eeec6f2fff7..8324c2afbf3 100644 --- a/mozilla/js/rhino/docs/tutorial.html +++ b/mozilla/js/rhino/docs/tutorial.html @@ -210,9 +210,8 @@ hi

The next example is RunScript2. This is the same as RunScript, but with the addition of two extra lines of code: -

Scriptable jsArgs = Context.toObject(System.out, -scope); -
scope.put("out", scope, jsArgs);
+Object wrappedOut = Context.javaToJS(System.out, scope); +
ScriptableObject.putProperty(scope, "out", wrappedOut);
These lines add a global variable out that is a JavaScript reflection of the System.out variable: $ java RunScript2 'out.println(42)' diff --git a/mozilla/js/rhino/examples/File.java b/mozilla/js/rhino/examples/File.java index 52bb93d4b15..d39e3565da4 100644 --- a/mozilla/js/rhino/examples/File.java +++ b/mozilla/js/rhino/examples/File.java @@ -252,7 +252,7 @@ public class File extends ScriptableObject { // in a Scriptable object so that it can be manipulated by // JavaScript. Scriptable parent = ScriptableObject.getTopLevelScope(this); - return Context.toObject(reader, parent); + return Context.javaToJS(reader, parent); } /** @@ -265,7 +265,7 @@ public class File extends ScriptableObject { if (writer == null) return null; Scriptable parent = ScriptableObject.getTopLevelScope(this); - return Context.toObject(writer, parent); + return Context.javaToJS(writer, parent); } /** diff --git a/mozilla/js/rhino/examples/RunScript2.java b/mozilla/js/rhino/examples/RunScript2.java index 5021605ea78..79810aeb942 100644 --- a/mozilla/js/rhino/examples/RunScript2.java +++ b/mozilla/js/rhino/examples/RunScript2.java @@ -41,7 +41,6 @@ import org.mozilla.javascript.*; */ public class RunScript2 { public static void main(String args[]) - throws JavaScriptException { Context cx = Context.enter(); try { @@ -49,8 +48,8 @@ public class RunScript2 { // Add a global variable "out" that is a JavaScript reflection // of System.out - Scriptable jsArgs = Context.toObject(System.out, scope); - scope.put("out", scope, jsArgs); + Object jsOut = Context.javaToJS(System.out, scope); + ScriptableObject.putProperty(scope, "out", jsOut); String s = ""; for (int i=0; i < args.length; i++) { diff --git a/mozilla/js/rhino/examples/RunScript3.java b/mozilla/js/rhino/examples/RunScript3.java index 2bfee6033ee..f2505b4d063 100644 --- a/mozilla/js/rhino/examples/RunScript3.java +++ b/mozilla/js/rhino/examples/RunScript3.java @@ -44,7 +44,6 @@ import org.mozilla.javascript.*; */ public class RunScript3 { public static void main(String args[]) - throws JavaScriptException { Context cx = Context.enter(); try {