From a8190a7325e1d6fa5cb6d855deea10edae770a0f Mon Sep 17 00:00:00 2001 From: Greg Brail Date: Tue, 10 Dec 2024 16:57:45 -0800 Subject: [PATCH] Remove deprecated functions from rhino module --- .../benchmarks/BuiltinBenchmark.java | 1 - .../javascript/benchmarks/MathBenchmark.java | 1 - .../benchmarks/ObjectBenchmark.java | 1 - .../benchmarks/PropertyBenchmark.java | 1 - .../benchmarks/SunSpiderBenchmark.java | 1 - .../javascript/benchmarks/V8Benchmark.java | 1 - .../javascript/tests/Bug482203Test.java | 4 +- .../javascript/tests/Bug685403Test.java | 2 +- .../javascript/tests/Bug708801Test.java | 3 - .../javascript/tests/Bug782363Test.java | 1 - .../mozilla/javascript/tests/CatchTest.java | 2 +- .../mozilla/javascript/tests/CodegenTest.java | 8 +-- .../tests/ContinuationsApiTest.java | 22 +++---- .../javascript/tests/DynamicScopeTest.java | 1 - .../javascript/tests/ErrorPropertiesTest.java | 9 ++- .../javascript/tests/Issue385Test.java | 2 +- .../ScriptRuntimeEquivalentValuesTest.java | 4 +- .../tests/ToNumberConversionsTest.java | 8 +-- .../tests/ToNumberLegacyConversionsTest.java | 8 +-- .../org/mozilla/javascript/tests/Utils.java | 59 +------------------ 20 files changed, 37 insertions(+), 102 deletions(-) diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/BuiltinBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/BuiltinBenchmark.java index 2e943bb443..9071d4f7bb 100644 --- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/BuiltinBenchmark.java +++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/BuiltinBenchmark.java @@ -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(); diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/MathBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/MathBenchmark.java index 427e5a9897..e298919eff 100644 --- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/MathBenchmark.java +++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/MathBenchmark.java @@ -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(); diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/ObjectBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/ObjectBenchmark.java index 53ed05195d..269469a2f1 100644 --- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/ObjectBenchmark.java +++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/ObjectBenchmark.java @@ -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); diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/PropertyBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/PropertyBenchmark.java index 329e39a15d..402f003934 100644 --- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/PropertyBenchmark.java +++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/PropertyBenchmark.java @@ -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(); diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java index 55a181b75f..12555f6c0a 100644 --- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java +++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/SunSpiderBenchmark.java @@ -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)) { diff --git a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/V8Benchmark.java b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/V8Benchmark.java index 5b7f92a483..9c38ffe717 100644 --- a/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/V8Benchmark.java +++ b/benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/V8Benchmark.java @@ -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"); } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug482203Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug482203Test.java index 658c09bcad..26de80223a 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug482203Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug482203Test.java @@ -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); @@ -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); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug685403Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug685403Test.java index 1624eb201c..9c9f49748a 100755 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug685403Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug685403Test.java @@ -28,7 +28,7 @@ public class Bug685403Test { @Before public void setUp() { cx = Context.enter(); - cx.setOptimizationLevel(-1); + cx.setInterpretedMode(true); scope = cx.initStandardObjects(); } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug708801Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug708801Test.java index a8e884c373..3022e49fa9 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug708801Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug708801Test.java @@ -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; } }; diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug782363Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug782363Test.java index 92c72c8992..16ff9a19e9 100755 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug782363Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug782363Test.java @@ -41,7 +41,6 @@ public class Bug782363Test { public void setUp() { cx = Context.enter(); cx.setLanguageVersion(Context.VERSION_1_8); - cx.setOptimizationLevel(9); } @After diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/CatchTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/CatchTest.java index ee086f6298..50df20797a 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/CatchTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/CatchTest.java @@ -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); } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java index 2f72ee02dc..ac8f64d057 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/CodegenTest.java @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ContinuationsApiTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ContinuationsApiTest.java index 1ae2e5607a..0e0d0d60fb 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ContinuationsApiTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ContinuationsApiTest.java @@ -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)); } } @@ -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"); @@ -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); @@ -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); @@ -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); }", @@ -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"); @@ -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; }", @@ -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(); }", @@ -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( diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/DynamicScopeTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/DynamicScopeTest.java index f35d7d11be..8cdbc2e788 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/DynamicScopeTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/DynamicScopeTest.java @@ -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; } } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java index 636655becb..e6add2db78 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ErrorPropertiesTest.java @@ -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()); } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Issue385Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Issue385Test.java index 802be5e4aa..9e1746796b 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Issue385Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Issue385Test.java @@ -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 diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java index 7dedbf2dad..7638cc24bd 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ScriptRuntimeEquivalentValuesTest.java @@ -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; }); @@ -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; }); diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java index 9991962d94..1886412f36 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberConversionsTest.java @@ -91,9 +91,9 @@ public class ToNumberConversionsTest { public static Collection data() { List 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}); } } @@ -107,7 +107,7 @@ public static Collection data() { public String source; @Parameterized.Parameter(2) - public int optLevel; + public boolean interpreted; @SuppressWarnings("ConstantConditions") private boolean execute(Context cx, Scriptable scope, String script) { @@ -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(); } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberLegacyConversionsTest.java b/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberLegacyConversionsTest.java index 427c2192da..1093b1d6bc 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberLegacyConversionsTest.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/ToNumberLegacyConversionsTest.java @@ -97,9 +97,9 @@ public class ToNumberLegacyConversionsTest { public static Collection data() { List 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}); } } @@ -113,7 +113,7 @@ public static Collection data() { public String source; @Parameterized.Parameter(2) - public int optLevel; + public boolean interpreted; @SuppressWarnings("ConstantConditions") private boolean execute(Context cx, Scriptable scope, String script) { @@ -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(); } diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Utils.java b/rhino/src/test/java/org/mozilla/javascript/tests/Utils.java index 036aaab774..87f131441b 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Utils.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Utils.java @@ -5,14 +5,11 @@ package org.mozilla.javascript.tests; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import org.mozilla.javascript.Context; import org.mozilla.javascript.ContextAction; import org.mozilla.javascript.ContextFactory; -import org.mozilla.javascript.EvaluatorException; import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; /** * Misc utilities to make test code easier. @@ -21,9 +18,6 @@ * @author Ronald Brill */ public class Utils { - /** The default set of levels to run tests at. */ - public static final int[] DEFAULT_OPT_LEVELS = new int[] {-1, 9}; - /** Runs the action successively with all available optimization levels */ public static void runWithAllOptimizationLevels(final ContextAction action) { runWithMode(action, false); @@ -37,29 +31,11 @@ public static void runWithAllOptimizationLevels( runWithMode(contextFactory, action, true); } - /** Runs the provided action at the given optimization level */ - public static void runWithOptimizationLevel( - final ContextAction action, final int optimizationLevel) { - runWithOptimizationLevel(new ContextFactory(), action, optimizationLevel); - } - /** Runs the provided action at the given interpretation mode */ public static void runWithMode(final ContextAction action, final boolean interpretedMode) { runWithMode(new ContextFactory(), action, interpretedMode); } - /** Runs the provided action at the given optimization level */ - public static void runWithOptimizationLevel( - final ContextFactory contextFactory, - final ContextAction action, - final int optimizationLevel) { - - try (final Context cx = contextFactory.enterContext()) { - cx.setOptimizationLevel(optimizationLevel); - action.run(cx); - } - } - /** Runs the provided action at the given optimization level */ public static void runWithMode( final ContextFactory contextFactory, @@ -76,25 +52,13 @@ public static void runWithMode( * * @param script the script code */ - static void executeScript(final String script, final int optimizationLevel) { - Utils.runWithOptimizationLevel( + static void executeScript(String script, boolean interpreted) { + Utils.runWithMode( cx -> { final Scriptable scope = cx.initStandardObjects(); return cx.evaluateString(scope, script, "myScript.js", 1, null); }, - optimizationLevel); - } - - /** - * If the TEST_OPTLEVEL system property is set, then return an array containing only that one - * integer. Otherwise, return an array of the typical opt levels that we expect for testing. - */ - public static int[] getTestOptLevels() { - String overriddenLevel = System.getProperty("TEST_OPTLEVEL"); - if (overriddenLevel != null && !overriddenLevel.isEmpty()) { - return new int[] {Integer.parseInt(overriddenLevel)}; - } - return DEFAULT_OPT_LEVELS; + interpreted); } public static void assertWithAllOptimizationLevels(final Object expected, final String script) { @@ -120,21 +84,4 @@ public static void assertWithAllOptimizationLevelsES6( return null; }); } - - public static void assertEvaluatorExceptionES6(String expectedMessage, String js) { - Utils.runWithAllOptimizationLevels( - cx -> { - cx.setLanguageVersion(Context.VERSION_ES6); - ScriptableObject scope = cx.initStandardObjects(); - - try { - cx.evaluateString(scope, js, "test", 1, null); - fail("EvaluatorException expected"); - } catch (EvaluatorException e) { - assertEquals(expectedMessage, e.getMessage()); - } - - return null; - }); - } }