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 {
+
+ // FIXME: move these to an interface so they're optional
+ // 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;
+
+ // FIXME: be smart here; perhaps intern
+ public static final Number N(int i) { return new Integer(i); }
+ public static final Number N(long l) { return new Long(l); }
+ public static final Number N(double d) { return new Double(d); }
+
+ public static final Boolean B(boolean b) { return b ? Boolean.TRUE : Boolean.FALSE; }
+
private Hash entries = null;
private boolean sealed = false;
public Obj() { this(false); }
public static class Scope extends ScopeImpl {
public Scope(Scope parentScope) { this(parentScope, false); }
public Scope(Scope parentScope, boolean sealed) { super(parentScope, sealed); }
- public boolean isTransparent() { return super.isTransparent(); } //< transparent scopes are not returned by THIS
public boolean has(Object key) { return super.has(key); }
public Object get(Object key) { return super._get(key); }
public Object put(Object key, Object val) { super._put(key, val); return null; }
}
}
+
+ 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);
+
+ }
+ }
+
}