Skip to content

Commit

Permalink
custom property for a Context
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZZank committed Jun 17, 2024
1 parent 8949119 commit 461f26d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions common/src/main/java/dev/latvian/mods/rhino/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import dev.latvian.mods.rhino.util.remapper.Remapper;
import dev.latvian.mods.rhino.util.wrap.TypeWrappers;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
Expand Down Expand Up @@ -276,6 +277,7 @@ public class Context {
private ClassLoader applicationClassLoader;
@Setter
private Remapper remapper;
private final Map<String, Object> customProperties;

/**
* Creates a new context. Provided as a preferred super constructor for
Expand All @@ -295,6 +297,7 @@ protected Context(ContextFactory factory) {
maximumInterpreterStackDepth = Integer.MAX_VALUE;
optimizationLevel = RhinoProperties.INSTANCE.optimizationLevel;
remapper = null;
customProperties = new HashMap<>();
}

/**
Expand Down Expand Up @@ -790,6 +793,18 @@ public Remapper getRemapper() {
return remapper == null ? factory.remapper : remapper;
}

public Object getCustomProperty(String name) {
return customProperties.get(name);
}

public Object getCustomProperty(String name, Object orDefault) {
return customProperties.getOrDefault(name, orDefault);
}

public void setCustomProperty(String name, @Nullable Object value) {
customProperties.put(name, value);
}

/**
* Return {@link ContextFactory} instance used to create this Context.
*/
Expand Down

0 comments on commit 461f26d

Please sign in to comment.