Skip to content

Commit

Permalink
Revert "Remap default class names"
Browse files Browse the repository at this point in the history
This reverts commit b4e444b. It's not
really possible to also apply this to the result of Class.toString(), so
lets just get rid of it.
  • Loading branch information
mattco98 committed Jul 23, 2023
1 parent 84d71da commit ff2a393
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/mozilla/javascript/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ public void setJavaObjectMappingProvider(JavaObjectMappingProvider provider) {
private Object propertyListeners;
private Map<Object, Object> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MethodSignature, RenameableMethod> map, boolean includeProtected, boolean includePrivate);

void findExtraFields(Class<?> clazz, List<RenameableField> list, boolean includeProtected, boolean includePrivate);

class Default implements JavaObjectMappingProvider {
@Override
public String remapClass(Class<?> clazz) {
return null;
}

@Override
public void findExtraMethods(Class<?> clazz, Map<MethodSignature, RenameableMethod> map, boolean includeProtected, boolean includePrivate) {
}
Expand Down
16 changes: 1 addition & 15 deletions src/main/java/org/mozilla/javascript/NativeJavaObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ff2a393

Please sign in to comment.