| 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; |
| 639 } |
| 640 ParsingModeScope parsing_mode(this, mode); |
| 641 |
| 640 FunctionState function_state(this, scope, isolate()); // Enters 'scope'. | 642 FunctionState function_state(this, scope, isolate()); // Enters 'scope'. |
| 641 top_scope_->SetLanguageMode(info->language_mode()); | 643 top_scope_->SetLanguageMode(info->language_mode()); |
| 642 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 644 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
| 643 bool ok = true; | 645 bool ok = true; |
| 644 int beg_loc = scanner().location().beg_pos; | 646 int beg_loc = scanner().location().beg_pos; |
| 645 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); | 647 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); |
| 646 if (ok && !top_scope_->is_classic_mode()) { | 648 if (ok && !top_scope_->is_classic_mode()) { |
| 647 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); | 649 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); |
| 648 } | 650 } |
| 649 | 651 |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 | 1054 |
| 1053 // Check "use strict" directive (ES5 14.1). | 1055 // Check "use strict" directive (ES5 14.1). |
| 1054 if (top_scope_->is_classic_mode() && | 1056 if (top_scope_->is_classic_mode() && |
| 1055 directive->Equals(isolate()->heap()->use_strict()) && | 1057 directive->Equals(isolate()->heap()->use_strict()) && |
| 1056 token_loc.end_pos - token_loc.beg_pos == | 1058 token_loc.end_pos - token_loc.beg_pos == |
| 1057 isolate()->heap()->use_strict()->length() + 2) { | 1059 isolate()->heap()->use_strict()->length() + 2) { |
| 1058 // TODO(mstarzinger): Global strict eval calls, need their own scope | 1060 // 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 | 1061 // 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 | 1062 // add this scope in DoParseProgram(), but that requires adaptations |
| 1061 // all over the code base, so we go with a quick-fix for now. | 1063 // all over the code base, so we go with a quick-fix for now. |
| 1064 // In the same manner, we have to patch the parsing mode. |
| 1062 if (is_eval && !top_scope_->is_eval_scope()) { | 1065 if (is_eval && !top_scope_->is_eval_scope()) { |
| 1063 ASSERT(top_scope_->is_global_scope()); | 1066 ASSERT(top_scope_->is_global_scope()); |
| 1064 Scope* scope = NewScope(top_scope_, EVAL_SCOPE); | 1067 Scope* scope = NewScope(top_scope_, EVAL_SCOPE); |
| 1065 scope->set_start_position(top_scope_->start_position()); | 1068 scope->set_start_position(top_scope_->start_position()); |
| 1066 scope->set_end_position(top_scope_->end_position()); | 1069 scope->set_end_position(top_scope_->end_position()); |
| 1067 top_scope_ = scope; | 1070 top_scope_ = scope; |
| 1071 mode_ = PARSE_EAGERLY; |
| 1068 } | 1072 } |
| 1069 // TODO(ES6): Fix entering extended mode, once it is specified. | 1073 // TODO(ES6): Fix entering extended mode, once it is specified. |
| 1070 top_scope_->SetLanguageMode(FLAG_harmony_scoping | 1074 top_scope_->SetLanguageMode(FLAG_harmony_scoping |
| 1071 ? EXTENDED_MODE : STRICT_MODE); | 1075 ? EXTENDED_MODE : STRICT_MODE); |
| 1072 // "use strict" is the only directive for now. | 1076 // "use strict" is the only directive for now. |
| 1073 directive_prologue = false; | 1077 directive_prologue = false; |
| 1074 } | 1078 } |
| 1075 } else { | 1079 } else { |
| 1076 // End of the directive prologue. | 1080 // End of the directive prologue. |
| 1077 directive_prologue = false; | 1081 directive_prologue = false; |
| (...skipping 4846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5924 ASSERT(info->isolate()->has_pending_exception()); | 5928 ASSERT(info->isolate()->has_pending_exception()); |
| 5925 } else { | 5929 } else { |
| 5926 result = parser.ParseProgram(); | 5930 result = parser.ParseProgram(); |
| 5927 } | 5931 } |
| 5928 } | 5932 } |
| 5929 info->SetFunction(result); | 5933 info->SetFunction(result); |
| 5930 return (result != NULL); | 5934 return (result != NULL); |
| 5931 } | 5935 } |
| 5932 | 5936 |
| 5933 } } // namespace v8::internal | 5937 } } // namespace v8::internal |
| OLD | NEW |