зеркало из https://github.com/mozilla/pjs.git
Removal of overridden equals that simply calls super.equals since JavaAdapter does not need to define the method for ScriptableObject.defineClass to work and layout cosmetics.
This commit is contained in:
Родитель
260660f381
Коммит
6e8c35eed6
|
@ -46,16 +46,15 @@ import java.lang.reflect.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class JavaAdapter extends ScriptableObject {
|
public class JavaAdapter extends ScriptableObject
|
||||||
public boolean equals(Object obj) {
|
{
|
||||||
return super.equals(obj);
|
public String getClassName()
|
||||||
}
|
{
|
||||||
|
|
||||||
public String getClassName() {
|
|
||||||
return "JavaAdapter";
|
return "JavaAdapter";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object convertResult(Object result, Class c) {
|
public static Object convertResult(Object result, Class c)
|
||||||
|
{
|
||||||
if (result == Undefined.instance &&
|
if (result == Undefined.instance &&
|
||||||
(c != ScriptRuntime.ObjectClass &&
|
(c != ScriptRuntime.ObjectClass &&
|
||||||
c != ScriptRuntime.StringClass))
|
c != ScriptRuntime.StringClass))
|
||||||
|
@ -66,7 +65,8 @@ public class JavaAdapter extends ScriptableObject {
|
||||||
return NativeJavaObject.coerceType(c, result, true);
|
return NativeJavaObject.coerceType(c, result, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Scriptable setAdapterProto(Scriptable obj, Object adapter) {
|
public static Scriptable setAdapterProto(Scriptable obj, Object adapter)
|
||||||
|
{
|
||||||
// We could be called from a thread not associated with a Context
|
// We could be called from a thread not associated with a Context
|
||||||
Context cx = Context.enter();
|
Context cx = Context.enter();
|
||||||
try {
|
try {
|
||||||
|
@ -183,10 +183,11 @@ public class JavaAdapter extends ScriptableObject {
|
||||||
throw new ClassNotFoundException("adapter");
|
throw new ClassNotFoundException("adapter");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[]
|
public static byte[] createAdapterCode(Context cx, Scriptable jsObj,
|
||||||
createAdapterCode(Context cx, Scriptable jsObj, String adapterName,
|
String adapterName,
|
||||||
Class superClass, Class[] interfaces,
|
Class superClass,
|
||||||
String scriptClassName)
|
Class[] interfaces,
|
||||||
|
String scriptClassName)
|
||||||
{
|
{
|
||||||
ClassFileWriter cfw = new ClassFileWriter(adapterName,
|
ClassFileWriter cfw = new ClassFileWriter(adapterName,
|
||||||
superClass.getName(),
|
superClass.getName(),
|
||||||
|
@ -439,8 +440,10 @@ public class JavaAdapter extends ScriptableObject {
|
||||||
cfw.stopMethod((short)20, null); // TODO: magic number "20"
|
cfw.stopMethod((short)20, null); // TODO: magic number "20"
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generateEmptyCtor(ClassFileWriter cfw, String adapterName,
|
private static void generateEmptyCtor(ClassFileWriter cfw,
|
||||||
String superName, String scriptClassName)
|
String adapterName,
|
||||||
|
String superName,
|
||||||
|
String scriptClassName)
|
||||||
{
|
{
|
||||||
cfw.startMethod("<init>", "()V", ClassFileWriter.ACC_PUBLIC);
|
cfw.startMethod("<init>", "()V", ClassFileWriter.ACC_PUBLIC);
|
||||||
|
|
||||||
|
@ -827,7 +830,8 @@ public class JavaAdapter extends ScriptableObject {
|
||||||
/**
|
/**
|
||||||
* Returns a fully qualified method name concatenated with its signature.
|
* Returns a fully qualified method name concatenated with its signature.
|
||||||
*/
|
*/
|
||||||
private static String getMethodSignature(Method method) {
|
private static String getMethodSignature(Method method)
|
||||||
|
{
|
||||||
Class[] parms = method.getParameterTypes();
|
Class[] parms = method.getParameterTypes();
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append('(');
|
sb.append('(');
|
||||||
|
@ -868,18 +872,21 @@ public class JavaAdapter extends ScriptableObject {
|
||||||
* Provides a key with which to distinguish previously generated
|
* Provides a key with which to distinguish previously generated
|
||||||
* adapter classes stored in a hash table.
|
* adapter classes stored in a hash table.
|
||||||
*/
|
*/
|
||||||
static class ClassSignature {
|
static class ClassSignature
|
||||||
|
{
|
||||||
Class mSuperClass;
|
Class mSuperClass;
|
||||||
Class[] mInterfaces;
|
Class[] mInterfaces;
|
||||||
Object[] mProperties; // JDK1.2: Use HashSet
|
Object[] mProperties; // JDK1.2: Use HashSet
|
||||||
|
|
||||||
ClassSignature(Class superClass, Class[] interfaces, Scriptable jsObj) {
|
ClassSignature(Class superClass, Class[] interfaces, Scriptable jsObj)
|
||||||
|
{
|
||||||
mSuperClass = superClass;
|
mSuperClass = superClass;
|
||||||
mInterfaces = interfaces;
|
mInterfaces = interfaces;
|
||||||
mProperties = ScriptableObject.getPropertyIds(jsObj);
|
mProperties = ScriptableObject.getPropertyIds(jsObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
if (obj instanceof ClassSignature) {
|
if (obj instanceof ClassSignature) {
|
||||||
ClassSignature sig = (ClassSignature) obj;
|
ClassSignature sig = (ClassSignature) obj;
|
||||||
if (mSuperClass == sig.mSuperClass) {
|
if (mSuperClass == sig.mSuperClass) {
|
||||||
|
@ -905,7 +912,8 @@ public class JavaAdapter extends ScriptableObject {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode()
|
||||||
|
{
|
||||||
return mSuperClass.hashCode();
|
return mSuperClass.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче