Mozilla/mozilla/js/js2/java/JSString.java
rogerl%netscape.com 300d6f0885 Hmmm, new changes these are.
git-svn-id: svn://10.0.0.236/trunk@32641 18797224-902f-48f8-a5cc-f745e15eee43
1999-05-26 01:01:07 +00:00

102 lines
2.9 KiB
Java

class JSString extends JSValue {
JSString(String p)
{
s = p;
}
void eval(Environment theEnv)
{
theEnv.theStack.push(this);
}
void typeof(Environment theEnv) {
theEnv.theStack.push(new JSString("string"));
}
void add(Environment theEnv)
{
JSString vR = theEnv.theStack.pop().toJSString(theEnv);
theEnv.theStack.push(new JSString(s + vR.s));
}
void gt(Environment theEnv) {
JSValue vR = theEnv.theStack.peek();
if (vR instanceof JSString) {
theEnv.theStack.pop();
theEnv.theStack.push((s.compareTo(vR.toJSString(theEnv).s) == 1) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble(theEnv).gt(theEnv);
}
void ge(Environment theEnv) {
JSValue vR = theEnv.theStack.peek();
if (vR instanceof JSString) {
theEnv.theStack.pop();
theEnv.theStack.push((s.compareTo(vR.toJSString(theEnv).s) != -1) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble(theEnv).ge(theEnv);
}
void lt(Environment theEnv) {
JSValue vR = theEnv.theStack.peek();
if (vR instanceof JSString) {
theEnv.theStack.pop();
theEnv.theStack.push((s.compareTo(vR.toJSString(theEnv).s) == -1) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble(theEnv).lt(theEnv);
}
void le(Environment theEnv) {
JSValue vR = theEnv.theStack.peek();
if (vR instanceof JSString) {
theEnv.theStack.pop();
theEnv.theStack.push((s.compareTo(vR.toJSString(theEnv).s) != 1) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble(theEnv).le(theEnv);
}
void eq(Environment theEnv) {
JSValue vR = theEnv.theStack.peek();
if (vR instanceof JSString) {
theEnv.theStack.pop();
theEnv.theStack.push((s.compareTo(vR.toJSString(theEnv).s) == 0) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble(theEnv).eq(theEnv);
}
void ne(Environment theEnv) {
JSValue vR = theEnv.theStack.peek();
if (vR instanceof JSString) {
theEnv.theStack.pop();
theEnv.theStack.push((s.compareTo(vR.toJSString(theEnv).s) != 0) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble(theEnv).ne(theEnv);
}
JSDouble toJSDouble(Environment theEnv) {
return new JSDouble(s); // XXX Way More To Do, see Rhino ScriptRuntime.java
}
JSString toJSString(Environment theEnv) {
return this;
}
JSValue toPrimitive(Environment theEnv, String hint) {
return this;
}
String print(String indent)
{
return indent + "JSString : " + s + "\n";
}
protected String s;
}