Use newly introduced Context.initStandardObjects(), not initStandardObjects(null) in the examples
git-svn-id: svn://10.0.0.236/trunk@147795 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -59,7 +59,7 @@ public class Control {
|
||||
|
||||
// Initialize the standard objects (Object, Function, etc.)
|
||||
// This must be done before scripts can be executed.
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
Scriptable scope = cx.initStandardObjects();
|
||||
|
||||
// Now we can evaluate a script. Let's create a new object
|
||||
// using the object literal notation.
|
||||
|
||||
@@ -53,7 +53,7 @@ public class CounterTest {
|
||||
{
|
||||
Context cx = Context.enter();
|
||||
try {
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
Scriptable scope = cx.initStandardObjects();
|
||||
ScriptableObject.defineClass(scope, Counter.class);
|
||||
|
||||
Scriptable testCounter = cx.newObject(scope, "Counter");
|
||||
|
||||
@@ -79,7 +79,7 @@ public class DynamicScopes {
|
||||
// Initialize the standard objects (Object, Function, etc.)
|
||||
// This must be done before scripts can be executed. The call
|
||||
// returns a new scope that we will share.
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
Scriptable scope = cx.initStandardObjects();
|
||||
|
||||
// Now we can evaluate a script and functions will be compiled to
|
||||
// use dynamic scope if the Context is so initialized.
|
||||
@@ -159,9 +159,6 @@ public class DynamicScopes {
|
||||
catch (NotAFunctionException jse) {
|
||||
// ignore
|
||||
}
|
||||
catch (PropertyException jse) {
|
||||
// ignore
|
||||
}
|
||||
catch (JavaScriptException jse) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@@ -143,17 +143,8 @@ public class File extends ScriptableObject {
|
||||
v.copyInto(lines);
|
||||
|
||||
Scriptable scope = ScriptableObject.getTopLevelScope(this);
|
||||
Scriptable result;
|
||||
try {
|
||||
Context cx = Context.getCurrentContext();
|
||||
result = cx.newObject(scope, "Array", lines);
|
||||
} catch (PropertyException e) {
|
||||
throw Context.reportRuntimeError(e.getMessage());
|
||||
} catch (NotAFunctionException e) {
|
||||
throw Context.reportRuntimeError(e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
Context cx = Context.getCurrentContext();
|
||||
return cx.newObject(scope, "Array", lines);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,6 @@ java -classpath js.jar org.mozilla.javascript.tools.jsc.Main \
|
||||
</pre>
|
||||
and the resulting 2 classes, NervousText.class extending java.applet.Applet and implementing java.lang.Runnable and NervousText1.class which represents compiled JavaScript code, are placed in the same directory as NervousText.html.
|
||||
<p>
|
||||
The test also assumes that js.jar from Rhino distribution is available in the same directory.
|
||||
The test also assumes that js.jar from Rhino distribution is available in the same directory.
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -40,8 +40,9 @@ import org.mozilla.javascript.*;
|
||||
* that can be converted to ECMA primitive values.
|
||||
* So java.lang.String is mapped to ECMA string, all java.lang.Numbers are
|
||||
* mapped to ECMA numbers, and java.lang.Booleans are mapped to ECMA booleans
|
||||
* instead of being wrapped as objects. Additionally java.lang.Characters are
|
||||
* converted to ECMA strings. Other types have the default behavior.
|
||||
* instead of being wrapped as objects. Additionally java.lang.Character is
|
||||
* converted to ECMA string with length 1.
|
||||
* Other types have the default behavior.
|
||||
* <p>
|
||||
* Note that calling "new java.lang.String('foo')" in JavaScript with this
|
||||
* wrap factory enabled will still produce a wrapped Java object since the
|
||||
|
||||
@@ -53,7 +53,7 @@ public class RunScript {
|
||||
// Initialize the standard objects (Object, Function, etc.)
|
||||
// This must be done before scripts can be executed. Returns
|
||||
// a scope object that we use in later calls.
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
Scriptable scope = cx.initStandardObjects();
|
||||
|
||||
// Collect the arguments into a single string.
|
||||
String s = "";
|
||||
|
||||
@@ -45,7 +45,7 @@ public class RunScript2 {
|
||||
{
|
||||
Context cx = Context.enter();
|
||||
try {
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
Scriptable scope = cx.initStandardObjects();
|
||||
|
||||
// Add a global variable "out" that is a JavaScript reflection
|
||||
// of System.out
|
||||
|
||||
@@ -48,7 +48,7 @@ public class RunScript3 {
|
||||
{
|
||||
Context cx = Context.enter();
|
||||
try {
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
Scriptable scope = cx.initStandardObjects();
|
||||
|
||||
// Collect the arguments into a single string.
|
||||
String s = "";
|
||||
|
||||
@@ -46,7 +46,7 @@ public class RunScript4 {
|
||||
{
|
||||
Context cx = Context.enter();
|
||||
try {
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
Scriptable scope = cx.initStandardObjects();
|
||||
|
||||
// Use the Counter class to define a Counter constructor
|
||||
// and prototype in JavaScript.
|
||||
|
||||
Reference in New Issue
Block a user