Mozilla/mozilla/js/js2/java/JSString.java
rogerl%netscape.com 1c31755a34 JSValue changes, closing in on JSObject API. Began 'correct' semantic
implementation for various operators.


git-svn-id: svn://10.0.0.236/trunk@32626 18797224-902f-48f8-a5cc-f745e15eee43
1999-05-25 21:49:40 +00:00

97 lines
2.7 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.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().s) == 1) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble().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().s) != -1) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble().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().s) == -1) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble().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().s) != 1) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble().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().s) == 0) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble().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().s) != 0) ? JSBoolean.JSTrue : JSBoolean.JSFalse);
}
else
toJSDouble().ne(theEnv);
}
JSDouble toJSDouble() {
return new JSDouble(s); // XXX Way More To Do, see Rhino ScriptRuntime.java
}
JSString toJSString() {
return this;
}
JSValue toPrimitive() {
return this;
}
protected String s;
}