| 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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 | 597 |
| 598 // Compute the parsing mode. | 598 // Compute the parsing mode. |
| 599 mode_ = (FLAG_lazy && allow_lazy_) ? PARSE_LAZILY : PARSE_EAGERLY; | 599 mode_ = (FLAG_lazy && allow_lazy_) ? PARSE_LAZILY : PARSE_EAGERLY; |
| 600 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; | 600 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; |
| 601 | 601 |
| 602 Handle<String> no_name = isolate()->factory()->empty_symbol(); | 602 Handle<String> no_name = isolate()->factory()->empty_symbol(); |
| 603 | 603 |
| 604 FunctionLiteral* result = NULL; | 604 FunctionLiteral* result = NULL; |
| 605 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); | 605 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); |
| 606 info->SetGlobalScope(scope); | 606 info->SetGlobalScope(scope); |
| 607 if (!info->is_global() && | 607 if (info->is_eval()) { |
| 608 (info->shared_info().is_null() || info->shared_info()->is_function())) { | 608 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 609 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope); | 609 if (!info->is_global() && (shared.is_null() || shared->is_function())) { |
| 610 scope = NewScope(scope, EVAL_SCOPE); | 610 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope); |
| 611 } |
| 612 if (!scope->is_global_scope() || info->language_mode() != CLASSIC_MODE) { |
| 613 scope = NewScope(scope, EVAL_SCOPE); |
| 614 } |
| 611 } | 615 } |
| 612 scope->set_start_position(0); | 616 scope->set_start_position(0); |
| 613 scope->set_end_position(source->length()); | 617 scope->set_end_position(source->length()); |
| 614 FunctionState function_state(this, scope, isolate()); | 618 FunctionState function_state(this, scope, isolate()); |
| 615 top_scope_->SetLanguageMode(info->language_mode()); | 619 top_scope_->SetLanguageMode(info->language_mode()); |
| 616 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); | 620 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); |
| 617 bool ok = true; | 621 bool ok = true; |
| 618 int beg_loc = scanner().location().beg_pos; | 622 int beg_loc = scanner().location().beg_pos; |
| 619 ParseSourceElements(body, Token::EOS, &ok); | 623 ParseSourceElements(body, Token::EOS, info->is_eval(), &ok); |
| 620 if (ok && !top_scope_->is_classic_mode()) { | 624 if (ok && !top_scope_->is_classic_mode()) { |
| 621 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); | 625 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); |
| 622 } | 626 } |
| 623 | 627 |
| 624 if (ok && is_extended_mode()) { | 628 if (ok && is_extended_mode()) { |
| 625 CheckConflictingVarDeclarations(scope, &ok); | 629 CheckConflictingVarDeclarations(top_scope_, &ok); |
| 626 } | 630 } |
| 627 | 631 |
| 628 if (ok) { | 632 if (ok) { |
| 629 result = factory()->NewFunctionLiteral( | 633 result = factory()->NewFunctionLiteral( |
| 630 no_name, | 634 no_name, |
| 631 top_scope_, | 635 top_scope_, |
| 632 body, | 636 body, |
| 633 function_state.materialized_literal_count(), | 637 function_state.materialized_literal_count(), |
| 634 function_state.expected_property_count(), | 638 function_state.expected_property_count(), |
| 635 function_state.handler_count(), | 639 function_state.handler_count(), |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 Isolate* isolate_; | 1093 Isolate* isolate_; |
| 1090 bool only_simple_this_property_assignments_; | 1094 bool only_simple_this_property_assignments_; |
| 1091 ZoneStringList names_; | 1095 ZoneStringList names_; |
| 1092 ZoneList<int> assigned_arguments_; | 1096 ZoneList<int> assigned_arguments_; |
| 1093 ZoneObjectList assigned_constants_; | 1097 ZoneObjectList assigned_constants_; |
| 1094 }; | 1098 }; |
| 1095 | 1099 |
| 1096 | 1100 |
| 1097 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, | 1101 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, |
| 1098 int end_token, | 1102 int end_token, |
| 1103 bool is_eval, |
| 1099 bool* ok) { | 1104 bool* ok) { |
| 1100 // SourceElements :: | 1105 // SourceElements :: |
| 1101 // (ModuleElement)* <end_token> | 1106 // (ModuleElement)* <end_token> |
| 1102 | 1107 |
| 1103 // Allocate a target stack to use for this set of source | 1108 // Allocate a target stack to use for this set of source |
| 1104 // elements. This way, all scripts and functions get their own | 1109 // elements. This way, all scripts and functions get their own |
| 1105 // target stack thus avoiding illegal breaks and continues across | 1110 // target stack thus avoiding illegal breaks and continues across |
| 1106 // functions. | 1111 // functions. |
| 1107 TargetScope scope(&this->target_stack_); | 1112 TargetScope scope(&this->target_stack_); |
| 1108 | 1113 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1131 if ((e_stat = stat->AsExpressionStatement()) != NULL && | 1136 if ((e_stat = stat->AsExpressionStatement()) != NULL && |
| 1132 (literal = e_stat->expression()->AsLiteral()) != NULL && | 1137 (literal = e_stat->expression()->AsLiteral()) != NULL && |
| 1133 literal->handle()->IsString()) { | 1138 literal->handle()->IsString()) { |
| 1134 Handle<String> directive = Handle<String>::cast(literal->handle()); | 1139 Handle<String> directive = Handle<String>::cast(literal->handle()); |
| 1135 | 1140 |
| 1136 // Check "use strict" directive (ES5 14.1). | 1141 // Check "use strict" directive (ES5 14.1). |
| 1137 if (top_scope_->is_classic_mode() && | 1142 if (top_scope_->is_classic_mode() && |
| 1138 directive->Equals(isolate()->heap()->use_strict()) && | 1143 directive->Equals(isolate()->heap()->use_strict()) && |
| 1139 token_loc.end_pos - token_loc.beg_pos == | 1144 token_loc.end_pos - token_loc.beg_pos == |
| 1140 isolate()->heap()->use_strict()->length() + 2) { | 1145 isolate()->heap()->use_strict()->length() + 2) { |
| 1146 // TODO(mstarzinger): Global strict eval calls, need their own scope |
| 1147 // as specified in ES5 10.4.2(3). The correct fix would be to always |
| 1148 // add this scope in DoParseProgram(), but that requires adaptations |
| 1149 // all over the code base, so we go with a quick-fix for now. |
| 1150 if (is_eval && !top_scope_->is_eval_scope()) { |
| 1151 ASSERT(top_scope_->is_global_scope()); |
| 1152 Scope* scope = NewScope(top_scope_, EVAL_SCOPE); |
| 1153 scope->set_start_position(top_scope_->start_position()); |
| 1154 scope->set_end_position(top_scope_->end_position()); |
| 1155 top_scope_ = scope; |
| 1156 } |
| 1141 // TODO(ES6): Fix entering extended mode, once it is specified. | 1157 // TODO(ES6): Fix entering extended mode, once it is specified. |
| 1142 top_scope_->SetLanguageMode(FLAG_harmony_scoping | 1158 top_scope_->SetLanguageMode(FLAG_harmony_scoping |
| 1143 ? EXTENDED_MODE : STRICT_MODE); | 1159 ? EXTENDED_MODE : STRICT_MODE); |
| 1144 // "use strict" is the only directive for now. | 1160 // "use strict" is the only directive for now. |
| 1145 directive_prologue = false; | 1161 directive_prologue = false; |
| 1146 } | 1162 } |
| 1147 } else { | 1163 } else { |
| 1148 // End of the directive prologue. | 1164 // End of the directive prologue. |
| 1149 directive_prologue = false; | 1165 directive_prologue = false; |
| 1150 } | 1166 } |
| (...skipping 3390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4541 if (fvar != NULL) { | 4557 if (fvar != NULL) { |
| 4542 VariableProxy* fproxy = | 4558 VariableProxy* fproxy = |
| 4543 top_scope_->NewUnresolved(factory(), function_name); | 4559 top_scope_->NewUnresolved(factory(), function_name); |
| 4544 fproxy->BindTo(fvar); | 4560 fproxy->BindTo(fvar); |
| 4545 body->Add(factory()->NewExpressionStatement( | 4561 body->Add(factory()->NewExpressionStatement( |
| 4546 factory()->NewAssignment(fvar_init_op, | 4562 factory()->NewAssignment(fvar_init_op, |
| 4547 fproxy, | 4563 fproxy, |
| 4548 factory()->NewThisFunction(), | 4564 factory()->NewThisFunction(), |
| 4549 RelocInfo::kNoPosition))); | 4565 RelocInfo::kNoPosition))); |
| 4550 } | 4566 } |
| 4551 ParseSourceElements(body, Token::RBRACE, CHECK_OK); | 4567 ParseSourceElements(body, Token::RBRACE, false, CHECK_OK); |
| 4552 | 4568 |
| 4553 materialized_literal_count = function_state.materialized_literal_count(); | 4569 materialized_literal_count = function_state.materialized_literal_count(); |
| 4554 expected_property_count = function_state.expected_property_count(); | 4570 expected_property_count = function_state.expected_property_count(); |
| 4555 handler_count = function_state.handler_count(); | 4571 handler_count = function_state.handler_count(); |
| 4556 only_simple_this_property_assignments = | 4572 only_simple_this_property_assignments = |
| 4557 function_state.only_simple_this_property_assignments(); | 4573 function_state.only_simple_this_property_assignments(); |
| 4558 this_property_assignments = function_state.this_property_assignments(); | 4574 this_property_assignments = function_state.this_property_assignments(); |
| 4559 | 4575 |
| 4560 Expect(Token::RBRACE, CHECK_OK); | 4576 Expect(Token::RBRACE, CHECK_OK); |
| 4561 scope->set_end_position(scanner().location().end_pos); | 4577 scope->set_end_position(scanner().location().end_pos); |
| (...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5999 ASSERT(info->isolate()->has_pending_exception()); | 6015 ASSERT(info->isolate()->has_pending_exception()); |
| 6000 } else { | 6016 } else { |
| 6001 result = parser.ParseProgram(info); | 6017 result = parser.ParseProgram(info); |
| 6002 } | 6018 } |
| 6003 } | 6019 } |
| 6004 info->SetFunction(result); | 6020 info->SetFunction(result); |
| 6005 return (result != NULL); | 6021 return (result != NULL); |
| 6006 } | 6022 } |
| 6007 | 6023 |
| 6008 } } // namespace v8::internal | 6024 } } // namespace v8::internal |
| OLD | NEW |