- public Number coerceToNumber() { throw new JS.Exn("tried to coerce a JavaScript object to a Number"); }
- public String coerceToString() { throw new JS.Exn("tried to coerce a JavaScript object to a String"); }
- public boolean coerceToBoolean() { throw new JS.Exn("tried to coerce a JavaScript object to a Boolean"); }
- public String typeName() { return "object"; }
-
-
- // Inner Classes /////////////////////////////////////////////////////////////////////////
-
- /** 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 Obj(boolean sealed) { this.sealed = sealed; }
- public void setSeal(boolean sealed) { this.sealed = sealed; } ///< a sealed object cannot have its properties modified
- public Object put(Object key, Object val) { put2(key, null, val); return null; }
- protected void put2(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);
- }
+ private static Enumeration emptyEnumeration = new Enumeration() {
+ public boolean hasMoreElements() { return false; }
+ public Object nextElement() { throw new NoSuchElementException(); }
+ };
+
+ private Hash entries = null;
+ public Enumeration keys() throws JSExn {
+ return entries == null ? emptyEnumeration : entries.keys();
+ }
+ public Object get(Object key) throws JSExn { return entries == null ? null : entries.get(key, null); }
+ public void put(Object key, Object val) throws JSExn {
+ if (entries == null) entries = new Hash();
+ entries.put(key, null, val);