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

74 lines
1.8 KiB
Java
Raw Normal View History

1999-05-20 00:14:26 +00:00
class JSInteger extends JSNumber {
JSInteger(String s)
{
i = new Integer(s).intValue();
}
JSInteger(int p)
{
i = p;
}
1999-05-20 00:14:26 +00:00
void eval(Environment theEnv)
{
theEnv.theStack.push(this);
}
1999-05-26 01:01:07 +00:00
JSBoolean toJSBoolean(Environment theEnv) {
return (i != 0) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
1999-05-20 00:14:26 +00:00
}
1999-05-26 01:01:07 +00:00
JSDouble toJSDouble(Environment theEnv) {
return new JSDouble(i);
}
1999-05-26 01:01:07 +00:00
JSInteger toJSInteger(Environment theEnv) {
return this;
}
1999-05-26 01:01:07 +00:00
JSValue toPrimitive(Environment theEnv, String hint) {
1999-05-21 00:54:26 +00:00
return this;
}
1999-05-26 01:01:07 +00:00
JSString toJSString(Environment theEnv) {
return new JSString(Integer.toString(i));
}
void twiddle(Environment theEnv) {
theEnv.theStack.push(new JSInteger(~i));
}
void and(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
1999-05-26 01:01:07 +00:00
theEnv.theStack.push(new JSInteger(i & vR.toJSInteger(theEnv).i));
}
void or(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
1999-05-26 01:01:07 +00:00
theEnv.theStack.push(new JSInteger(i | vR.toJSInteger(theEnv).i));
}
void xor(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
1999-05-26 01:01:07 +00:00
theEnv.theStack.push(new JSInteger(i ^ vR.toJSInteger(theEnv).i));
}
void shl(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
1999-05-26 01:01:07 +00:00
theEnv.theStack.push(new JSInteger(i >> vR.toJSInteger(theEnv).i));
}
void shr(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
1999-05-26 01:01:07 +00:00
theEnv.theStack.push(new JSInteger(i << vR.toJSInteger(theEnv).i));
}
void ushl(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
1999-05-26 01:01:07 +00:00
theEnv.theStack.push(new JSInteger(i >>> vR.toJSInteger(theEnv).i));
}
1999-05-20 00:14:26 +00:00
int i;
}