Mozilla/mozilla/js/js2/java/JSInteger.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

74 lines
1.7 KiB
Java

class JSInteger extends JSNumber {
JSInteger(String s)
{
i = new Integer(s).intValue();
}
JSInteger(int p)
{
i = p;
}
void eval(Environment theEnv)
{
theEnv.theStack.push(this);
}
JSBoolean toJSBoolean() {
return (i != 0) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
}
JSDouble toJSDouble() {
return new JSDouble(i);
}
JSInteger toJSInteger() {
return this;
}
JSValue toPrimitive() {
return this;
}
JSString toJSString() {
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();
theEnv.theStack.push(new JSInteger(i & vR.toJSInteger().i));
}
void or(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
theEnv.theStack.push(new JSInteger(i | vR.toJSInteger().i));
}
void xor(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
theEnv.theStack.push(new JSInteger(i ^ vR.toJSInteger().i));
}
void shl(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
theEnv.theStack.push(new JSInteger(i >> vR.toJSInteger().i));
}
void shr(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
theEnv.theStack.push(new JSInteger(i << vR.toJSInteger().i));
}
void ushl(Environment theEnv) {
JSValue vR = theEnv.theStack.pop();
theEnv.theStack.push(new JSInteger(i >>> vR.toJSInteger().i));
}
int i;
}