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

40 lines
1009 B
Java
Raw Normal View History

1999-05-20 00:14:26 +00:00
class LogicalNode extends BinaryNode {
LogicalNode(String aOp, ExpressionNode aLeft, ExpressionNode aRight)
{
super(aOp, aLeft, aRight);
}
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
JSBoolean b = left.eval(theEnv).toJSBoolean(theEnv);
1999-05-20 00:14:26 +00:00
if (op == "&&") {
if (b.isFalse())
1999-05-28 19:00:48 +00:00
return b;
1999-05-20 00:14:26 +00:00
else {
1999-05-28 19:00:48 +00:00
b = right.eval(theEnv).toJSBoolean(theEnv);
if (b.isFalse())
1999-05-28 19:00:48 +00:00
return b;
1999-05-20 00:14:26 +00:00
else
1999-05-28 19:00:48 +00:00
return JSBoolean.JSTrue;
1999-05-20 00:14:26 +00:00
}
}
if (op == "||") {
if (b.isTrue())
1999-05-28 19:00:48 +00:00
return b;
1999-05-20 00:14:26 +00:00
else {
1999-05-28 19:00:48 +00:00
b = right.eval(theEnv).toJSBoolean(theEnv);
if (b.isTrue())
1999-05-28 19:00:48 +00:00
return b;
1999-05-20 00:14:26 +00:00
else
1999-05-28 19:00:48 +00:00
return JSBoolean.JSFalse;
1999-05-20 00:14:26 +00:00
}
}
1999-05-28 19:00:48 +00:00
else {
1999-05-20 00:14:26 +00:00
System.out.println("missing logical op " + op);
1999-05-28 19:00:48 +00:00
return null;
}
1999-05-20 00:14:26 +00:00
}
}