Continuing JSValue fun.

git-svn-id: svn://10.0.0.236/trunk@32436 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rogerl%netscape.com
1999-05-21 00:54:26 +00:00
parent 426e6d0544
commit f70f2834fd
7 changed files with 212 additions and 10 deletions

View File

@@ -26,10 +26,126 @@ class JSObject extends JSValue {
}
else
theEnv.theStack.push(v);
}
}
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;
}
public String toString()
{
JSDouble toJSDouble() {
return toPrimitive("Number").toJSDouble();
}
void gt(Environment theEnv) {
JSValue lV = toPrimitive("Number");
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
if ((lV instanceof JSString) && (rV instanceof JSString)) {
theEnv.theStack.push(rV);
lV.gt(theEnv);
}
else {
theEnv.theStack.push(rV.toJSDouble());
lV.toJSDouble().gt(theEnv);
}
}
void ge(Environment theEnv) {
JSValue lV = toPrimitive("Number");
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
if ((lV instanceof JSString) && (rV instanceof JSString)) {
theEnv.theStack.push(rV);
lV.ge(theEnv);
}
else {
theEnv.theStack.push(rV.toJSDouble());
lV.toJSDouble().ge(theEnv);
}
}
void lt(Environment theEnv) {
JSValue lV = toPrimitive("Number");
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
if ((lV instanceof JSString) && (rV instanceof JSString)) {
theEnv.theStack.push(rV);
lV.lt(theEnv);
}
else {
theEnv.theStack.push(rV.toJSDouble());
lV.toJSDouble().lt(theEnv);
}
}
void le(Environment theEnv) {
JSValue lV = toPrimitive("Number");
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
if ((lV instanceof JSString) && (rV instanceof JSString)) {
theEnv.theStack.push(rV);
lV.le(theEnv);
}
else {
theEnv.theStack.push(rV.toJSDouble());
lV.toJSDouble().le(theEnv);
}
}
void eq(Environment theEnv) {
JSValue lV = toPrimitive("Number");
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
if ((lV instanceof JSString) && (rV instanceof JSString)) {
theEnv.theStack.push(rV);
lV.eq(theEnv);
}
else {
theEnv.theStack.push(rV.toJSDouble());
lV.toJSDouble().eq(theEnv);
}
}
void ne(Environment theEnv) {
JSValue lV = toPrimitive("Number");
JSValue rV = theEnv.theStack.pop().toPrimitive("Number");
if ((lV instanceof JSString) && (rV instanceof JSString)) {
theEnv.theStack.push(rV);
lV.ne(theEnv);
}
else {
theEnv.theStack.push(rV.toJSDouble());
lV.toJSDouble().ne(theEnv);
}
}
void add(Environment theEnv) {
JSValue lV = toPrimitive("");
JSValue rV = theEnv.theStack.pop().toPrimitive("");
if ((lV instanceof JSString) || (rV instanceof JSString)) {
theEnv.theStack.push(rV);
lV.ne(theEnv);
}
else {
theEnv.theStack.push(rV.toJSDouble());
lV.toJSDouble().add(theEnv);
}
}
void subtract(Environment theEnv) {
theEnv.theStack.push(theEnv.theStack.pop().toJSDouble());
toJSDouble().subtract(theEnv);
}
public String toString() {
return value;
}