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

41 lines
1.1 KiB
Java

class LogicalNode extends BinaryNode {
LogicalNode(String aOp, ExpressionNode aLeft, ExpressionNode aRight)
{
super(aOp, aLeft, aRight);
}
void eval(Environment theEnv)
{
left.eval(theEnv);
JSBoolean b = theEnv.theStack.pop().toJSBoolean(theEnv);
if (op == "&&") {
if (b.isFalse())
theEnv.theStack.push(b);
else {
right.eval(theEnv);
b = theEnv.theStack.pop().toJSBoolean(theEnv);
if (b.isFalse())
theEnv.theStack.push(b);
else
theEnv.theStack.push(JSBoolean.JSTrue);
}
}
if (op == "||") {
if (b.isTrue())
theEnv.theStack.push(b);
else {
right.eval(theEnv);
b = theEnv.theStack.pop().toJSBoolean(theEnv);
if (b.isTrue())
theEnv.theStack.push(b);
else
theEnv.theStack.push(JSBoolean.JSFalse);
}
}
else
System.out.println("missing logical op " + op);
}
}