Skip to content

Commit

Permalink
Remove deprecated functions from rhino module
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrail committed Dec 11, 2024
1 parent d15eb7a commit a8190a7
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static class AbstractClassState {
public void init()
throws IllegalAccessException, InvocationTargetException, InstantiationException {
cx = Context.enter();
cx.setOptimizationLevel(9);
cx.setLanguageVersion(Context.VERSION_ES6);

scope = cx.initStandardObjects();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public static class MathState {
@Setup(Level.Trial)
public void setup() throws IOException {
cx = Context.enter();
cx.setOptimizationLevel(9);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = cx.initStandardObjects();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static class FieldTestState {
@SuppressWarnings("unused")
public void create() throws IOException {
cx = Context.enter();
cx.setOptimizationLevel(9);
cx.setLanguageVersion(Context.VERSION_ES6);

scope = new Global(cx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public static class PropertyState {
@Setup(Level.Trial)
public void setup() throws IOException {
cx = Context.enter();
cx.setOptimizationLevel(9);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = cx.initStandardObjects();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ abstract static class AbstractState {
public void setUp() {
cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_ES6);
cx.setOptimizationLevel(9);
scope = cx.initStandardObjects();

try (FileReader rdr = new FileReader(fileName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void evaluateSource(Context cx, Scriptable scope, String fileName) {
void initialize() {
cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_ES6);
cx.setOptimizationLevel(9);
scope = cx.initStandardObjects();
evaluateSource(cx, scope, "testsrc/benchmarks/framework.js");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Bug482203Test {
@Test
public void jsApi() throws Exception {
try (Context cx = Context.enter()) {
cx.setOptimizationLevel(-1);
cx.setInterpretedMode(true);
InputStreamReader in =
new InputStreamReader(Bug482203Test.class.getResourceAsStream("Bug482203.js"));
Script script = cx.compileReader(in, "", 1, null);
Expand All @@ -42,7 +42,7 @@ public void jsApi() throws Exception {
@Test
public void javaApi() throws Exception {
try (Context cx = Context.enter()) {
cx.setOptimizationLevel(-1);
cx.setInterpretedMode(true);
InputStreamReader in =
new InputStreamReader(Bug482203Test.class.getResourceAsStream("Bug482203.js"));
Script script = cx.compileReader(in, "", 1, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Bug685403Test {
@Before
public void setUp() {
cx = Context.enter();
cx.setOptimizationLevel(-1);
cx.setInterpretedMode(true);
scope = cx.initStandardObjects();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ public class Bug708801Test {

private static final ContextFactory factory =
new ContextFactory() {
static final int COMPILER_MODE = 9;

@Override
protected Context makeContext() {
Context cx = super.makeContext();
cx.setLanguageVersion(Context.VERSION_1_8);
cx.setOptimizationLevel(COMPILER_MODE);
return cx;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class Bug782363Test {
public void setUp() {
cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_1_8);
cx.setOptimizationLevel(9);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String doCatchWrappedException(final ClassShutter shutter) throws Excepti

return factory.call(
context -> {
context.setOptimizationLevel(-1);
context.setInterpretedMode(true);
if (shutter != null) {
context.setClassShutter(shutter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void largeMethod() {
_cx -> {
Script script =
_cx.compileString(scriptSource.toString(), "test-source", 1, null);
if (_cx.getOptimizationLevel() > -1) {
if (!_cx.isInterpretedMode()) {
Assert.assertTrue(
script.getClass().getName(),
script.getClass()
Expand Down Expand Up @@ -119,7 +119,7 @@ public void largeVarList() {
_cx -> {
Script script =
_cx.compileString(scriptSource.toString(), "test-source", 1, null);
if (_cx.getOptimizationLevel() > -1) {
if (!_cx.isInterpretedMode()) {
Assert.assertTrue(
script.getClass().getName(),
script.getClass()
Expand Down Expand Up @@ -188,7 +188,7 @@ public void largeLocalVarList() {
_cx -> {
Script script =
_cx.compileString(scriptSource.toString(), "test-source", 1, null);
if (_cx.getOptimizationLevel() > -1) {
if (!_cx.isInterpretedMode()) {
Assert.assertTrue(
script.getClass().getName(),
script.getClass()
Expand Down Expand Up @@ -259,7 +259,7 @@ public void tooManyMethods() {
_cx -> {
Script script =
_cx.compileString(scriptSource.toString(), "test-source", 1, null);
if (_cx.getOptimizationLevel() > -1) {
if (!_cx.isInterpretedMode()) {
Assert.assertTrue(
script.getClass().getName(),
script.getClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String h() {
public void setUp() {
try (Context cx = Context.enter()) {
globalScope = cx.initStandardObjects();
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
globalScope.put("myObject", globalScope, Context.javaToJS(new MyClass(), globalScope));
}
}
Expand All @@ -80,7 +80,7 @@ public void setUp() {
public void scriptWithContinuations() {
try (Context cx = Context.enter()) {
try {
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
Script script = cx.compileString("myObject.f(3) + 1;", "test source", 1, null);
cx.executeScriptWithContinuations(script, globalScope);
fail("Should throw ContinuationPending");
Expand All @@ -99,7 +99,7 @@ public void scriptWithContinuations() {
public void scriptWithMultipleContinuations() {
try (Context cx = Context.enter()) {
try {
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
Script script =
cx.compileString(
"myObject.f(3) + myObject.g(3) + 2;", "test source", 1, null);
Expand Down Expand Up @@ -129,7 +129,7 @@ public void scriptWithMultipleContinuations() {
public void scriptWithNestedContinuations() {
try (Context cx = Context.enter()) {
try {
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
Script script =
cx.compileString(
"myObject.g( myObject.f(1) ) + 2;", "test source", 1, null);
Expand Down Expand Up @@ -159,7 +159,7 @@ public void scriptWithNestedContinuations() {
public void functionWithContinuations() {
try (Context cx = Context.enter()) {
try {
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
cx.evaluateString(
globalScope,
"function f(a) { return myObject.f(a); }",
Expand Down Expand Up @@ -189,7 +189,7 @@ public void functionWithContinuations() {
@Test
public void errorOnEvalCall() {
try (Context cx = Context.enter()) {
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
Script script = cx.compileString("eval('myObject.f(3);');", "test source", 1, null);
cx.executeScriptWithContinuations(script, globalScope);
fail("Should throw IllegalStateException");
Expand All @@ -204,7 +204,7 @@ public void errorOnEvalCall() {
public void serializationWithContinuations() throws IOException, ClassNotFoundException {
try (Context cx = Context.enter()) {
try {
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
cx.evaluateString(
globalScope,
"function f(a) { var k = myObject.f(a); var t = []; return k; }",
Expand Down Expand Up @@ -255,13 +255,13 @@ public void continuationsPrototypesAndSerialization()

try (Context cx = Context.enter()) {
globalScope = cx.initStandardObjects();
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
globalScope.put(
"myObject", globalScope, Context.javaToJS(new MyClass(), globalScope));
}

try (Context cx = Context.enter()) {
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
cx.evaluateString(
globalScope,
"function f(a) { Number.prototype.blargh = function() {return 'foo';}; var k = myObject.f(a); var t = []; return new Number(8).blargh(); }",
Expand Down Expand Up @@ -315,12 +315,12 @@ public void continuationsInlineFunctionsSerialization()

try (Context cx = Context.enter()) {
globalScope = cx.initStandardObjects();
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode
globalScope.put("myObject", globalScope, Context.javaToJS(new MyClass(), globalScope));
}

try (Context cx = Context.enter()) {
cx.setOptimizationLevel(-1); // must use interpreter mode
cx.setInterpretedMode(true); // must use interpreter mode

try {
cx.evaluateString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ protected boolean hasFeature(Context cx, int featureIndex) {
protected Context makeContext() {
Context cx = super.makeContext();
cx.setLanguageVersion(Context.VERSION_ES6);
cx.setOptimizationLevel(0);
return cx;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ public class ErrorPropertiesTest {
static final String LS = System.getProperty("line.separator");

private void testScriptStackTrace(final String script, final String expectedStackTrace) {
testScriptStackTrace(script, expectedStackTrace, -1);
testScriptStackTrace(script, expectedStackTrace, 0);
testScriptStackTrace(script, expectedStackTrace, 1);
testScriptStackTrace(script, expectedStackTrace, false);
testScriptStackTrace(script, expectedStackTrace, true);
}

private void testScriptStackTrace(
final String script, final String expectedStackTrace, final int optimizationLevel) {
final String script, final String expectedStackTrace, final boolean interpreted) {
try {
Utils.executeScript(script, optimizationLevel);
Utils.executeScript(script, interpreted);
} catch (final RhinoException e) {
Assert.assertEquals(expectedStackTrace, e.getScriptStackTrace());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void setUp() {
cx.setLanguageVersion(Context.VERSION_1_8);
// errors are reported in the parsing stage,
// optimization level doesn't matter
cx.setOptimizationLevel(-1);
cx.setInterpretedMode(true);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void equivalentValuesUndefined() throws Exception {
"test",
1,
null);
assertEquals("" + cx.getOptimizationLevel(), "true true", result);
assertEquals("" + cx.isInterpretedMode(), "true true", result);

return null;
});
Expand All @@ -56,7 +56,7 @@ public void equivalentValuesNull() throws Exception {
"test",
1,
null);
assertEquals("" + cx.getOptimizationLevel(), "true true", result);
assertEquals("" + cx.isInterpretedMode(), "true true", result);

return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public class ToNumberConversionsTest {
public static Collection<Object[]> data() {
List<Object[]> cases = new ArrayList<>();

for (int optLevel : Utils.DEFAULT_OPT_LEVELS) {
for (boolean interpreted : new boolean[] {false, true}) {
for (Object[] test : TESTS) {
cases.add(new Object[] {test[0], test[1], optLevel});
cases.add(new Object[] {test[0], test[1], interpreted});
}
}

Expand All @@ -107,7 +107,7 @@ public static Collection<Object[]> data() {
public String source;

@Parameterized.Parameter(2)
public int optLevel;
public boolean interpreted;

@SuppressWarnings("ConstantConditions")
private boolean execute(Context cx, Scriptable scope, String script) {
Expand All @@ -120,7 +120,7 @@ private boolean execute(Context cx, Scriptable scope, String script) {
@Before
public void setup() {
cx = Context.enter();
cx.setOptimizationLevel(optLevel);
cx.setInterpretedMode(interpreted);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = cx.initSafeStandardObjects();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public class ToNumberLegacyConversionsTest {
public static Collection<Object[]> data() {
List<Object[]> cases = new ArrayList<>();

for (int optLevel : OPT_LEVELS) {
for (boolean interpreted : new boolean[] {false, true}) {
for (Object[] test : TESTS) {
cases.add(new Object[] {test[0], test[1], optLevel});
cases.add(new Object[] {test[0], test[1], interpreted});
}
}

Expand All @@ -113,7 +113,7 @@ public static Collection<Object[]> data() {
public String source;

@Parameterized.Parameter(2)
public int optLevel;
public boolean interpreted;

@SuppressWarnings("ConstantConditions")
private boolean execute(Context cx, Scriptable scope, String script) {
Expand All @@ -126,7 +126,7 @@ private boolean execute(Context cx, Scriptable scope, String script) {
@Before
public void setup() {
cx = Context.enter();
cx.setOptimizationLevel(optLevel);
cx.setInterpretedMode(interpreted);
cx.setLanguageVersion(Context.VERSION_1_8);
scope = cx.initSafeStandardObjects();
}
Expand Down
Loading

0 comments on commit a8190a7

Please sign in to comment.