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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 } | 607 } |
608 | 608 |
609 | 609 |
610 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, | 610 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, |
611 Handle<String> source, | 611 Handle<String> source, |
612 ZoneScope* zone_scope) { | 612 ZoneScope* zone_scope) { |
613 ASSERT(top_scope_ == NULL); | 613 ASSERT(top_scope_ == NULL); |
614 ASSERT(target_stack_ == NULL); | 614 ASSERT(target_stack_ == NULL); |
615 if (pre_data_ != NULL) pre_data_->Initialize(); | 615 if (pre_data_ != NULL) pre_data_->Initialize(); |
616 | 616 |
617 // Compute the parsing mode. | |
618 Mode mode = (FLAG_lazy && allow_lazy_) ? PARSE_LAZILY : PARSE_EAGERLY; | |
619 if (allow_natives_syntax_ || extension_ != NULL) mode = PARSE_EAGERLY; | |
620 ParsingModeScope parsing_mode(this, mode); | |
621 | |
622 Handle<String> no_name = isolate()->factory()->empty_symbol(); | 617 Handle<String> no_name = isolate()->factory()->empty_symbol(); |
623 | 618 |
624 FunctionLiteral* result = NULL; | 619 FunctionLiteral* result = NULL; |
625 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); | 620 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); |
626 info->SetGlobalScope(scope); | 621 info->SetGlobalScope(scope); |
627 if (!info->context().is_null()) { | 622 if (!info->context().is_null()) { |
628 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); | 623 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); |
629 } | 624 } |
630 if (info->is_eval()) { | 625 if (info->is_eval()) { |
631 if (!scope->is_global_scope() || info->language_mode() != CLASSIC_MODE) { | 626 if (!scope->is_global_scope() || info->language_mode() != CLASSIC_MODE) { |
632 scope = NewScope(scope, EVAL_SCOPE); | 627 scope = NewScope(scope, EVAL_SCOPE); |
633 } | 628 } |
634 } else if (info->is_global()) { | 629 } else if (info->is_global()) { |
635 scope = NewScope(scope, GLOBAL_SCOPE); | 630 scope = NewScope(scope, GLOBAL_SCOPE); |
636 } | 631 } |
637 scope->set_start_position(0); | 632 scope->set_start_position(0); |
638 scope->set_end_position(source->length()); | 633 scope->set_end_position(source->length()); |
639 | 634 |
635 // Compute the parsing mode. | |
636 Mode mode = (FLAG_lazy && allow_lazy_) ? PARSE_LAZILY : PARSE_EAGERLY; | |
637 if (allow_natives_syntax_ || extension_ != NULL || scope->is_eval_scope()) | |
638 mode = PARSE_EAGERLY; | |
Michael Starzinger
2012/12/07 09:50:17
Curly braces around body.
rossberg
2012/12/07 10:23:33
Done.
| |
639 ParsingModeScope parsing_mode(this, mode); | |
640 | |
640 FunctionState function_state(this, scope, isolate()); // Enters 'scope'. | 641 FunctionState function_state(this, scope, isolate()); // Enters 'scope'. |
641 top_scope_->SetLanguageMode(info->language_mode()); | 642 top_scope_->SetLanguageMode(info->language_mode()); |
642 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 643 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
643 bool ok = true; | 644 bool ok = true; |
644 int beg_loc = scanner().location().beg_pos; | 645 int beg_loc = scanner().location().beg_pos; |
645 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); | 646 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); |
646 if (ok && !top_scope_->is_classic_mode()) { | 647 if (ok && !top_scope_->is_classic_mode()) { |
647 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); | 648 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); |
648 } | 649 } |
649 | 650 |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1052 | 1053 |
1053 // Check "use strict" directive (ES5 14.1). | 1054 // Check "use strict" directive (ES5 14.1). |
1054 if (top_scope_->is_classic_mode() && | 1055 if (top_scope_->is_classic_mode() && |
1055 directive->Equals(isolate()->heap()->use_strict()) && | 1056 directive->Equals(isolate()->heap()->use_strict()) && |
1056 token_loc.end_pos - token_loc.beg_pos == | 1057 token_loc.end_pos - token_loc.beg_pos == |
1057 isolate()->heap()->use_strict()->length() + 2) { | 1058 isolate()->heap()->use_strict()->length() + 2) { |
1058 // TODO(mstarzinger): Global strict eval calls, need their own scope | 1059 // TODO(mstarzinger): Global strict eval calls, need their own scope |
1059 // as specified in ES5 10.4.2(3). The correct fix would be to always | 1060 // as specified in ES5 10.4.2(3). The correct fix would be to always |
1060 // add this scope in DoParseProgram(), but that requires adaptations | 1061 // add this scope in DoParseProgram(), but that requires adaptations |
1061 // all over the code base, so we go with a quick-fix for now. | 1062 // all over the code base, so we go with a quick-fix for now. |
1063 // In the same manner, we have to patch the parsing mode. | |
1062 if (is_eval && !top_scope_->is_eval_scope()) { | 1064 if (is_eval && !top_scope_->is_eval_scope()) { |
1063 ASSERT(top_scope_->is_global_scope()); | 1065 ASSERT(top_scope_->is_global_scope()); |
1064 Scope* scope = NewScope(top_scope_, EVAL_SCOPE); | 1066 Scope* scope = NewScope(top_scope_, EVAL_SCOPE); |
1065 scope->set_start_position(top_scope_->start_position()); | 1067 scope->set_start_position(top_scope_->start_position()); |
1066 scope->set_end_position(top_scope_->end_position()); | 1068 scope->set_end_position(top_scope_->end_position()); |
1067 top_scope_ = scope; | 1069 top_scope_ = scope; |
1070 mode_ = PARSE_EAGERLY; | |
1068 } | 1071 } |
1069 // TODO(ES6): Fix entering extended mode, once it is specified. | 1072 // TODO(ES6): Fix entering extended mode, once it is specified. |
1070 top_scope_->SetLanguageMode(FLAG_harmony_scoping | 1073 top_scope_->SetLanguageMode(FLAG_harmony_scoping |
1071 ? EXTENDED_MODE : STRICT_MODE); | 1074 ? EXTENDED_MODE : STRICT_MODE); |
1072 // "use strict" is the only directive for now. | 1075 // "use strict" is the only directive for now. |
1073 directive_prologue = false; | 1076 directive_prologue = false; |
1074 } | 1077 } |
1075 } else { | 1078 } else { |
1076 // End of the directive prologue. | 1079 // End of the directive prologue. |
1077 directive_prologue = false; | 1080 directive_prologue = false; |
(...skipping 4846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5924 ASSERT(info->isolate()->has_pending_exception()); | 5927 ASSERT(info->isolate()->has_pending_exception()); |
5925 } else { | 5928 } else { |
5926 result = parser.ParseProgram(); | 5929 result = parser.ParseProgram(); |
5927 } | 5930 } |
5928 } | 5931 } |
5929 info->SetFunction(result); | 5932 info->SetFunction(result); |
5930 return (result != NULL); | 5933 return (result != NULL); |
5931 } | 5934 } |
5932 | 5935 |
5933 } } // namespace v8::internal | 5936 } } // namespace v8::internal |
OLD | NEW |