X-Git-Url: http://git.megacz.com/?p=org.ibex.js.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSReflection.java;h=d6ecd759717efb5370d281fc96d2c3c6f0200966;hp=4d6ec04db9f54182f2650c54c798ccd8f4269d1f;hb=5a5f5ef235158d513c1f2879dc916b115a4fa9d0;hpb=e50fec35a2318586e3bb13f3a54a8a3532afee14 diff --git a/src/org/ibex/js/JSReflection.java b/src/org/ibex/js/JSReflection.java index 4d6ec04..d6ecd75 100644 --- a/src/org/ibex/js/JSReflection.java +++ b/src/org/ibex/js/JSReflection.java @@ -4,13 +4,11 @@ package org.ibex.js; -import org.ibex.util.*; -import java.io.*; -import java.util.*; import java.lang.reflect.*; /** Automatic JS-ification via Reflection (not for use in the core) */ -public class JSReflection extends JS { +public class JSReflection extends JS.Immutable { + private static final JS.Method METHOD = new JS.Method(); public static JS wrap(Object o) throws JSExn { if (o == null) return null; @@ -24,28 +22,25 @@ public class JSReflection extends JS { throw new JSExn("Reflection object tried to return a " + o.getClass().getName()); } - public static class Array extends JS { + public static class Array extends JS.Immutable { final Object[] arr; public Array(Object[] arr) { this.arr = arr; } // FEATURE: Add a JSCounterEnumeration public Enumeration keys() throws JSExn { return new Enumeration(null) { private int n = 0; - public boolean _hasMoreElements() { return n < arr.length; } - public JS _nextElement() { - return n >= arr.length ? null : Script.N(n++); - } + public boolean _hasNext() { return n < arr.length; } + public JS _next() { return Script.N(n++); } }; } - public JS get(JS key) throws JSExn { return wrap(arr[toInt(key)]); } - public void put(JS key, JS val) throws JSExn { throw new JSExn("can't write to org.ibex.js.Reflection.Array's"); } + public JS get(JS key) throws JSExn { return wrap(arr[Script.toInt(key)]); } } // FIXME public static class Hash { } // FIXME public Enumeration keys() throws JSExn { } public JS get(JS key) throws JSExn { - String k = toString(key); + String k = Script.toString(key); try { Field f = this.getClass().getField(k); return wrap(f.get(this)); @@ -54,7 +49,7 @@ public class JSReflection extends JS { } catch (SecurityException nfe) { } try { - Method[] methods = this.getClass().getMethods(); + java.lang.reflect.Method[] methods = this.getClass().getMethods(); for(int i=0; i