From cafff8f58dde4311296622b41883f7ef90992e71 Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Tue, 7 Jan 2025 13:01:36 +0100 Subject: [PATCH] improved api --- .../org/mozilla/javascript/tests/Bug421071Test.java | 2 +- .../org/mozilla/javascript/tests/Bug637811Test.java | 3 +-- .../java/org/mozilla/javascript/tests/Utils.java | 13 +++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug421071Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug421071Test.java index 431b016255..6db9cdf28e 100644 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug421071Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug421071Test.java @@ -64,7 +64,7 @@ private void runTestScript() throws InterruptedException { } private TopLevelScope createGlobalScope() { - factory = new Utils.FeatureContextFactory(Context.FEATURE_DYNAMIC_SCOPE); + factory = Utils.contextFactoryWithFeatures(Context.FEATURE_DYNAMIC_SCOPE); try (Context context = factory.enterContext()) { // noinspection deprecation diff --git a/rhino/src/test/java/org/mozilla/javascript/tests/Bug637811Test.java b/rhino/src/test/java/org/mozilla/javascript/tests/Bug637811Test.java index 35ecaece13..63c5311f15 100755 --- a/rhino/src/test/java/org/mozilla/javascript/tests/Bug637811Test.java +++ b/rhino/src/test/java/org/mozilla/javascript/tests/Bug637811Test.java @@ -16,8 +16,7 @@ public class Bug637811Test { @Test public void test() { Utils.assertWithAllModes( - new Utils.FeatureContextFactory( - Context.FEATURE_STRICT_MODE, Context.FEATURE_WARNING_AS_ERROR), + Utils.contextFactoryWithFeatures(Context.FEATURE_STRICT_MODE, Context.FEATURE_WARNING_AS_ERROR), Context.VERSION_ES6, null, Undefined.instance, diff --git a/testutils/src/main/java/org/mozilla/javascript/tests/Utils.java b/testutils/src/main/java/org/mozilla/javascript/tests/Utils.java index 5ab9d07dac..dd13c00c5c 100644 --- a/testutils/src/main/java/org/mozilla/javascript/tests/Utils.java +++ b/testutils/src/main/java/org/mozilla/javascript/tests/Utils.java @@ -335,10 +335,19 @@ public static void assertException( }); } - public static class FeatureContextFactory extends ContextFactory { + /** + * @param features the features to enable in addition to the already enabled + * featured from the {@link ContextFactory} + * @return a new {@link ContextFactory} with all provided features enabled + */ + public static ContextFactory contextFactoryWithFeatures(int... features) { + return new ContextFactoryWithFeatures(features); + } + + private static class ContextFactoryWithFeatures extends ContextFactory { private final int[] features; - public FeatureContextFactory(int... features) { + private ContextFactoryWithFeatures(int... features) { this.features = features; }