Skip to content

Commit 11b82e9

Browse files
aardvark179gbrail
authored andcommitted
Change ScriptableObject to TopLevel to avoid churn later.
1 parent 44fe30d commit 11b82e9

89 files changed

Lines changed: 301 additions & 307 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/src/main/java/Control.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.mozilla.javascript.Function;
99
import org.mozilla.javascript.Scriptable;
1010
import org.mozilla.javascript.ScriptableObject;
11+
import org.mozilla.javascript.TopLevel;
1112

1213
/**
1314
* Example of controlling the JavaScript execution engine.
@@ -32,7 +33,7 @@ public static void main(String[] args) {
3233

3334
// Initialize the standard objects (Object, Function, etc.)
3435
// This must be done before scripts can be executed.
35-
Scriptable scope = cx.initStandardObjects();
36+
TopLevel scope = cx.initStandardObjects();
3637

3738
// Now we can evaluate a script. Let's create a new object
3839
// using the object literal notation.

examples/src/main/java/CounterTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.mozilla.javascript.Context;
88
import org.mozilla.javascript.Scriptable;
99
import org.mozilla.javascript.ScriptableObject;
10+
import org.mozilla.javascript.TopLevel;
1011

1112
/**
1213
* An example illustrating how to create a JavaScript object and retrieve properties and call
@@ -62,7 +63,7 @@ public class CounterTest {
6263
public static void main(String[] args) throws Exception {
6364
Context cx = Context.enter();
6465
try {
65-
Scriptable scope = cx.initStandardObjects();
66+
TopLevel scope = cx.initStandardObjects();
6667
ScriptableObject.defineClass(scope, Counter.class);
6768

6869
Scriptable testCounter = cx.newObject(scope, "Counter");

examples/src/main/java/DynamicScopes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.mozilla.javascript.ContextFactory;
99
import org.mozilla.javascript.Script;
1010
import org.mozilla.javascript.Scriptable;
11-
import org.mozilla.javascript.ScriptableObject;
11+
import org.mozilla.javascript.TopLevel;
1212

1313
/** Example of controlling the JavaScript with multiple scopes and threads. */
1414
public class DynamicScopes {
@@ -85,7 +85,7 @@ static void runScripts(Context cx, Script script) {
8585
// Initialize the standard objects (Object, Function, etc.)
8686
// This must be done before scripts can be executed. The call
8787
// returns a new scope that we will share.
88-
ScriptableObject sharedScope = cx.initStandardObjects(null, true);
88+
TopLevel sharedScope = cx.initStandardObjects(null, true);
8989

9090
// Now we can execute the precompiled script against the scope
9191
// to define x variable and f function in the shared scope.

examples/src/main/java/RunScript.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

77
import org.mozilla.javascript.Context;
8-
import org.mozilla.javascript.Scriptable;
8+
import org.mozilla.javascript.TopLevel;
99

1010
/**
1111
* RunScript: simplest example of controlling execution of Rhino.
@@ -54,7 +54,7 @@ public static void main(String args[]) {
5454
// Initialize the standard objects (Object, Function, etc.)
5555
// This must be done before scripts can be executed. Returns
5656
// a scope object that we use in later calls.
57-
Scriptable scope = cx.initStandardObjects();
57+
TopLevel scope = cx.initStandardObjects();
5858

5959
// Collect the arguments into a single string.
6060
String s = "";

examples/src/main/java/RunScript2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

77
import org.mozilla.javascript.Context;
8-
import org.mozilla.javascript.Scriptable;
98
import org.mozilla.javascript.ScriptableObject;
9+
import org.mozilla.javascript.TopLevel;
1010

1111
/**
1212
* RunScript2: Like RunScript, but reflects the System.out into JavaScript.
@@ -53,7 +53,7 @@ public class RunScript2 {
5353
public static void main(String args[]) {
5454
Context cx = Context.enter();
5555
try {
56-
Scriptable scope = cx.initStandardObjects();
56+
TopLevel scope = cx.initStandardObjects();
5757

5858
// Add a global variable "out" that is a JavaScript reflection
5959
// of System.out

examples/src/main/java/RunScript3.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.mozilla.javascript.Context;
88
import org.mozilla.javascript.Function;
99
import org.mozilla.javascript.Scriptable;
10+
import org.mozilla.javascript.TopLevel;
1011

1112
/**
1213
* RunScript3: Example of using JavaScript objects
@@ -69,7 +70,7 @@ public class RunScript3 {
6970
public static void main(String args[]) {
7071
Context cx = Context.enter();
7172
try {
72-
Scriptable scope = cx.initStandardObjects();
73+
TopLevel scope = cx.initStandardObjects();
7374

7475
// Collect the arguments into a single string.
7576
String s = "";

examples/src/main/java/RunScript4.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.mozilla.javascript.Context;
88
import org.mozilla.javascript.Scriptable;
99
import org.mozilla.javascript.ScriptableObject;
10+
import org.mozilla.javascript.TopLevel;
1011

1112
/**
1213
* RunScript4: Execute scripts in an environment that includes the example Counter class.
@@ -69,7 +70,7 @@ public class RunScript4 {
6970
public static void main(String args[]) throws Exception {
7071
Context cx = Context.enter();
7172
try {
72-
Scriptable scope = cx.initStandardObjects();
73+
TopLevel scope = cx.initStandardObjects();
7374

7475
// Use the Counter class to define a Counter constructor
7576
// and prototype in JavaScript.

rhino-engine/src/main/java/org/mozilla/javascript/engine/Builtins.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.mozilla.javascript.ScriptRuntime;
1414
import org.mozilla.javascript.Scriptable;
1515
import org.mozilla.javascript.ScriptableObject;
16+
import org.mozilla.javascript.TopLevel;
1617
import org.mozilla.javascript.Undefined;
1718

1819
/**
@@ -29,20 +30,21 @@ public class Builtins {
2930

3031
private Writer stdout;
3132

32-
void register(Context cx, ScriptableObject scope, ScriptContext sc) {
33+
void register(Context cx, TopLevel scope, ScriptContext sc) {
3334
if (sc.getWriter() == null) {
3435
stdout = new OutputStreamWriter(System.out, StandardCharsets.UTF_8);
3536
} else {
3637
stdout = sc.getWriter();
3738
}
3839

39-
scope.defineProperty(
40-
scope,
41-
"print",
42-
0,
43-
Builtins::print,
44-
ScriptableObject.PERMANENT | ScriptableObject.DONTENUM,
45-
ScriptableObject.DONTENUM | ScriptableObject.READONLY);
40+
scope.getGlobalThis()
41+
.defineProperty(
42+
scope,
43+
"print",
44+
0,
45+
Builtins::print,
46+
ScriptableObject.PERMANENT | ScriptableObject.DONTENUM,
47+
ScriptableObject.DONTENUM | ScriptableObject.READONLY);
4648
}
4749

4850
private static Object print(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {

rhino-xml/src/test/java/org/mozilla/javascript/tests/XMLSecureParserTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.junit.Test;
1313
import org.mozilla.javascript.Context;
1414
import org.mozilla.javascript.ContextFactory;
15-
import org.mozilla.javascript.Scriptable;
15+
import org.mozilla.javascript.TopLevel;
1616

1717
/**
1818
* Test for secure xml parsing
@@ -121,7 +121,7 @@ public void xmlInsecureConfiguration() {
121121
}
122122

123123
private void executeXML(Context cx) {
124-
Scriptable scope = cx.initStandardObjects();
124+
TopLevel scope = cx.initStandardObjects();
125125
cx.evaluateString(scope, "new XML('<a></a>').toXMLString();", "source", 1, null);
126126
}
127127

rhino-xml/src/test/java/org/mozilla/javascript/xmlimpl/tests/XmlNonResettableDocumentBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.junit.Test;
77
import org.mozilla.javascript.Context;
88
import org.mozilla.javascript.ContextFactory;
9-
import org.mozilla.javascript.Scriptable;
9+
import org.mozilla.javascript.TopLevel;
1010

1111
public class XmlNonResettableDocumentBuilderTest {
1212
private static final String XML_PROPERTY = "javax.xml.parsers.DocumentBuilderFactory";
@@ -29,7 +29,7 @@ public void tearDown() {
2929
@Test
3030
public void nonResettableDocumentBuilder() {
3131
try (Context cx = new ContextFactory().enterContext()) {
32-
Scriptable scope = cx.initStandardObjects();
32+
TopLevel scope = cx.initStandardObjects();
3333
Object result =
3434
cx.evaluateString(
3535
scope,

0 commit comments

Comments
 (0)