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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 | 645 |
646 Scope::Type type = | 646 Scope::Type type = |
647 in_global_context | 647 in_global_context |
648 ? Scope::GLOBAL_SCOPE | 648 ? Scope::GLOBAL_SCOPE |
649 : Scope::EVAL_SCOPE; | 649 : Scope::EVAL_SCOPE; |
650 Handle<String> no_name = isolate()->factory()->empty_symbol(); | 650 Handle<String> no_name = isolate()->factory()->empty_symbol(); |
651 | 651 |
652 FunctionLiteral* result = NULL; | 652 FunctionLiteral* result = NULL; |
653 { Scope* scope = NewScope(top_scope_, type); | 653 { Scope* scope = NewScope(top_scope_, type); |
654 LexicalScope lexical_scope(this, scope, isolate()); | 654 LexicalScope lexical_scope(this, scope, isolate()); |
655 if (strict_mode == kStrictMode) { | 655 top_scope_->SetStrictModeFlag(strict_mode); |
Yang
2011/10/20 14:18:59
Here again. This only works if you assume the prev
Steven
2011/10/21 13:59:00
Because we start with a GLOBAL or EVAL scope the p
| |
656 top_scope_->EnableStrictMode(); | |
657 } | |
658 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); | 656 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); |
659 bool ok = true; | 657 bool ok = true; |
660 int beg_loc = scanner().location().beg_pos; | 658 int beg_loc = scanner().location().beg_pos; |
661 ParseSourceElements(body, Token::EOS, &ok); | 659 ParseSourceElements(body, Token::EOS, &ok); |
662 if (ok && top_scope_->is_strict_mode()) { | 660 if (ok && top_scope_->is_strict_mode()) { |
663 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); | 661 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); |
664 } | 662 } |
665 | 663 |
666 if (ok && harmony_scoping_) { | 664 if (ok && harmony_scoping_) { |
667 CheckConflictingVarDeclarations(scope, &ok); | 665 CheckConflictingVarDeclarations(scope, &ok); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 fni_->PushEnclosingName(name); | 732 fni_->PushEnclosingName(name); |
735 | 733 |
736 mode_ = PARSE_EAGERLY; | 734 mode_ = PARSE_EAGERLY; |
737 | 735 |
738 // Place holder for the result. | 736 // Place holder for the result. |
739 FunctionLiteral* result = NULL; | 737 FunctionLiteral* result = NULL; |
740 | 738 |
741 { | 739 { |
742 // Parse the function literal. | 740 // Parse the function literal. |
743 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE); | 741 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE); |
742 scope->SetStrictModeFlag(shared_info->strict_mode_flag()); | |
Yang
2011/10/20 14:18:59
Ditto.
Steven
2011/10/21 13:59:00
The move before the if was not correct. I added a
| |
744 if (!info->closure().is_null()) { | 743 if (!info->closure().is_null()) { |
745 scope = Scope::DeserializeScopeChain(info, scope); | 744 scope = Scope::DeserializeScopeChain(info, scope); |
746 } | 745 } |
747 LexicalScope lexical_scope(this, scope, isolate()); | 746 LexicalScope lexical_scope(this, scope, isolate()); |
748 | |
749 if (shared_info->strict_mode()) { | |
750 top_scope_->EnableStrictMode(); | |
751 } | |
752 | |
753 FunctionLiteral::Type type = shared_info->is_expression() | 747 FunctionLiteral::Type type = shared_info->is_expression() |
754 ? (shared_info->is_anonymous() | 748 ? (shared_info->is_anonymous() |
755 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 749 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
756 : FunctionLiteral::NAMED_EXPRESSION) | 750 : FunctionLiteral::NAMED_EXPRESSION) |
757 : FunctionLiteral::DECLARATION; | 751 : FunctionLiteral::DECLARATION; |
758 bool ok = true; | 752 bool ok = true; |
759 result = ParseFunctionLiteral(name, | 753 result = ParseFunctionLiteral(name, |
760 false, // Strict mode name already checked. | 754 false, // Strict mode name already checked. |
761 RelocInfo::kNoPosition, | 755 RelocInfo::kNoPosition, |
762 type, | 756 type, |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1189 if ((e_stat = stat->AsExpressionStatement()) != NULL && | 1183 if ((e_stat = stat->AsExpressionStatement()) != NULL && |
1190 (literal = e_stat->expression()->AsLiteral()) != NULL && | 1184 (literal = e_stat->expression()->AsLiteral()) != NULL && |
1191 literal->handle()->IsString()) { | 1185 literal->handle()->IsString()) { |
1192 Handle<String> directive = Handle<String>::cast(literal->handle()); | 1186 Handle<String> directive = Handle<String>::cast(literal->handle()); |
1193 | 1187 |
1194 // Check "use strict" directive (ES5 14.1). | 1188 // Check "use strict" directive (ES5 14.1). |
1195 if (!top_scope_->is_strict_mode() && | 1189 if (!top_scope_->is_strict_mode() && |
1196 directive->Equals(isolate()->heap()->use_strict()) && | 1190 directive->Equals(isolate()->heap()->use_strict()) && |
1197 token_loc.end_pos - token_loc.beg_pos == | 1191 token_loc.end_pos - token_loc.beg_pos == |
1198 isolate()->heap()->use_strict()->length() + 2) { | 1192 isolate()->heap()->use_strict()->length() + 2) { |
1199 top_scope_->EnableStrictMode(); | 1193 top_scope_->SetStrictModeFlag(kStrictMode); |
1200 // "use strict" is the only directive for now. | 1194 // "use strict" is the only directive for now. |
1201 directive_prologue = false; | 1195 directive_prologue = false; |
1202 } | 1196 } |
1203 } else { | 1197 } else { |
1204 // End of the directive prologue. | 1198 // End of the directive prologue. |
1205 directive_prologue = false; | 1199 directive_prologue = false; |
1206 } | 1200 } |
1207 } | 1201 } |
1208 | 1202 |
1209 block_finder.Update(stat); | 1203 block_finder.Update(stat); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1589 | 1583 |
1590 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { | 1584 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { |
1591 // The harmony mode uses source elements instead of statements. | 1585 // The harmony mode uses source elements instead of statements. |
1592 // | 1586 // |
1593 // Block :: | 1587 // Block :: |
1594 // '{' SourceElement* '}' | 1588 // '{' SourceElement* '}' |
1595 | 1589 |
1596 // Construct block expecting 16 statements. | 1590 // Construct block expecting 16 statements. |
1597 Block* body = new(zone()) Block(isolate(), labels, 16, false); | 1591 Block* body = new(zone()) Block(isolate(), labels, 16, false); |
1598 Scope* block_scope = NewScope(top_scope_, Scope::BLOCK_SCOPE); | 1592 Scope* block_scope = NewScope(top_scope_, Scope::BLOCK_SCOPE); |
1599 if (top_scope_->is_strict_mode()) { | |
1600 block_scope->EnableStrictMode(); | |
1601 } | |
1602 | 1593 |
1603 // Parse the statements and collect escaping labels. | 1594 // Parse the statements and collect escaping labels. |
1604 Expect(Token::LBRACE, CHECK_OK); | 1595 Expect(Token::LBRACE, CHECK_OK); |
1605 { SaveScope save_scope(this, block_scope); | 1596 { SaveScope save_scope(this, block_scope); |
1606 TargetCollector collector; | 1597 TargetCollector collector; |
1607 Target target(&this->target_stack_, &collector); | 1598 Target target(&this->target_stack_, &collector); |
1608 Target target_body(&this->target_stack_, body); | 1599 Target target_body(&this->target_stack_, body); |
1609 InitializationBlockFinder block_finder(top_scope_, target_stack_); | 1600 InitializationBlockFinder block_finder(top_scope_, target_stack_); |
1610 | 1601 |
1611 while (peek() != Token::RBRACE) { | 1602 while (peek() != Token::RBRACE) { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1837 // the number of arguments (1 or 2). | 1828 // the number of arguments (1 or 2). |
1838 initialize = | 1829 initialize = |
1839 new(zone()) CallRuntime( | 1830 new(zone()) CallRuntime( |
1840 isolate(), | 1831 isolate(), |
1841 isolate()->factory()->InitializeConstGlobal_symbol(), | 1832 isolate()->factory()->InitializeConstGlobal_symbol(), |
1842 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), | 1833 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), |
1843 arguments); | 1834 arguments); |
1844 } else { | 1835 } else { |
1845 // Add strict mode. | 1836 // Add strict mode. |
1846 // We may want to pass singleton to avoid Literal allocations. | 1837 // We may want to pass singleton to avoid Literal allocations. |
1847 StrictModeFlag flag = initialization_scope->is_strict_mode() | 1838 StrictModeFlag flag = initialization_scope->strict_mode_flag(); |
1848 ? kStrictMode | |
1849 : kNonStrictMode; | |
1850 arguments->Add(NewNumberLiteral(flag)); | 1839 arguments->Add(NewNumberLiteral(flag)); |
1851 | 1840 |
1852 // Be careful not to assign a value to the global variable if | 1841 // Be careful not to assign a value to the global variable if |
1853 // we're in a with. The initialization value should not | 1842 // we're in a with. The initialization value should not |
1854 // necessarily be stored in the global object in that case, | 1843 // necessarily be stored in the global object in that case, |
1855 // which is why we need to generate a separate assignment node. | 1844 // which is why we need to generate a separate assignment node. |
1856 if (value != NULL && !inside_with()) { | 1845 if (value != NULL && !inside_with()) { |
1857 arguments->Add(value); | 1846 arguments->Add(value); |
1858 value = NULL; // zap the value to avoid the unnecessary assignment | 1847 value = NULL; // zap the value to avoid the unnecessary assignment |
1859 } | 1848 } |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2249 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); | 2238 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); |
2250 *ok = false; | 2239 *ok = false; |
2251 return NULL; | 2240 return NULL; |
2252 } | 2241 } |
2253 | 2242 |
2254 Expect(Token::RPAREN, CHECK_OK); | 2243 Expect(Token::RPAREN, CHECK_OK); |
2255 | 2244 |
2256 if (peek() == Token::LBRACE) { | 2245 if (peek() == Token::LBRACE) { |
2257 Target target(&this->target_stack_, &catch_collector); | 2246 Target target(&this->target_stack_, &catch_collector); |
2258 catch_scope = NewScope(top_scope_, Scope::CATCH_SCOPE); | 2247 catch_scope = NewScope(top_scope_, Scope::CATCH_SCOPE); |
2259 if (top_scope_->is_strict_mode()) { | |
2260 catch_scope->EnableStrictMode(); | |
2261 } | |
2262 VariableMode mode = harmony_scoping_ ? LET : VAR; | 2248 VariableMode mode = harmony_scoping_ ? LET : VAR; |
2263 catch_variable = catch_scope->DeclareLocal(name, mode); | 2249 catch_variable = catch_scope->DeclareLocal(name, mode); |
2264 | 2250 |
2265 SaveScope save_scope(this, catch_scope); | 2251 SaveScope save_scope(this, catch_scope); |
2266 catch_block = ParseBlock(NULL, CHECK_OK); | 2252 catch_block = ParseBlock(NULL, CHECK_OK); |
2267 } else { | 2253 } else { |
2268 Expect(Token::LBRACE, CHECK_OK); | 2254 Expect(Token::LBRACE, CHECK_OK); |
2269 } | 2255 } |
2270 | 2256 |
2271 tok = peek(); | 2257 tok = peek(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2369 | 2355 |
2370 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { | 2356 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { |
2371 // ForStatement :: | 2357 // ForStatement :: |
2372 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 2358 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
2373 | 2359 |
2374 Statement* init = NULL; | 2360 Statement* init = NULL; |
2375 | 2361 |
2376 // Create an in-between scope for let-bound iteration variables. | 2362 // Create an in-between scope for let-bound iteration variables. |
2377 Scope* saved_scope = top_scope_; | 2363 Scope* saved_scope = top_scope_; |
2378 Scope* for_scope = NewScope(top_scope_, Scope::BLOCK_SCOPE); | 2364 Scope* for_scope = NewScope(top_scope_, Scope::BLOCK_SCOPE); |
2379 if (top_scope_->is_strict_mode()) { | |
2380 for_scope->EnableStrictMode(); | |
2381 } | |
2382 top_scope_ = for_scope; | 2365 top_scope_ = for_scope; |
2383 | 2366 |
2384 Expect(Token::FOR, CHECK_OK); | 2367 Expect(Token::FOR, CHECK_OK); |
2385 Expect(Token::LPAREN, CHECK_OK); | 2368 Expect(Token::LPAREN, CHECK_OK); |
2386 if (peek() != Token::SEMICOLON) { | 2369 if (peek() != Token::SEMICOLON) { |
2387 if (peek() == Token::VAR || peek() == Token::CONST) { | 2370 if (peek() == Token::VAR || peek() == Token::CONST) { |
2388 Handle<String> name; | 2371 Handle<String> name; |
2389 Block* variable_statement = | 2372 Block* variable_statement = |
2390 ParseVariableDeclarations(kForStatement, NULL, &name, CHECK_OK); | 2373 ParseVariableDeclarations(kForStatement, NULL, &name, CHECK_OK); |
2391 | 2374 |
(...skipping 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3968 if (end_pos <= function_block_pos) { | 3951 if (end_pos <= function_block_pos) { |
3969 // End position greater than end of stream is safe, and hard to check. | 3952 // End position greater than end of stream is safe, and hard to check. |
3970 ReportInvalidPreparseData(function_name, CHECK_OK); | 3953 ReportInvalidPreparseData(function_name, CHECK_OK); |
3971 } | 3954 } |
3972 isolate()->counters()->total_preparse_skipped()->Increment( | 3955 isolate()->counters()->total_preparse_skipped()->Increment( |
3973 end_pos - function_block_pos); | 3956 end_pos - function_block_pos); |
3974 // Seek to position just before terminal '}'. | 3957 // Seek to position just before terminal '}'. |
3975 scanner().SeekForward(end_pos - 1); | 3958 scanner().SeekForward(end_pos - 1); |
3976 materialized_literal_count = entry.literal_count(); | 3959 materialized_literal_count = entry.literal_count(); |
3977 expected_property_count = entry.property_count(); | 3960 expected_property_count = entry.property_count(); |
3978 if (entry.strict_mode()) top_scope_->EnableStrictMode(); | 3961 if (entry.strict_mode()) top_scope_->SetStrictModeFlag(kStrictMode); |
3979 only_simple_this_property_assignments = false; | 3962 only_simple_this_property_assignments = false; |
3980 this_property_assignments = isolate()->factory()->empty_fixed_array(); | 3963 this_property_assignments = isolate()->factory()->empty_fixed_array(); |
3981 Expect(Token::RBRACE, CHECK_OK); | 3964 Expect(Token::RBRACE, CHECK_OK); |
3982 } | 3965 } |
3983 } | 3966 } |
3984 | 3967 |
3985 if (!is_lazily_compiled) { | 3968 if (!is_lazily_compiled) { |
3986 ParseSourceElements(body, Token::RBRACE, CHECK_OK); | 3969 ParseSourceElements(body, Token::RBRACE, CHECK_OK); |
3987 | 3970 |
3988 materialized_literal_count = lexical_scope.materialized_literal_count(); | 3971 materialized_literal_count = lexical_scope.materialized_literal_count(); |
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5378 DeleteArray(message); | 5361 DeleteArray(message); |
5379 for (int i = 0; i < args.length(); i++) { | 5362 for (int i = 0; i < args.length(); i++) { |
5380 DeleteArray(args[i]); | 5363 DeleteArray(args[i]); |
5381 } | 5364 } |
5382 DeleteArray(args.start()); | 5365 DeleteArray(args.start()); |
5383 ASSERT(info->isolate()->has_pending_exception()); | 5366 ASSERT(info->isolate()->has_pending_exception()); |
5384 } else { | 5367 } else { |
5385 Handle<String> source = Handle<String>(String::cast(script->source())); | 5368 Handle<String> source = Handle<String>(String::cast(script->source())); |
5386 result = parser.ParseProgram(source, | 5369 result = parser.ParseProgram(source, |
5387 info->is_global(), | 5370 info->is_global(), |
5388 info->StrictMode()); | 5371 info->strict_mode_flag()); |
5389 } | 5372 } |
5390 } | 5373 } |
5391 info->SetFunction(result); | 5374 info->SetFunction(result); |
5392 return (result != NULL); | 5375 return (result != NULL); |
5393 } | 5376 } |
5394 | 5377 |
5395 } } // namespace v8::internal | 5378 } } // namespace v8::internal |
OLD | NEW |