Skip to content

Commit

Permalink
improved api
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jan 7, 2025
1 parent 025a102 commit cafff8f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions testutils/src/main/java/org/mozilla/javascript/tests/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,19 @@ public static <T extends Exception> 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;
}

Expand Down

0 comments on commit cafff8f

Please sign in to comment.