X-Git-Url: http://git.megacz.com/?p=org.ibex.js.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSReflection.java;fp=src%2Forg%2Fibex%2Fjs%2FJSReflection.java;h=d9c241f628161c1701f3fa9f411e2c7d5e63858d;hp=2f163e7f2d1a7e42f63a32f80ecd5ee5d6fa3ada;hb=1da9851e5aa0c1aa6063847a4a7f3f874266af3a;hpb=95c5a8f2287c2869f100995b7e2bcf749bb097c8 diff --git a/src/org/ibex/js/JSReflection.java b/src/org/ibex/js/JSReflection.java index 2f163e7..d9c241f 100644 --- a/src/org/ibex/js/JSReflection.java +++ b/src/org/ibex/js/JSReflection.java @@ -16,10 +16,56 @@ public class JSReflection extends JS.Immutable { if (o instanceof Boolean) return JSU.B(((Boolean)o).booleanValue()); if (o instanceof Number) return JSU.N((Number)o); if (o instanceof JS) return (JS)o; - if (o instanceof Object[]) { - throw new JSExn("Reflection onto Object[] not supported yet"); + if (o instanceof Object[]) throw new JSExn("Reflection onto Object[] not supported yet"); + return new Wrapper(o); + } + + public static class Wrapper extends JS.Immutable { + private final Object o; + public Wrapper(Object o) { this.o = o; } + public Object unwrap() { return o; } + public Enumeration keys() throws JSExn { throw new JSExn("JSReflection.keys() not supported yet"); } + public JS get(JS key) throws JSExn { + String k = JSU.toString(key); + Class c = o.getClass(); + while(c != null) { + try { + Field f = c.getField(k); + if (f != null) return wrap(f.get(o)); + } catch (NoSuchFieldException nfe) { + } catch (IllegalAccessException nfe) { + } catch (SecurityException nfe) { } + c = c.getSuperclass(); + } + + try { + java.lang.reflect.Method[] methods = o.getClass().getMethods(); + for(int i=0; i