Skip to content

Commit

Permalink
fixes a few CR/LF issues
Browse files Browse the repository at this point in the history
  • Loading branch information
embeepea committed Oct 12, 2012
1 parent 90f5d1f commit 831b6f4
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 353 deletions.
234 changes: 117 additions & 117 deletions lib/rhino/testsrc/org/mozilla/javascript/tests/Bug421071Test.java
Original file line number Diff line number Diff line change
@@ -1,117 +1,117 @@
/*
* @(#)Bug421071Test.java
*
*/

package org.mozilla.javascript.tests;

import junit.framework.TestCase;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;

public class Bug421071Test extends TestCase {
private ContextFactory factory;
private TopLevelScope globalScope;
private Script testScript;

public void testProblemReplicator() throws Exception {
// before debugging please put the breakpoint in the
// NativeJavaPackage.getPkgProperty()
// and observe names passed in there
testScript = compileScript();
runTestScript(); // this one does not get to the
// NativeJavaPackage.getPkgProperty() on my
// variables
runTestScript(); // however this one does
}

private Script compileScript() {
String scriptSource = "importPackage(java.util);\n"
+ "var searchmon = 3;\n"
+ "var searchday = 10;\n"
+ "var searchyear = 2008;\n"
+ "var searchwkday = 0;\n"
+ "\n"
+ "var myDate = Calendar.getInstance();\n // this is a java.util.Calendar"
+ "myDate.set(Calendar.MONTH, searchmon);\n"
+ "myDate.set(Calendar.DATE, searchday);\n"
+ "myDate.set(Calendar.YEAR, searchyear);\n"
+ "searchwkday.value = myDate.get(Calendar.DAY_OF_WEEK);";
Script script;
Context context = factory.enterContext();
try {
script = context.compileString(scriptSource, "testScript", 1, null);
return script;
} finally {
Context.exit();
}
}

private void runTestScript() throws InterruptedException {
// will start new thread to get as close as possible to original
// environment, however the same behavior is exposed using new
// ScriptRunner(script).run();
Thread thread = new Thread(new ScriptRunner(testScript));
thread.start();
thread.join();
}

static class DynamicScopeContextFactory extends ContextFactory {
@Override
public boolean hasFeature(Context cx, int featureIndex) {
if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE)
return true;
return super.hasFeature(cx, featureIndex);
}
}

private TopLevelScope createGlobalScope() {
factory = new DynamicScopeContextFactory();
Context context = factory.enterContext();
// noinspection deprecation
TopLevelScope globalScope = new TopLevelScope(context);
Context.exit();
return globalScope;
}

@Override
protected void setUp() throws Exception {
super.setUp();
globalScope = createGlobalScope();
}

private class TopLevelScope extends ImporterTopLevel {
private static final long serialVersionUID = 7831526694313927899L;

public TopLevelScope(Context context) {
super(context);
}
}

private class ScriptRunner implements Runnable {
private Script script;

public ScriptRunner(Script script) {
this.script = script;
}

public void run() {
Context context = factory.enterContext();
try {
// Run each script in its own scope, to keep global variables
// defined in each script separate
Scriptable threadScope = context.newObject(globalScope);
threadScope.setPrototype(globalScope);
threadScope.setParentScope(null);
script.exec(context, threadScope);
} catch (Exception ee) {
ee.printStackTrace();
} finally {
Context.exit();
}
}
}
}
/*
* @(#)Bug421071Test.java
*
*/

package org.mozilla.javascript.tests;

import junit.framework.TestCase;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;

public class Bug421071Test extends TestCase {
private ContextFactory factory;
private TopLevelScope globalScope;
private Script testScript;

public void testProblemReplicator() throws Exception {
// before debugging please put the breakpoint in the
// NativeJavaPackage.getPkgProperty()
// and observe names passed in there
testScript = compileScript();
runTestScript(); // this one does not get to the
// NativeJavaPackage.getPkgProperty() on my
// variables
runTestScript(); // however this one does
}

private Script compileScript() {
String scriptSource = "importPackage(java.util);\n"
+ "var searchmon = 3;\n"
+ "var searchday = 10;\n"
+ "var searchyear = 2008;\n"
+ "var searchwkday = 0;\n"
+ "\n"
+ "var myDate = Calendar.getInstance();\n // this is a java.util.Calendar"
+ "myDate.set(Calendar.MONTH, searchmon);\n"
+ "myDate.set(Calendar.DATE, searchday);\n"
+ "myDate.set(Calendar.YEAR, searchyear);\n"
+ "searchwkday.value = myDate.get(Calendar.DAY_OF_WEEK);";
Script script;
Context context = factory.enterContext();
try {
script = context.compileString(scriptSource, "testScript", 1, null);
return script;
} finally {
Context.exit();
}
}

private void runTestScript() throws InterruptedException {
// will start new thread to get as close as possible to original
// environment, however the same behavior is exposed using new
// ScriptRunner(script).run();
Thread thread = new Thread(new ScriptRunner(testScript));
thread.start();
thread.join();
}

static class DynamicScopeContextFactory extends ContextFactory {
@Override
public boolean hasFeature(Context cx, int featureIndex) {
if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE)
return true;
return super.hasFeature(cx, featureIndex);
}
}

private TopLevelScope createGlobalScope() {
factory = new DynamicScopeContextFactory();
Context context = factory.enterContext();
// noinspection deprecation
TopLevelScope globalScope = new TopLevelScope(context);
Context.exit();
return globalScope;
}

@Override
protected void setUp() throws Exception {
super.setUp();
globalScope = createGlobalScope();
}

private class TopLevelScope extends ImporterTopLevel {
private static final long serialVersionUID = 7831526694313927899L;

public TopLevelScope(Context context) {
super(context);
}
}

private class ScriptRunner implements Runnable {
private Script script;

public ScriptRunner(Script script) {
this.script = script;
}

public void run() {
Context context = factory.enterContext();
try {
// Run each script in its own scope, to keep global variables
// defined in each script separate
Scriptable threadScope = context.newObject(globalScope);
threadScope.setPrototype(globalScope);
threadScope.setParentScope(null);
script.exec(context, threadScope);
} catch (Exception ee) {
ee.printStackTrace();
} finally {
Context.exit();
}
}
}
}
108 changes: 54 additions & 54 deletions lib/rhino/testsrc/org/mozilla/javascript/tests/Bug482203.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
package org.mozilla.javascript.tests;

import java.io.InputStreamReader;

import junit.framework.TestCase;

import org.mozilla.javascript.Callable;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class Bug482203 extends TestCase {
public void testJsApi() throws Exception {
Context cx = Context.enter();
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203.class.getResourceAsStream("conttest.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
script.exec(cx, scope);
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
((Callable)cont).call(cx, scope, scope, new Object[] { null });
}
}
public void testJavaApi() throws Exception {
Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203.class.getResourceAsStream("conttest.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
cx.executeScriptWithContinuations(script, scope);
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
cx.resumeContinuation(cont, scope, null);
}
} finally {
Context.exit();
}
}
}
package org.mozilla.javascript.tests;

import java.io.InputStreamReader;

import junit.framework.TestCase;

import org.mozilla.javascript.Callable;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class Bug482203 extends TestCase {
public void testJsApi() throws Exception {
Context cx = Context.enter();
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203.class.getResourceAsStream("conttest.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
script.exec(cx, scope);
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
((Callable)cont).call(cx, scope, scope, new Object[] { null });
}
}
public void testJavaApi() throws Exception {
Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203.class.getResourceAsStream("conttest.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
cx.executeScriptWithContinuations(script, scope);
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
cx.resumeContinuation(cont, scope, null);
}
} finally {
Context.exit();
}
}
}
Loading

0 comments on commit 831b6f4

Please sign in to comment.