Skip to content

Commit

Permalink
Formatting changes.
Browse files Browse the repository at this point in the history
apply spotless for all code
  • Loading branch information
tuchida authored and gbrail committed Jan 28, 2022
1 parent f7b16e9 commit 8fac718
Show file tree
Hide file tree
Showing 423 changed files with 15,388 additions and 17,219 deletions.
553 changes: 276 additions & 277 deletions benchmarks/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java

Large diffs are not rendered by default.

428 changes: 214 additions & 214 deletions benchmarks/org/mozilla/javascript/benchmarks/V8Benchmark.java

Large diffs are not rendered by default.

22 changes: 8 additions & 14 deletions examples/Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
/**
* Example of controlling the JavaScript execution engine.
*
* We evaluate a script and then manipulate the result.
*
* <p>We evaluate a script and then manipulate the result.
*/
public class Control {

/**
* Main entry point.
*
* Process arguments as would a normal Java program. Also
* create a new Context and associate it with the current thread.
* Then set up the execution environment and begin to
* execute scripts.
* <p>Process arguments as would a normal Java program. Also create a new Context and associate
* it with the current thread. Then set up the execution environment and begin to execute
* scripts.
*/
public static void main(String[] args)
{
public static void main(String[] args) {
Context cx = Context.enter();
try {
// Set version to JavaScript1.2 so that we get object-literal style
Expand All @@ -39,15 +36,14 @@ public static void main(String[] args)

// Now we can evaluate a script. Let's create a new object
// using the object literal notation.
Object result = cx.evaluateString(scope, "obj = {a:1, b:['x','y']}",
"MySource", 1, null);
Object result =
cx.evaluateString(scope, "obj = {a:1, b:['x','y']}", "MySource", 1, null);

Scriptable obj = (Scriptable) scope.get("obj", scope);

// Should print "obj == result" (Since the result of an assignment
// expression is the value that was assigned)
System.out.println("obj " + (obj == result ? "==" : "!=") +
" result");
System.out.println("obj " + (obj == result ? "==" : "!=") + " result");

// Should print "obj.a == 1"
System.out.println("obj.a == " + obj.get("a", obj));
Expand All @@ -67,6 +63,4 @@ public static void main(String[] args)
Context.exit();
}
}

}

18 changes: 13 additions & 5 deletions examples/Counter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,32 @@ public class Counter extends ScriptableObject {
private static final long serialVersionUID = 438270592527335642L;

// The zero-argument constructor used by Rhino runtime to create instances
public Counter() { }
public Counter() {}

// @JSConstructor annotation defines the JavaScript constructor
@JSConstructor
public Counter(int a) { count = a; }
public Counter(int a) {
count = a;
}

// The class name is defined by the getClassName method
@Override
public String getClassName() { return "Counter"; }
public String getClassName() {
return "Counter";
}

// The method getCount defines the count property.
@JSGetter
public int getCount() { return count++; }
public int getCount() {
return count++;
}

// Methods can be defined the @JSFunction annotation.
// Here we define resetCount for JavaScript.
@JSFunction
public void resetCount() { count = 0; }
public void resetCount() {
count = 0;
}

private int count;
}
17 changes: 7 additions & 10 deletions examples/CounterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import org.mozilla.javascript.ScriptableObject;

/**
* An example illustrating how to create a JavaScript object and retrieve
* properties and call methods.
* <p>
* Output should be:
* An example illustrating how to create a JavaScript object and retrieve properties and call
* methods.
*
* <p>Output should be:
*
* <pre>
* count = 0
* count = 1
Expand All @@ -22,8 +23,7 @@
*/
public class CounterTest {

public static void main(String[] args) throws Exception
{
public static void main(String[] args) throws Exception {
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects();
Expand All @@ -37,9 +37,7 @@ public static void main(String[] args) throws Exception
count = ScriptableObject.getProperty(testCounter, "count");
System.out.println("count = " + count);

ScriptableObject.callMethod(testCounter,
"resetCount",
new Object[0]);
ScriptableObject.callMethod(testCounter, "resetCount", new Object[0]);
System.out.println("resetCount");

count = ScriptableObject.getProperty(testCounter, "count");
Expand All @@ -48,5 +46,4 @@ public static void main(String[] args) throws Exception
Context.exit();
}
}

}
72 changes: 32 additions & 40 deletions examples/DynamicScopes.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

/**
* Example of controlling the JavaScript with multiple scopes and threads.
*/
/** Example of controlling the JavaScript with multiple scopes and threads. */
public class DynamicScopes {

static boolean useDynamicScope;

static class MyFactory extends ContextFactory
{
static class MyFactory extends ContextFactory {
@Override
protected boolean hasFeature(Context cx, int featureIndex)
{
protected boolean hasFeature(Context cx, int featureIndex) {
if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE) {
return useDynamicScope;
}
Expand All @@ -33,15 +29,14 @@ protected boolean hasFeature(Context cx, int featureIndex)
ContextFactory.initGlobal(new MyFactory());
}


/**
* Main entry point.
*
* Set up the shared scope and then spawn new threads that execute
* relative to that shared scope. Try to run functions with and
* without dynamic scope to see the effect.
* <p>Set up the shared scope and then spawn new threads that execute relative to that shared
* scope. Try to run functions with and without dynamic scope to see the effect.
*
* <p>The expected output is
*
* The expected output is
* <pre>
* sharedScope
* nested:sharedScope
Expand All @@ -56,23 +51,23 @@ protected boolean hasFeature(Context cx, int featureIndex)
* thread2
* nested:thread2
* </pre>
* The final three lines may be permuted in any order depending on
* thread scheduling.
*
* The final three lines may be permuted in any order depending on thread scheduling.
*/
public static void main(String[] args)
{
public static void main(String[] args) {
Context cx = Context.enter();
try {
// Precompile source only once
String source = ""
+"var x = 'sharedScope';\n"
+"function f() { return x; }\n"
String source =
""
+ "var x = 'sharedScope';\n"
+ "function f() { return x; }\n"
// Dynamic scope works with nested function too
+"function initClosure(prefix) {\n"
+" return function test() { return prefix+x; }\n"
+"}\n"
+"var closure = initClosure('nested:');\n"
+"";
+ "function initClosure(prefix) {\n"
+ " return function test() { return prefix+x; }\n"
+ "}\n"
+ "var closure = initClosure('nested:');\n"
+ "";
Script script = cx.compileString(source, "sharedScript", 1, null);

useDynamicScope = false;
Expand All @@ -84,8 +79,7 @@ public static void main(String[] args)
}
}

static void runScripts(Context cx, Script script)
{
static void runScripts(Context cx, Script script) {
// 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.
Expand Down Expand Up @@ -116,21 +110,20 @@ static void runScripts(Context cx, Script script)
// calls 'f') should not be seen by 'f'.
final int threadCount = 3;
Thread[] t = new Thread[threadCount];
for (int i=0; i < threadCount; i++) {
String source2 = ""
+"function g() { var x = 'local'; return f(); }\n"
+"java.lang.System.out.println(g());\n"
+"function g2() { var x = 'local'; return closure(); }\n"
+"java.lang.System.out.println(g2());\n"
+"";
t[i] = new Thread(new PerThread(sharedScope, source2,
"thread" + i));
for (int i = 0; i < threadCount; i++) {
String source2 =
""
+ "function g() { var x = 'local'; return f(); }\n"
+ "java.lang.System.out.println(g());\n"
+ "function g2() { var x = 'local'; return closure(); }\n"
+ "java.lang.System.out.println(g2());\n"
+ "";
t[i] = new Thread(new PerThread(sharedScope, source2, "thread" + i));
}
for (int i=0; i < threadCount; i++)
t[i].start();
for (int i = 0; i < threadCount; i++) t[i].start();
// Don't return in this thread until all the spawned threads have
// completed.
for (int i=0; i < threadCount; i++) {
for (int i = 0; i < threadCount; i++) {
try {
t[i].join();
} catch (InterruptedException e) {
Expand Down Expand Up @@ -168,10 +161,9 @@ public void run() {
Context.exit();
}
}

private Scriptable sharedScope;
private String source;
private String x;
}

}

Loading

0 comments on commit 8fac718

Please sign in to comment.