gecko-dev/js/js2/java/JSObject.java

84 lines
1.9 KiB
Java
Raw Normal View History

import java.util.Hashtable;
1999-05-20 00:14:26 +00:00
class JSObject extends JSValue {
static JSObject objectPrototype = new JSObject("Object");
static JSObject JSUndefined = new JSObject("undefined");
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)
{
return indent + "JSObject : " + oClass + "\n";
1999-05-20 00:14:26 +00:00
}
1999-05-26 01:01:07 +00:00
public String toString() {
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-28 19:00:48 +00:00
JSValue typeof(Environment theEnv) {
if (this == JSUndefined)
1999-05-28 19:00:48 +00:00
return new JSString("undefined");
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-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
}
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;
}
Hashtable contents = new Hashtable();
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
}