OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2538 // '-' UnaryExpression | 2538 // '-' UnaryExpression |
2539 // '~' UnaryExpression | 2539 // '~' UnaryExpression |
2540 // '!' UnaryExpression | 2540 // '!' UnaryExpression |
2541 | 2541 |
2542 Token::Value op = peek(); | 2542 Token::Value op = peek(); |
2543 if (Token::IsUnaryOp(op)) { | 2543 if (Token::IsUnaryOp(op)) { |
2544 op = Next(); | 2544 op = Next(); |
2545 int position = scanner().location().beg_pos; | 2545 int position = scanner().location().beg_pos; |
2546 Expression* expression = ParseUnaryExpression(CHECK_OK); | 2546 Expression* expression = ParseUnaryExpression(CHECK_OK); |
2547 | 2547 |
2548 // Compute some expressions involving only number literals. | 2548 if (expression != NULL && (expression->AsLiteral() != NULL)) { |
2549 if (expression != NULL && expression->AsLiteral() && | 2549 Handle<Object> literal = expression->AsLiteral()->handle(); |
2550 expression->AsLiteral()->handle()->IsNumber()) { | 2550 if (op == Token::NOT) { |
2551 double value = expression->AsLiteral()->handle()->Number(); | 2551 // Convert the literal to a boolean condition and negate it. |
2552 switch (op) { | 2552 bool condition = literal->ToBoolean()->IsTrue(); |
2553 case Token::ADD: | 2553 Handle<Object> result(isolate()->heap()->ToBoolean(!condition)); |
2554 return expression; | 2554 return new(zone()) Literal(result); |
2555 case Token::SUB: | 2555 } else if (literal->IsNumber()) { |
2556 return NewNumberLiteral(-value); | 2556 // Compute some expressions involving only number literals. |
2557 case Token::BIT_NOT: | 2557 double value = literal->Number(); |
2558 return NewNumberLiteral(~DoubleToInt32(value)); | 2558 switch (op) { |
2559 default: break; | 2559 case Token::ADD: |
| 2560 return expression; |
| 2561 case Token::SUB: |
| 2562 return NewNumberLiteral(-value); |
| 2563 case Token::BIT_NOT: |
| 2564 return NewNumberLiteral(~DoubleToInt32(value)); |
| 2565 default: |
| 2566 break; |
| 2567 } |
2560 } | 2568 } |
2561 } | 2569 } |
2562 | 2570 |
2563 // "delete identifier" is a syntax error in strict mode. | 2571 // "delete identifier" is a syntax error in strict mode. |
2564 if (op == Token::DELETE && top_scope_->is_strict_mode()) { | 2572 if (op == Token::DELETE && top_scope_->is_strict_mode()) { |
2565 VariableProxy* operand = expression->AsVariableProxy(); | 2573 VariableProxy* operand = expression->AsVariableProxy(); |
2566 if (operand != NULL && !operand->is_this()) { | 2574 if (operand != NULL && !operand->is_this()) { |
2567 ReportMessage("strict_delete", Vector<const char*>::empty()); | 2575 ReportMessage("strict_delete", Vector<const char*>::empty()); |
2568 *ok = false; | 2576 *ok = false; |
2569 return NULL; | 2577 return NULL; |
(...skipping 2425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4995 info->is_global(), | 5003 info->is_global(), |
4996 info->StrictMode()); | 5004 info->StrictMode()); |
4997 } | 5005 } |
4998 } | 5006 } |
4999 | 5007 |
5000 info->SetFunction(result); | 5008 info->SetFunction(result); |
5001 return (result != NULL); | 5009 return (result != NULL); |
5002 } | 5010 } |
5003 | 5011 |
5004 } } // namespace v8::internal | 5012 } } // namespace v8::internal |
OLD | NEW |