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

83 lines
2.4 KiB
Java
Raw Normal View History

1999-05-20 00:14:26 +00:00
class JSString extends JSValue {
JSString(String p)
{
s = p;
}
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) {
return new JSString("string");
}
1999-05-28 19:00:48 +00:00
JSValue add(Environment theEnv, JSValue rV)
{
1999-05-28 19:00:48 +00:00
return new JSString(s + rV.toJSString(theEnv).s);
}
1999-05-21 00:54:26 +00:00
1999-05-28 19:00:48 +00:00
JSValue gt(Environment theEnv, JSValue rV) {
if (rV instanceof JSString)
return (s.compareTo(rV.toJSString(theEnv).s) == 1) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
1999-05-21 00:54:26 +00:00
else
1999-05-28 19:00:48 +00:00
return toJSDouble(theEnv).gt(theEnv, rV);
1999-05-21 00:54:26 +00:00
}
1999-05-28 19:00:48 +00:00
JSValue ge(Environment theEnv, JSValue rV) {
if (rV instanceof JSString)
return (s.compareTo(rV.toJSString(theEnv).s) != -1) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
1999-05-21 00:54:26 +00:00
else
1999-05-28 19:00:48 +00:00
return toJSDouble(theEnv).ge(theEnv, rV);
1999-05-21 00:54:26 +00:00
}
1999-05-28 19:00:48 +00:00
JSValue lt(Environment theEnv, JSValue rV) {
if (rV instanceof JSString)
return (s.compareTo(rV.toJSString(theEnv).s) == -1) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
1999-05-21 00:54:26 +00:00
else
1999-05-28 19:00:48 +00:00
return toJSDouble(theEnv).lt(theEnv, rV);
1999-05-21 00:54:26 +00:00
}
1999-05-28 19:00:48 +00:00
JSValue le(Environment theEnv, JSValue rV) {
if (rV instanceof JSString)
return (s.compareTo(rV.toJSString(theEnv).s) != 1) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
1999-05-21 00:54:26 +00:00
else
1999-05-28 19:00:48 +00:00
return toJSDouble(theEnv).le(theEnv, rV);
1999-05-21 00:54:26 +00:00
}
1999-05-28 19:00:48 +00:00
JSValue eq(Environment theEnv, JSValue rV) {
if (rV instanceof JSString)
return (s.compareTo(rV.toJSString(theEnv).s) == 0) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
1999-05-21 00:54:26 +00:00
else
1999-05-28 19:00:48 +00:00
return toJSDouble(theEnv).eq(theEnv, rV);
1999-05-21 00:54:26 +00:00
}
1999-05-28 19:00:48 +00:00
JSValue ne(Environment theEnv, JSValue rV) {
if (rV instanceof JSString)
return (s.compareTo(rV.toJSString(theEnv).s) != 0) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
1999-05-21 00:54:26 +00:00
else
1999-05-28 19:00:48 +00:00
return toJSDouble(theEnv).ne(theEnv, rV);
1999-05-21 00:54:26 +00:00
}
1999-05-26 01:01:07 +00:00
JSDouble toJSDouble(Environment theEnv) {
1999-05-21 00:54:26 +00:00
return new JSDouble(s); // XXX Way More To Do, see Rhino ScriptRuntime.java
}
1999-05-26 01:01:07 +00:00
JSString toJSString(Environment theEnv) {
1999-05-21 00:54:26 +00:00
return this;
}
1999-05-26 01:01:07 +00:00
JSValue toPrimitive(Environment theEnv, String hint) {
return this;
}
1999-05-20 00:14:26 +00:00
1999-05-26 01:01:07 +00:00
String print(String indent)
{
return indent + "JSString : " + s + "\n";
}
protected String s;
1999-05-20 00:14:26 +00:00
}