implementation for various operators. git-svn-id: svn://10.0.0.236/trunk@32626 18797224-902f-48f8-a5cc-f745e15eee43
71 lines
1.6 KiB
Java
71 lines
1.6 KiB
Java
|
|
import java.util.Hashtable;
|
|
|
|
class JSObject extends JSValue {
|
|
|
|
static JSObject JSUndefined = new JSObject("undefined");
|
|
|
|
JSObject(String aValue)
|
|
{
|
|
value = aValue;
|
|
}
|
|
|
|
String print(String indent)
|
|
{
|
|
return indent + "JSObject : " + value + "\n";
|
|
}
|
|
|
|
void eval(Environment theEnv)
|
|
{
|
|
theEnv.theStack.push(this);
|
|
}
|
|
|
|
void typeof(Environment theEnv) {
|
|
if (this == JSUndefined)
|
|
theEnv.theStack.push(new JSString("undefined"));
|
|
else
|
|
theEnv.theStack.push(new JSString("object"));
|
|
}
|
|
|
|
JSValue defaultValue(String hint) {
|
|
return null; // XXX
|
|
}
|
|
|
|
JSValue toPrimitive(String hint) {
|
|
JSValue result = defaultValue(hint);
|
|
if (result instanceof JSObject)
|
|
throw new JSException(new JSString("default value returned object"));
|
|
else
|
|
return result;
|
|
}
|
|
|
|
JSBoolean toJSBoolean() {
|
|
return JSBoolean.JSTrue;
|
|
}
|
|
|
|
JSDouble toJSDouble() {
|
|
return toPrimitive("Number").toJSDouble();
|
|
}
|
|
|
|
public String toString() {
|
|
return value + contents.toString();
|
|
}
|
|
|
|
void getProp(Environment theEnv) {
|
|
JSString id = theEnv.theStack.pop().toJSString();
|
|
JSValue v = (JSValue)(contents.get(id.s));
|
|
theEnv.theStack.push(v);
|
|
}
|
|
|
|
void putProp(Environment theEnv) {
|
|
JSValue v = theEnv.theStack.pop();
|
|
JSString id = theEnv.theStack.pop().toJSString();
|
|
contents.put(id.s, v);
|
|
}
|
|
|
|
|
|
Hashtable contents = new Hashtable();
|
|
|
|
String value;
|
|
|
|
} |