From 461f26d4287d7ba2be17f0b4876be83718c85d28 Mon Sep 17 00:00:00 2001 From: ZZZank <3410764033@qq.com> Date: Mon, 17 Jun 2024 11:18:38 +0800 Subject: [PATCH] custom property for a Context --- .../main/java/dev/latvian/mods/rhino/Context.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/src/main/java/dev/latvian/mods/rhino/Context.java b/common/src/main/java/dev/latvian/mods/rhino/Context.java index d908f9ff..7c6d26be 100644 --- a/common/src/main/java/dev/latvian/mods/rhino/Context.java +++ b/common/src/main/java/dev/latvian/mods/rhino/Context.java @@ -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; @@ -276,6 +277,7 @@ public class Context { private ClassLoader applicationClassLoader; @Setter private Remapper remapper; + private final Map customProperties; /** * Creates a new context. Provided as a preferred super constructor for @@ -295,6 +297,7 @@ protected Context(ContextFactory factory) { maximumInterpreterStackDepth = Integer.MAX_VALUE; optimizationLevel = RhinoProperties.INSTANCE.optimizationLevel; remapper = null; + customProperties = new HashMap<>(); } /** @@ -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. */