From ff2a3931f4740a1c82ebae01d29d2c6a5b8a0632 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sun, 23 Jul 2023 11:39:33 -0700 Subject: [PATCH] Revert "Remap default class names" This reverts commit b4e444bd6fe49e5f7f5e2bf2317e035ee1f624ec. It's not really possible to also apply this to the result of Class.toString(), so lets just get rid of it. --- .../java/org/mozilla/javascript/Context.java | 2 +- .../javascript/JavaObjectMappingProvider.java | 9 +-------- .../org/mozilla/javascript/NativeJavaObject.java | 16 +--------------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/mozilla/javascript/Context.java b/src/main/java/org/mozilla/javascript/Context.java index 2d1d378a..0a285025 100644 --- a/src/main/java/org/mozilla/javascript/Context.java +++ b/src/main/java/org/mozilla/javascript/Context.java @@ -2677,7 +2677,7 @@ public void setJavaObjectMappingProvider(JavaObjectMappingProvider provider) { private Object propertyListeners; private Map threadLocalMap; private ClassLoader applicationClassLoader; - private JavaObjectMappingProvider javaObjectMappingProvider = JavaObjectMappingProvider.DEFAULT; + private JavaObjectMappingProvider javaObjectMappingProvider = JavaObjectMappingProvider.EMPTY; /** * This is the list of names of objects forcing the creation of diff --git a/src/main/java/org/mozilla/javascript/JavaObjectMappingProvider.java b/src/main/java/org/mozilla/javascript/JavaObjectMappingProvider.java index edcd17b7..6f948d23 100644 --- a/src/main/java/org/mozilla/javascript/JavaObjectMappingProvider.java +++ b/src/main/java/org/mozilla/javascript/JavaObjectMappingProvider.java @@ -7,20 +7,13 @@ import java.util.Map; public interface JavaObjectMappingProvider { - JavaObjectMappingProvider DEFAULT = new Default(); - - String remapClass(Class clazz); + JavaObjectMappingProvider EMPTY = new Default(); void findExtraMethods(Class clazz, Map map, boolean includeProtected, boolean includePrivate); void findExtraFields(Class clazz, List list, boolean includeProtected, boolean includePrivate); class Default implements JavaObjectMappingProvider { - @Override - public String remapClass(Class clazz) { - return null; - } - @Override public void findExtraMethods(Class clazz, Map map, boolean includeProtected, boolean includePrivate) { } diff --git a/src/main/java/org/mozilla/javascript/NativeJavaObject.java b/src/main/java/org/mozilla/javascript/NativeJavaObject.java index 8b6a796b..92c8f1d1 100644 --- a/src/main/java/org/mozilla/javascript/NativeJavaObject.java +++ b/src/main/java/org/mozilla/javascript/NativeJavaObject.java @@ -15,7 +15,6 @@ import java.lang.reflect.Method; import java.util.Date; import java.util.Map; -import java.util.Objects; /** * This class reflects non-Array Java objects into the JavaScript environment. It @@ -233,20 +232,7 @@ public Object getDefaultValue(Class hint) { } } if (hint == null || hint == ScriptRuntime.StringClass) { - String string = javaObject.toString(); - - // If the object doesn't have an overridden toString() method, try to replace - // its class name with a possibly-remapped version. Guard this with a sanity - // string check - if (string.length() >= 9 && string.charAt(string.length() - 9) == '@') { - Class cls = javaObject.getClass(); - String remapped = Context.getCurrentContext().getJavaObjectMappingProvider().remapClass(cls); - if (remapped != null) { - string = string.replace(cls.getName(), remapped); - } - } - - value = string; + value = javaObject.toString(); } else { String converterName; if (hint == ScriptRuntime.BooleanClass) {