- return o.toString();
- }
-
- // Instance Methods ////////////////////////////////////////////////////////////////////
-
- public abstract Object get(Object key) throws JS.Exn;
- public abstract void 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;
- 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-method: " +method);
- }
- }
-
- public Number coerceToNumber() { return new Integer(0); }
- public String coerceToString() { throw new JS.Exn("tried to coerce a JavaScript object to a String"); }
- public boolean coerceToBoolean() { return true; }
-
- public String typeName() { return "object"; }
-
-
- // Inner Classes /////////////////////////////////////////////////////////////////////////
-
- /** A sensible implementation of the abstract methods in the JS class */
- public static class Obj extends JS {
- private Hash entries = null;
- private boolean sealed = false;
- public Obj() { this(false); }
- public Obj(boolean sealed) { this.sealed = sealed; }
- public void setSeal(boolean sealed) { this.sealed = sealed; } ///< a sealed object cannot have its properties modified
- public void put(Object key, Object val) { put(key, null, val); }
- protected void put(Object key, Object key2, Object val) {
- if (sealed) return;
- if (entries == null) entries = new Hash();
- entries.put(key, key2, val); }
- public Object[] keys() { return entries == null ? new Object[0] : entries.keys(); }
- public Object get(Object key) { return get(key, null); }
- protected Object get(Object key, Object key2) {
- if (entries == null) return null;
- if(key2 == null && callMethod((String)key, null, true) == Boolean.TRUE)
- return new Internal.CallableStub(this, key);
- return entries.get(key, key2);
- }