public abstract Object get(Object key) throws JS.Exn;
public abstract Object put(Object key, Object val) throws JS.Exn;
public abstract Object[] keys();
+
public Object callMethod(Object method, Array args, boolean checkOnly) throws JS.Exn {
- if (checkOnly) return Boolean.FALSE;
+ if(checkOnly) return Boolean.FALSE;
Object o = get(method);
- if (o instanceof JS.Callable) return ((JS.Callable)o).call(args);
- else if (o == null) throw new JS.Exn("Attempted to call non-existent method: " + method);
- else throw new JS.Exn("Attempted to call a non-function: " +method);
+ if(o instanceof JS.Callable) {
+ return ((JS.Callable)o).call(args);
+ } else if(o == null) {
+ throw new JS.Exn("Attempted to call non-existent method: " + method);
+ } else {
+ throw new JS.Exn("Attempted to call a non-method: " +method);
+ }
}
public Number coerceToNumber() { throw new JS.Exn("tried to coerce a JavaScript object to a Number"); }
/** A sensible implementation of the abstract methods in the JS class */
public static class Obj extends JS {
+ // this gets around a wierd fluke in the Java type checking rules for ?..:
+ public static final Object T = Boolean.TRUE;
+ public static final Object F = Boolean.FALSE;
private Hash entries = null;
private boolean sealed = false;
public Obj() { this(false); }
}
}
+
+ public static void recurse(String indent, String name, Object o) {
+ if (!name.equals("")) name += " : ";
+
+ if (o == null) {
+ Log.logJS(indent + name + "<null>");
+
+ } else if (o instanceof JS.Array) {
+ Log.logJS(indent + name + "<array>");
+ JS.Array na = (JS.Array)o;
+ for(int i=0; i<na.length(); i++)
+ recurse(indent + " ", i + "", na.elementAt(i));
+
+ } else if (o instanceof JS) {
+ Log.logJS(indent + name + "<object>");
+ JS s = (JS)o;
+ Object[] keys = s.keys();
+ for(int i=0; i<keys.length; i++)
+ if (keys[i] != null)
+ recurse(indent + " ", keys[i].toString(),
+ (keys[i] instanceof Integer) ?
+ s.get(((Integer)keys[i])) : s.get(keys[i].toString()));
+
+ } else {
+ Log.logJS(indent + name + o);
+
+ }
+ }
+
}