| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left, | 442 void ParserTraits::CheckAssigningFunctionLiteralToProperty(Expression* left, |
| 443 Expression* right) { | 443 Expression* right) { |
| 444 ASSERT(left != NULL); | 444 ASSERT(left != NULL); |
| 445 if (left->AsProperty() != NULL && | 445 if (left->AsProperty() != NULL && |
| 446 right->AsFunctionLiteral() != NULL) { | 446 right->AsFunctionLiteral() != NULL) { |
| 447 right->AsFunctionLiteral()->set_pretenure(); | 447 right->AsFunctionLiteral()->set_pretenure(); |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 | 450 |
| 451 | 451 |
| 452 void ParserTraits::CheckPossibleEvalCall(Expression* expression, |
| 453 Scope* scope) { |
| 454 VariableProxy* callee = expression->AsVariableProxy(); |
| 455 if (callee != NULL && |
| 456 callee->IsVariable(parser_->isolate()->factory()->eval_string())) { |
| 457 scope->DeclarationScope()->RecordEvalCall(); |
| 458 } |
| 459 } |
| 460 |
| 461 |
| 452 Expression* ParserTraits::MarkExpressionAsLValue(Expression* expression) { | 462 Expression* ParserTraits::MarkExpressionAsLValue(Expression* expression) { |
| 453 VariableProxy* proxy = expression != NULL | 463 VariableProxy* proxy = expression != NULL |
| 454 ? expression->AsVariableProxy() | 464 ? expression->AsVariableProxy() |
| 455 : NULL; | 465 : NULL; |
| 456 if (proxy != NULL) proxy->MarkAsLValue(); | 466 if (proxy != NULL) proxy->MarkAsLValue(); |
| 457 return expression; | 467 return expression; |
| 458 } | 468 } |
| 459 | 469 |
| 460 | 470 |
| 461 void ParserTraits::CheckStrictModeLValue(Expression* expression, | 471 void ParserTraits::CheckStrictModeLValue(Expression* expression, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 bool is_generator, | 743 bool is_generator, |
| 734 int function_token_position, | 744 int function_token_position, |
| 735 FunctionLiteral::FunctionType type, | 745 FunctionLiteral::FunctionType type, |
| 736 bool* ok) { | 746 bool* ok) { |
| 737 return parser_->ParseFunctionLiteral(name, function_name_location, | 747 return parser_->ParseFunctionLiteral(name, function_name_location, |
| 738 name_is_strict_reserved, is_generator, | 748 name_is_strict_reserved, is_generator, |
| 739 function_token_position, type, ok); | 749 function_token_position, type, ok); |
| 740 } | 750 } |
| 741 | 751 |
| 742 | 752 |
| 743 Expression* ParserTraits::ParseLeftHandSideExpression(bool* ok) { | 753 Expression* ParserTraits::ParseMemberWithNewPrefixesExpression(bool* ok) { |
| 744 return parser_->ParseLeftHandSideExpression(ok); | 754 return parser_->ParseMemberWithNewPrefixesExpression(ok); |
| 745 } | 755 } |
| 746 | 756 |
| 747 | 757 |
| 748 Parser::Parser(CompilationInfo* info) | 758 Parser::Parser(CompilationInfo* info) |
| 749 : ParserBase<ParserTraits>(&scanner_, | 759 : ParserBase<ParserTraits>(&scanner_, |
| 750 info->isolate()->stack_guard()->real_climit(), | 760 info->isolate()->stack_guard()->real_climit(), |
| 751 info->extension(), | 761 info->extension(), |
| 752 NULL, | 762 NULL, |
| 753 info->zone(), | 763 info->zone(), |
| 754 this), | 764 this), |
| (...skipping 2281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 result->set_scope(for_scope); | 3046 result->set_scope(for_scope); |
| 3037 loop->Initialize(NULL, cond, next, body); | 3047 loop->Initialize(NULL, cond, next, body); |
| 3038 return result; | 3048 return result; |
| 3039 } else { | 3049 } else { |
| 3040 loop->Initialize(init, cond, next, body); | 3050 loop->Initialize(init, cond, next, body); |
| 3041 return loop; | 3051 return loop; |
| 3042 } | 3052 } |
| 3043 } | 3053 } |
| 3044 | 3054 |
| 3045 | 3055 |
| 3046 Expression* Parser::ParseLeftHandSideExpression(bool* ok) { | |
| 3047 // LeftHandSideExpression :: | |
| 3048 // (NewExpression | MemberExpression) ... | |
| 3049 | |
| 3050 Expression* result = ParseMemberWithNewPrefixesExpression(CHECK_OK); | |
| 3051 | |
| 3052 while (true) { | |
| 3053 switch (peek()) { | |
| 3054 case Token::LBRACK: { | |
| 3055 Consume(Token::LBRACK); | |
| 3056 int pos = position(); | |
| 3057 Expression* index = ParseExpression(true, CHECK_OK); | |
| 3058 result = factory()->NewProperty(result, index, pos); | |
| 3059 Expect(Token::RBRACK, CHECK_OK); | |
| 3060 break; | |
| 3061 } | |
| 3062 | |
| 3063 case Token::LPAREN: { | |
| 3064 int pos; | |
| 3065 if (scanner()->current_token() == Token::IDENTIFIER) { | |
| 3066 // For call of an identifier we want to report position of | |
| 3067 // the identifier as position of the call in the stack trace. | |
| 3068 pos = position(); | |
| 3069 } else { | |
| 3070 // For other kinds of calls we record position of the parenthesis as | |
| 3071 // position of the call. Note that this is extremely important for | |
| 3072 // expressions of the form function(){...}() for which call position | |
| 3073 // should not point to the closing brace otherwise it will intersect | |
| 3074 // with positions recorded for function literal and confuse debugger. | |
| 3075 pos = peek_position(); | |
| 3076 // Also the trailing parenthesis are a hint that the function will | |
| 3077 // be called immediately. If we happen to have parsed a preceding | |
| 3078 // function literal eagerly, we can also compile it eagerly. | |
| 3079 if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | |
| 3080 result->AsFunctionLiteral()->set_parenthesized(); | |
| 3081 } | |
| 3082 } | |
| 3083 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); | |
| 3084 | |
| 3085 // Keep track of eval() calls since they disable all local variable | |
| 3086 // optimizations. | |
| 3087 // The calls that need special treatment are the | |
| 3088 // direct eval calls. These calls are all of the form eval(...), with | |
| 3089 // no explicit receiver. | |
| 3090 // These calls are marked as potentially direct eval calls. Whether | |
| 3091 // they are actually direct calls to eval is determined at run time. | |
| 3092 VariableProxy* callee = result->AsVariableProxy(); | |
| 3093 if (callee != NULL && | |
| 3094 callee->IsVariable(isolate()->factory()->eval_string())) { | |
| 3095 scope_->DeclarationScope()->RecordEvalCall(); | |
| 3096 } | |
| 3097 result = factory()->NewCall(result, args, pos); | |
| 3098 if (fni_ != NULL) fni_->RemoveLastFunction(); | |
| 3099 break; | |
| 3100 } | |
| 3101 | |
| 3102 case Token::PERIOD: { | |
| 3103 Consume(Token::PERIOD); | |
| 3104 int pos = position(); | |
| 3105 Handle<String> name = ParseIdentifierName(CHECK_OK); | |
| 3106 result = factory()->NewProperty( | |
| 3107 result, factory()->NewLiteral(name, pos), pos); | |
| 3108 if (fni_ != NULL) fni_->PushLiteralName(name); | |
| 3109 break; | |
| 3110 } | |
| 3111 | |
| 3112 default: | |
| 3113 return result; | |
| 3114 } | |
| 3115 } | |
| 3116 } | |
| 3117 | |
| 3118 | |
| 3119 Expression* Parser::ParseMemberWithNewPrefixesExpression(bool* ok) { | 3056 Expression* Parser::ParseMemberWithNewPrefixesExpression(bool* ok) { |
| 3120 // NewExpression :: | 3057 // NewExpression :: |
| 3121 // ('new')+ MemberExpression | 3058 // ('new')+ MemberExpression |
| 3122 | 3059 |
| 3123 // The grammar for new expressions is pretty warped. We can have several 'new' | 3060 // The grammar for new expressions is pretty warped. We can have several 'new' |
| 3124 // keywords following each other, and then a MemberExpression. When we see '(' | 3061 // keywords following each other, and then a MemberExpression. When we see '(' |
| 3125 // after the MemberExpression, it's associated with the rightmost unassociated | 3062 // after the MemberExpression, it's associated with the rightmost unassociated |
| 3126 // 'new' to create a NewExpression with arguments. However, a NewExpression | 3063 // 'new' to create a NewExpression with arguments. However, a NewExpression |
| 3127 // can also occur without arguments. | 3064 // can also occur without arguments. |
| 3128 | 3065 |
| (...skipping 1739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4868 ASSERT(info()->isolate()->has_pending_exception()); | 4805 ASSERT(info()->isolate()->has_pending_exception()); |
| 4869 } else { | 4806 } else { |
| 4870 result = ParseProgram(); | 4807 result = ParseProgram(); |
| 4871 } | 4808 } |
| 4872 } | 4809 } |
| 4873 info()->SetFunction(result); | 4810 info()->SetFunction(result); |
| 4874 return (result != NULL); | 4811 return (result != NULL); |
| 4875 } | 4812 } |
| 4876 | 4813 |
| 4877 } } // namespace v8::internal | 4814 } } // namespace v8::internal |
| OLD | NEW |