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 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 no_name, | 652 no_name, |
653 top_scope_, | 653 top_scope_, |
654 body, | 654 body, |
655 lexical_scope.materialized_literal_count(), | 655 lexical_scope.materialized_literal_count(), |
656 lexical_scope.expected_property_count(), | 656 lexical_scope.expected_property_count(), |
657 lexical_scope.only_simple_this_property_assignments(), | 657 lexical_scope.only_simple_this_property_assignments(), |
658 lexical_scope.this_property_assignments(), | 658 lexical_scope.this_property_assignments(), |
659 0, | 659 0, |
660 0, | 660 0, |
661 source->length(), | 661 source->length(), |
662 false, | 662 true, // is_expression |
Vyacheslav Egorov (Chromium)
2011/08/09 12:24:57
Can we change it to pass FunctionLiteralType inste
Kevin Millikin (Chromium)
2011/08/09 12:42:52
Good idea. Done. I had to move it to ast to avoi
| |
663 false); | 663 true, // is_anonymous |
664 false); // has_duplicate_parameters | |
664 } else if (stack_overflow_) { | 665 } else if (stack_overflow_) { |
665 isolate()->StackOverflow(); | 666 isolate()->StackOverflow(); |
666 } | 667 } |
667 } | 668 } |
668 | 669 |
669 // Make sure the target stack is empty. | 670 // Make sure the target stack is empty. |
670 ASSERT(target_stack_ == NULL); | 671 ASSERT(target_stack_ == NULL); |
671 | 672 |
672 // If there was a syntax error we have to get rid of the AST | 673 // If there was a syntax error we have to get rid of the AST |
673 // and it is not safe to do so before the scope has been deleted. | 674 // and it is not safe to do so before the scope has been deleted. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); | 723 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); |
723 if (!info->closure().is_null()) { | 724 if (!info->closure().is_null()) { |
724 scope = Scope::DeserializeScopeChain(info, scope); | 725 scope = Scope::DeserializeScopeChain(info, scope); |
725 } | 726 } |
726 LexicalScope lexical_scope(this, scope, isolate()); | 727 LexicalScope lexical_scope(this, scope, isolate()); |
727 | 728 |
728 if (shared_info->strict_mode()) { | 729 if (shared_info->strict_mode()) { |
729 top_scope_->EnableStrictMode(); | 730 top_scope_->EnableStrictMode(); |
730 } | 731 } |
731 | 732 |
732 FunctionLiteralType type = | 733 FunctionLiteralType type = shared_info->is_expression() |
733 shared_info->is_expression() ? EXPRESSION : DECLARATION; | 734 ? (shared_info->is_anonymous() |
734 Handle<String> function_name = | 735 ? ANONYMOUS_EXPRESSION |
735 shared_info->is_anonymous() ? Handle<String>::null() : name; | 736 : NAMED_EXPRESSION) |
737 : DECLARATION; | |
736 bool ok = true; | 738 bool ok = true; |
737 result = ParseFunctionLiteral(function_name, | 739 result = ParseFunctionLiteral(name, |
738 false, // Strict mode name already checked. | 740 false, // Strict mode name already checked. |
739 RelocInfo::kNoPosition, | 741 RelocInfo::kNoPosition, |
740 type, | 742 type, |
741 &ok); | 743 &ok); |
742 // Make sure the results agree. | 744 // Make sure the results agree. |
743 ASSERT(ok == (result != NULL)); | 745 ASSERT(ok == (result != NULL)); |
744 } | 746 } |
745 | 747 |
746 // Make sure the target stack is empty. | 748 // Make sure the target stack is empty. |
747 ASSERT(target_stack_ == NULL); | 749 ASSERT(target_stack_ == NULL); |
(...skipping 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2839 Expression* result = NULL; | 2841 Expression* result = NULL; |
2840 if (peek() == Token::FUNCTION) { | 2842 if (peek() == Token::FUNCTION) { |
2841 Expect(Token::FUNCTION, CHECK_OK); | 2843 Expect(Token::FUNCTION, CHECK_OK); |
2842 int function_token_position = scanner().location().beg_pos; | 2844 int function_token_position = scanner().location().beg_pos; |
2843 Handle<String> name; | 2845 Handle<String> name; |
2844 bool is_strict_reserved_name = false; | 2846 bool is_strict_reserved_name = false; |
2845 if (peek_any_identifier()) { | 2847 if (peek_any_identifier()) { |
2846 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, | 2848 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, |
2847 CHECK_OK); | 2849 CHECK_OK); |
2848 } | 2850 } |
2851 FunctionLiteralType type = | |
2852 name.is_null() ? ANONYMOUS_EXPRESSION : NAMED_EXPRESSION; | |
2849 result = ParseFunctionLiteral(name, | 2853 result = ParseFunctionLiteral(name, |
2850 is_strict_reserved_name, | 2854 is_strict_reserved_name, |
2851 function_token_position, | 2855 function_token_position, |
2852 EXPRESSION, | 2856 type, |
2853 CHECK_OK); | 2857 CHECK_OK); |
2854 } else { | 2858 } else { |
2855 result = ParsePrimaryExpression(CHECK_OK); | 2859 result = ParsePrimaryExpression(CHECK_OK); |
2856 } | 2860 } |
2857 | 2861 |
2858 while (true) { | 2862 while (true) { |
2859 switch (peek()) { | 2863 switch (peek()) { |
2860 case Token::LBRACK: { | 2864 case Token::LBRACK: { |
2861 Consume(Token::LBRACK); | 2865 Consume(Token::LBRACK); |
2862 int pos = scanner().location().beg_pos; | 2866 int pos = scanner().location().beg_pos; |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3412 Handle<String> name; | 3416 Handle<String> name; |
3413 if (is_keyword) { | 3417 if (is_keyword) { |
3414 name = isolate_->factory()->LookupAsciiSymbol(Token::String(next)); | 3418 name = isolate_->factory()->LookupAsciiSymbol(Token::String(next)); |
3415 } else { | 3419 } else { |
3416 name = GetSymbol(CHECK_OK); | 3420 name = GetSymbol(CHECK_OK); |
3417 } | 3421 } |
3418 FunctionLiteral* value = | 3422 FunctionLiteral* value = |
3419 ParseFunctionLiteral(name, | 3423 ParseFunctionLiteral(name, |
3420 false, // reserved words are allowed here | 3424 false, // reserved words are allowed here |
3421 RelocInfo::kNoPosition, | 3425 RelocInfo::kNoPosition, |
3422 EXPRESSION, | 3426 ANONYMOUS_EXPRESSION, |
3423 CHECK_OK); | 3427 CHECK_OK); |
3424 // Allow any number of parameters for compatiabilty with JSC. | 3428 // Allow any number of parameters for compatiabilty with JSC. |
3425 // Specification only allows zero parameters for get and one for set. | 3429 // Specification only allows zero parameters for get and one for set. |
3426 ObjectLiteral::Property* property = | 3430 ObjectLiteral::Property* property = |
3427 new(zone()) ObjectLiteral::Property(is_getter, value); | 3431 new(zone()) ObjectLiteral::Property(is_getter, value); |
3428 return property; | 3432 return property; |
3429 } else { | 3433 } else { |
3430 ReportUnexpectedToken(next); | 3434 ReportUnexpectedToken(next); |
3431 *ok = false; | 3435 *ok = false; |
3432 return NULL; | 3436 return NULL; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3702 Expect(Token::RPAREN, CHECK_OK); | 3706 Expect(Token::RPAREN, CHECK_OK); |
3703 | 3707 |
3704 Expect(Token::LBRACE, CHECK_OK); | 3708 Expect(Token::LBRACE, CHECK_OK); |
3705 | 3709 |
3706 // If we have a named function expression, we add a local variable | 3710 // If we have a named function expression, we add a local variable |
3707 // declaration to the body of the function with the name of the | 3711 // declaration to the body of the function with the name of the |
3708 // function and let it refer to the function itself (closure). | 3712 // function and let it refer to the function itself (closure). |
3709 // NOTE: We create a proxy and resolve it here so that in the | 3713 // NOTE: We create a proxy and resolve it here so that in the |
3710 // future we can change the AST to only refer to VariableProxies | 3714 // future we can change the AST to only refer to VariableProxies |
3711 // instead of Variables and Proxis as is the case now. | 3715 // instead of Variables and Proxis as is the case now. |
3712 if (type == EXPRESSION && function_name->length() > 0) { | 3716 if (type == NAMED_EXPRESSION) { |
3713 Variable* fvar = top_scope_->DeclareFunctionVar(function_name); | 3717 Variable* fvar = top_scope_->DeclareFunctionVar(function_name); |
3714 VariableProxy* fproxy = | 3718 VariableProxy* fproxy = |
3715 top_scope_->NewUnresolved(function_name, inside_with()); | 3719 top_scope_->NewUnresolved(function_name, inside_with()); |
3716 fproxy->BindTo(fvar); | 3720 fproxy->BindTo(fvar); |
3717 body->Add(new(zone()) ExpressionStatement( | 3721 body->Add(new(zone()) ExpressionStatement( |
3718 new(zone()) Assignment(isolate(), | 3722 new(zone()) Assignment(isolate(), |
3719 Token::INIT_CONST, | 3723 Token::INIT_CONST, |
3720 fproxy, | 3724 fproxy, |
3721 new(zone()) ThisFunction(isolate()), | 3725 new(zone()) ThisFunction(isolate()), |
3722 RelocInfo::kNoPosition))); | 3726 RelocInfo::kNoPosition))); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3820 function_name, | 3824 function_name, |
3821 scope, | 3825 scope, |
3822 body, | 3826 body, |
3823 materialized_literal_count, | 3827 materialized_literal_count, |
3824 expected_property_count, | 3828 expected_property_count, |
3825 only_simple_this_property_assignments, | 3829 only_simple_this_property_assignments, |
3826 this_property_assignments, | 3830 this_property_assignments, |
3827 num_parameters, | 3831 num_parameters, |
3828 start_pos, | 3832 start_pos, |
3829 end_pos, | 3833 end_pos, |
3830 type == EXPRESSION, | 3834 type != DECLARATION, |
Vyacheslav Egorov (Chromium)
2011/08/09 12:24:57
Ditto.
Vyacheslav Egorov (Chromium)
2011/08/09 12:24:57
Ditto.
| |
3835 type == ANONYMOUS_EXPRESSION, | |
3831 has_duplicate_parameters); | 3836 has_duplicate_parameters); |
3832 function_literal->set_function_token_position(function_token_position); | 3837 function_literal->set_function_token_position(function_token_position); |
3833 | 3838 |
3834 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 3839 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
3835 return function_literal; | 3840 return function_literal; |
3836 } | 3841 } |
3837 | 3842 |
3838 | 3843 |
3839 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 3844 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
3840 // CallRuntime :: | 3845 // CallRuntime :: |
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5125 info->is_global(), | 5130 info->is_global(), |
5126 info->StrictMode()); | 5131 info->StrictMode()); |
5127 } | 5132 } |
5128 } | 5133 } |
5129 | 5134 |
5130 info->SetFunction(result); | 5135 info->SetFunction(result); |
5131 return (result != NULL); | 5136 return (result != NULL); |
5132 } | 5137 } |
5133 | 5138 |
5134 } } // namespace v8::internal | 5139 } } // namespace v8::internal |
OLD | NEW |