1999-05-25 21:49:40 +00:00
|
|
|
|
|
|
|
import java.util.Hashtable;
|
|
|
|
|
1999-05-20 00:14:26 +00:00
|
|
|
class JSObject extends JSValue {
|
|
|
|
|
1999-06-15 00:57:05 +00:00
|
|
|
static JSObject objectPrototype = new JSObject("Object");
|
|
|
|
static JSObject JSUndefined = new JSObject("undefined");
|
1999-05-20 21:16:11 +00:00
|
|
|
|
1999-06-15 00:57:05 +00:00
|
|
|
JSObject(String aClass)
|
|
|
|
{
|
|
|
|
oClass = aClass;
|
|
|
|
prototype = objectPrototype;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPrototype(JSObject aPrototype)
|
1999-05-20 00:14:26 +00:00
|
|
|
{
|
1999-06-11 23:05:16 +00:00
|
|
|
prototype = aPrototype;
|
1999-05-20 00:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String print(String indent)
|
|
|
|
{
|
1999-06-15 00:57:05 +00:00
|
|
|
return indent + "JSObject : " + oClass + "\n";
|
1999-05-20 00:14:26 +00:00
|
|
|
}
|
|
|
|
|
1999-05-26 01:01:07 +00:00
|
|
|
public String toString() {
|
1999-06-15 00:57:05 +00:00
|
|
|
return oClass + contents.toString();
|
1999-05-26 01:01:07 +00:00
|
|
|
}
|
|
|
|
|
1999-05-28 19:00:48 +00:00
|
|
|
JSValue eval(Environment theEnv)
|
1999-05-20 00:14:26 +00:00
|
|
|
{
|
1999-05-28 19:00:48 +00:00
|
|
|
return this;
|
1999-05-20 00:14:26 +00:00
|
|
|
}
|
1999-05-25 21:49:40 +00:00
|
|
|
|
1999-05-28 19:00:48 +00:00
|
|
|
JSValue typeof(Environment theEnv) {
|
1999-05-25 21:49:40 +00:00
|
|
|
if (this == JSUndefined)
|
1999-05-28 19:00:48 +00:00
|
|
|
return new JSString("undefined");
|
1999-05-20 21:16:11 +00:00
|
|
|
else
|
1999-05-28 19:00:48 +00:00
|
|
|
return new JSString("object");
|
1999-05-21 00:54:26 +00:00
|
|
|
}
|
|
|
|
|
1999-05-26 01:01:07 +00:00
|
|
|
JSBoolean toJSBoolean(Environment theEnv) {
|
1999-05-21 00:54:26 +00:00
|
|
|
return JSBoolean.JSTrue;
|
|
|
|
}
|
1999-05-20 21:16:11 +00:00
|
|
|
|
1999-05-26 01:01:07 +00:00
|
|
|
JSDouble toJSDouble(Environment theEnv) {
|
|
|
|
return toPrimitive(theEnv, "Number").toJSDouble(theEnv);
|
1999-05-21 00:54:26 +00:00
|
|
|
}
|
1999-06-11 23:05:16 +00:00
|
|
|
|
|
|
|
JSValue getProp(Environment theEnv, JSString id)
|
|
|
|
{
|
|
|
|
Object v = contents.get(id.s);
|
|
|
|
if (v == null)
|
|
|
|
if (prototype == null)
|
|
|
|
return JSUndefined;
|
|
|
|
else
|
|
|
|
return prototype.getProp(theEnv, id);
|
|
|
|
else
|
|
|
|
return (JSValue)v;
|
1999-05-21 00:54:26 +00:00
|
|
|
}
|
1999-05-25 21:49:40 +00:00
|
|
|
|
1999-06-15 00:57:05 +00:00
|
|
|
boolean hasProp(Environment theEnv, JSString id)
|
|
|
|
{
|
|
|
|
Object v = contents.get(id.s);
|
|
|
|
if (v == null)
|
|
|
|
if (prototype == null)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return prototype.hasProp(theEnv, id);
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
1999-05-28 19:00:48 +00:00
|
|
|
JSValue putProp(Environment theEnv, JSString id, JSValue rV) {
|
|
|
|
contents.put(id.s, rV);
|
|
|
|
return rV;
|
1999-05-20 21:16:11 +00:00
|
|
|
}
|
|
|
|
|
1999-05-25 21:49:40 +00:00
|
|
|
|
|
|
|
Hashtable contents = new Hashtable();
|
|
|
|
|
1999-06-15 00:57:05 +00:00
|
|
|
String oClass;
|
1999-05-20 00:14:26 +00:00
|
|
|
|
1999-06-11 23:05:16 +00:00
|
|
|
JSObject prototype;
|
1999-05-20 00:14:26 +00:00
|
|
|
}
|