Index: src/parser.cc |
=================================================================== |
--- src/parser.cc (revision 8322) |
+++ src/parser.cc (working copy) |
@@ -2545,18 +2545,26 @@ |
int position = scanner().location().beg_pos; |
Expression* expression = ParseUnaryExpression(CHECK_OK); |
- // Compute some expressions involving only number literals. |
- if (expression != NULL && expression->AsLiteral() && |
- expression->AsLiteral()->handle()->IsNumber()) { |
- double value = expression->AsLiteral()->handle()->Number(); |
- switch (op) { |
- case Token::ADD: |
- return expression; |
- case Token::SUB: |
- return NewNumberLiteral(-value); |
- case Token::BIT_NOT: |
- return NewNumberLiteral(~DoubleToInt32(value)); |
- default: break; |
+ if (expression != NULL && (expression->AsLiteral() != NULL)) { |
+ Handle<Object> literal = expression->AsLiteral()->handle(); |
+ if (op == Token::NOT) { |
+ // Convert the literal to a boolean condition and negate it. |
+ bool condition = literal->ToBoolean()->IsTrue(); |
+ Handle<Object> result(isolate()->heap()->ToBoolean(!condition)); |
+ return new(zone()) Literal(result); |
+ } else if (literal->IsNumber()) { |
+ // Compute some expressions involving only number literals. |
+ double value = literal->Number(); |
+ switch (op) { |
+ case Token::ADD: |
+ return expression; |
+ case Token::SUB: |
+ return NewNumberLiteral(-value); |
+ case Token::BIT_NOT: |
+ return NewNumberLiteral(~DoubleToInt32(value)); |
+ default: |
+ break; |
+ } |
} |
} |