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 3623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3634 // that case, we don't have a function name (it's empty). | 3634 // that case, we don't have a function name (it's empty). |
3635 Handle<String> name = | 3635 Handle<String> name = |
3636 is_named ? var_name : isolate()->factory()->empty_symbol(); | 3636 is_named ? var_name : isolate()->factory()->empty_symbol(); |
3637 // The function name, if any. | 3637 // The function name, if any. |
3638 Handle<String> function_name = isolate()->factory()->empty_symbol(); | 3638 Handle<String> function_name = isolate()->factory()->empty_symbol(); |
3639 if (is_named && (type == EXPRESSION || type == NESTED)) { | 3639 if (is_named && (type == EXPRESSION || type == NESTED)) { |
3640 function_name = name; | 3640 function_name = name; |
3641 } | 3641 } |
3642 | 3642 |
3643 int num_parameters = 0; | 3643 int num_parameters = 0; |
3644 Scope* scope = NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); | 3644 // Function declarations are hoisted. |
3645 Scope* scope = (type == DECLARATION) | |
3646 ? NewScope(top_scope_->DeclarationScope(), Scope::FUNCTION_SCOPE, false) | |
3647 : NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); | |
3645 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8); | 3648 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8); |
3646 int materialized_literal_count; | 3649 int materialized_literal_count; |
3647 int expected_property_count; | 3650 int expected_property_count; |
3648 int start_pos; | 3651 int start_pos; |
3649 int end_pos; | 3652 int end_pos; |
3650 bool only_simple_this_property_assignments; | 3653 bool only_simple_this_property_assignments; |
3651 Handle<FixedArray> this_property_assignments; | 3654 Handle<FixedArray> this_property_assignments; |
3652 bool has_duplicate_parameters = false; | 3655 bool has_duplicate_parameters = false; |
3653 // Parse function body. | 3656 // Parse function body. |
3654 { LexicalScope lexical_scope(this, scope, isolate()); | 3657 { LexicalScope lexical_scope(this, scope, isolate()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3708 top_scope_->NewUnresolved(function_name, inside_with()); | 3711 top_scope_->NewUnresolved(function_name, inside_with()); |
3709 fproxy->BindTo(fvar); | 3712 fproxy->BindTo(fvar); |
3710 body->Add(new(zone()) ExpressionStatement( | 3713 body->Add(new(zone()) ExpressionStatement( |
3711 new(zone()) Assignment(isolate(), | 3714 new(zone()) Assignment(isolate(), |
3712 Token::INIT_CONST, | 3715 Token::INIT_CONST, |
3713 fproxy, | 3716 fproxy, |
3714 new(zone()) ThisFunction(isolate()), | 3717 new(zone()) ThisFunction(isolate()), |
3715 RelocInfo::kNoPosition))); | 3718 RelocInfo::kNoPosition))); |
3716 } | 3719 } |
3717 | 3720 |
3718 // Determine if the function will be lazily compiled. The mode can | 3721 // Determine if the function will be lazily compiled. The mode can only |
3719 // only be PARSE_LAZILY if the --lazy flag is true. | 3722 // be PARSE_LAZILY if the --lazy flag is true. We will not lazily |
3723 // compile if we do not have preparser data for the function. | |
3720 bool is_lazily_compiled = (mode() == PARSE_LAZILY && | 3724 bool is_lazily_compiled = (mode() == PARSE_LAZILY && |
3721 top_scope_->outer_scope()->is_global_scope() && | 3725 top_scope_->outer_scope()->is_global_scope() && |
3722 top_scope_->HasTrivialOuterContext() && | 3726 top_scope_->HasTrivialOuterContext() && |
3723 !parenthesized_function_); | 3727 !parenthesized_function_ && |
3728 pre_data() != NULL); | |
3724 parenthesized_function_ = false; // The bit was set for this function only. | 3729 parenthesized_function_ = false; // The bit was set for this function only. |
3725 | 3730 |
3726 int function_block_pos = scanner().location().beg_pos; | 3731 if (is_lazily_compiled) { |
3727 if (is_lazily_compiled && pre_data() != NULL) { | 3732 int function_block_pos = scanner().location().beg_pos; |
3728 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); | 3733 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); |
3729 if (!entry.is_valid()) { | 3734 if (!entry.is_valid()) { |
3730 ReportInvalidPreparseData(name, CHECK_OK); | 3735 // There is no preparser data for the function, we will not lazily |
3736 // compile after all. | |
3737 is_lazily_compiled = false; | |
Lasse Reichstein
2011/08/03 09:05:17
This handles false positives (from the parser's pe
Kevin Millikin (Chromium)
2011/08/03 09:09:49
Thanks for pointing that out, I hadn't realized it
| |
3738 } else { | |
3739 end_pos = entry.end_pos(); | |
3740 if (end_pos <= function_block_pos) { | |
3741 // End position greater than end of stream is safe, and hard to check. | |
3742 ReportInvalidPreparseData(name, CHECK_OK); | |
3743 } | |
3744 isolate()->counters()->total_preparse_skipped()->Increment( | |
3745 end_pos - function_block_pos); | |
3746 // Seek to position just before terminal '}'. | |
3747 scanner().SeekForward(end_pos - 1); | |
3748 materialized_literal_count = entry.literal_count(); | |
3749 expected_property_count = entry.property_count(); | |
3750 if (entry.strict_mode()) top_scope_->EnableStrictMode(); | |
3751 only_simple_this_property_assignments = false; | |
3752 this_property_assignments = isolate()->factory()->empty_fixed_array(); | |
3753 Expect(Token::RBRACE, CHECK_OK); | |
3731 } | 3754 } |
3732 end_pos = entry.end_pos(); | 3755 } |
3733 if (end_pos <= function_block_pos) { | 3756 |
3734 // End position greater than end of stream is safe, and hard to check. | 3757 if (!is_lazily_compiled) { |
3735 ReportInvalidPreparseData(name, CHECK_OK); | |
3736 } | |
3737 isolate()->counters()->total_preparse_skipped()->Increment( | |
3738 end_pos - function_block_pos); | |
3739 // Seek to position just before terminal '}'. | |
3740 scanner().SeekForward(end_pos - 1); | |
3741 materialized_literal_count = entry.literal_count(); | |
3742 expected_property_count = entry.property_count(); | |
3743 if (entry.strict_mode()) top_scope_->EnableStrictMode(); | |
3744 only_simple_this_property_assignments = false; | |
3745 this_property_assignments = isolate()->factory()->empty_fixed_array(); | |
3746 Expect(Token::RBRACE, CHECK_OK); | |
3747 } else { | |
3748 ParseSourceElements(body, Token::RBRACE, CHECK_OK); | 3758 ParseSourceElements(body, Token::RBRACE, CHECK_OK); |
3749 | 3759 |
3750 materialized_literal_count = lexical_scope.materialized_literal_count(); | 3760 materialized_literal_count = lexical_scope.materialized_literal_count(); |
3751 expected_property_count = lexical_scope.expected_property_count(); | 3761 expected_property_count = lexical_scope.expected_property_count(); |
3752 only_simple_this_property_assignments = | 3762 only_simple_this_property_assignments = |
3753 lexical_scope.only_simple_this_property_assignments(); | 3763 lexical_scope.only_simple_this_property_assignments(); |
3754 this_property_assignments = lexical_scope.this_property_assignments(); | 3764 this_property_assignments = lexical_scope.this_property_assignments(); |
3755 | 3765 |
3756 Expect(Token::RBRACE, CHECK_OK); | 3766 Expect(Token::RBRACE, CHECK_OK); |
3757 end_pos = scanner().location().end_pos; | 3767 end_pos = scanner().location().end_pos; |
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5111 info->is_global(), | 5121 info->is_global(), |
5112 info->StrictMode()); | 5122 info->StrictMode()); |
5113 } | 5123 } |
5114 } | 5124 } |
5115 | 5125 |
5116 info->SetFunction(result); | 5126 info->SetFunction(result); |
5117 return (result != NULL); | 5127 return (result != NULL); |
5118 } | 5128 } |
5119 | 5129 |
5120 } } // namespace v8::internal | 5130 } } // namespace v8::internal |
OLD | NEW |