Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: src/parser.cc

Issue 8417035: Introduce extended mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased version. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 fni_(NULL), 600 fni_(NULL),
601 stack_overflow_(false), 601 stack_overflow_(false),
602 parenthesized_function_(false), 602 parenthesized_function_(false),
603 harmony_scoping_(false) { 603 harmony_scoping_(false) {
604 AstNode::ResetIds(); 604 AstNode::ResetIds();
605 } 605 }
606 606
607 607
608 FunctionLiteral* Parser::ParseProgram(Handle<String> source, 608 FunctionLiteral* Parser::ParseProgram(Handle<String> source,
609 bool in_global_context, 609 bool in_global_context,
610 StrictModeFlag strict_mode) { 610 LanguageMode language_mode) {
611 ZoneScope zone_scope(isolate(), DONT_DELETE_ON_EXIT); 611 ZoneScope zone_scope(isolate(), DONT_DELETE_ON_EXIT);
612 612
613 HistogramTimerScope timer(isolate()->counters()->parse()); 613 HistogramTimerScope timer(isolate()->counters()->parse());
614 isolate()->counters()->total_parse_size()->Increment(source->length()); 614 isolate()->counters()->total_parse_size()->Increment(source->length());
615 fni_ = new(zone()) FuncNameInferrer(isolate()); 615 fni_ = new(zone()) FuncNameInferrer(isolate());
616 616
617 // Initialize parser state. 617 // Initialize parser state.
618 source->TryFlatten(); 618 source->TryFlatten();
619 if (source->IsExternalTwoByteString()) { 619 if (source->IsExternalTwoByteString()) {
620 // Notice that the stream is destroyed at the end of the branch block. 620 // Notice that the stream is destroyed at the end of the branch block.
621 // The last line of the blocks can't be moved outside, even though they're 621 // The last line of the blocks can't be moved outside, even though they're
622 // identical calls. 622 // identical calls.
623 ExternalTwoByteStringUC16CharacterStream stream( 623 ExternalTwoByteStringUC16CharacterStream stream(
624 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); 624 Handle<ExternalTwoByteString>::cast(source), 0, source->length());
625 scanner_.Initialize(&stream); 625 scanner_.Initialize(&stream);
626 return DoParseProgram(source, in_global_context, strict_mode, &zone_scope); 626 return
627 DoParseProgram(source, in_global_context, language_mode, &zone_scope);
627 } else { 628 } else {
628 GenericStringUC16CharacterStream stream(source, 0, source->length()); 629 GenericStringUC16CharacterStream stream(source, 0, source->length());
629 scanner_.Initialize(&stream); 630 scanner_.Initialize(&stream);
630 return DoParseProgram(source, in_global_context, strict_mode, &zone_scope); 631 return
632 DoParseProgram(source, in_global_context, language_mode, &zone_scope);
631 } 633 }
632 } 634 }
633 635
634 636
635 FunctionLiteral* Parser::DoParseProgram(Handle<String> source, 637 FunctionLiteral* Parser::DoParseProgram(Handle<String> source,
636 bool in_global_context, 638 bool in_global_context,
637 StrictModeFlag strict_mode, 639 LanguageMode language_mode,
638 ZoneScope* zone_scope) { 640 ZoneScope* zone_scope) {
639 ASSERT(top_scope_ == NULL); 641 ASSERT(top_scope_ == NULL);
640 ASSERT(target_stack_ == NULL); 642 ASSERT(target_stack_ == NULL);
641 if (pre_data_ != NULL) pre_data_->Initialize(); 643 if (pre_data_ != NULL) pre_data_->Initialize();
642 644
643 // Compute the parsing mode. 645 // Compute the parsing mode.
644 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; 646 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY;
645 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; 647 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY;
646 648
647 ScopeType type = in_global_context ? GLOBAL_SCOPE : EVAL_SCOPE; 649 ScopeType type = in_global_context ? GLOBAL_SCOPE : EVAL_SCOPE;
648 Handle<String> no_name = isolate()->factory()->empty_symbol(); 650 Handle<String> no_name = isolate()->factory()->empty_symbol();
649 651
650 FunctionLiteral* result = NULL; 652 FunctionLiteral* result = NULL;
651 { Scope* scope = NewScope(top_scope_, type); 653 { Scope* scope = NewScope(top_scope_, type);
652 scope->set_start_position(0); 654 scope->set_start_position(0);
653 scope->set_end_position(source->length()); 655 scope->set_end_position(source->length());
654 LexicalScope lexical_scope(this, scope, isolate()); 656 LexicalScope lexical_scope(this, scope, isolate());
655 ASSERT(top_scope_->strict_mode_flag() == kNonStrictMode); 657 ASSERT(top_scope_->language_mode() == CLASSIC_MODE);
656 top_scope_->SetStrictModeFlag(strict_mode); 658 top_scope_->SetLanguageMode(language_mode);
657 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); 659 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16);
658 bool ok = true; 660 bool ok = true;
659 int beg_loc = scanner().location().beg_pos; 661 int beg_loc = scanner().location().beg_pos;
660 ParseSourceElements(body, Token::EOS, &ok); 662 ParseSourceElements(body, Token::EOS, &ok);
661 if (ok && top_scope_->is_strict_mode()) { 663 if (ok && top_scope_->is_strict_or_extended_mode()) {
662 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); 664 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok);
663 } 665 }
664 666
665 if (ok && harmony_scoping_) { 667 if (ok && harmony_scoping_) {
666 CheckConflictingVarDeclarations(scope, &ok); 668 CheckConflictingVarDeclarations(scope, &ok);
667 } 669 }
668 670
669 if (ok) { 671 if (ok) {
670 result = new(zone()) FunctionLiteral( 672 result = new(zone()) FunctionLiteral(
671 isolate(), 673 isolate(),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 // Place holder for the result. 738 // Place holder for the result.
737 FunctionLiteral* result = NULL; 739 FunctionLiteral* result = NULL;
738 740
739 { 741 {
740 // Parse the function literal. 742 // Parse the function literal.
741 Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); 743 Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE);
742 if (!info->closure().is_null()) { 744 if (!info->closure().is_null()) {
743 scope = Scope::DeserializeScopeChain(info, scope); 745 scope = Scope::DeserializeScopeChain(info, scope);
744 } 746 }
745 LexicalScope lexical_scope(this, scope, isolate()); 747 LexicalScope lexical_scope(this, scope, isolate());
746 ASSERT(scope->strict_mode_flag() == kNonStrictMode || 748 ASSERT(scope->language_mode() != STRICT_MODE ||
747 scope->strict_mode_flag() == info->strict_mode_flag()); 749 info->is_strict_or_extended_mode());
748 ASSERT(info->strict_mode_flag() == shared_info->strict_mode_flag()); 750 ASSERT(scope->language_mode() != EXTENDED_MODE ||
749 scope->SetStrictModeFlag(shared_info->strict_mode_flag()); 751 info->is_extended_mode());
752 ASSERT(info->language_mode() == shared_info->language_mode());
753 scope->SetLanguageMode(shared_info->language_mode());
750 FunctionLiteral::Type type = shared_info->is_expression() 754 FunctionLiteral::Type type = shared_info->is_expression()
751 ? (shared_info->is_anonymous() 755 ? (shared_info->is_anonymous()
752 ? FunctionLiteral::ANONYMOUS_EXPRESSION 756 ? FunctionLiteral::ANONYMOUS_EXPRESSION
753 : FunctionLiteral::NAMED_EXPRESSION) 757 : FunctionLiteral::NAMED_EXPRESSION)
754 : FunctionLiteral::DECLARATION; 758 : FunctionLiteral::DECLARATION;
755 bool ok = true; 759 bool ok = true;
756 result = ParseFunctionLiteral(name, 760 result = ParseFunctionLiteral(name,
757 false, // Strict mode name already checked. 761 false, // Strict mode name already checked.
758 RelocInfo::kNoPosition, 762 RelocInfo::kNoPosition,
759 type, 763 type,
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 // A shot at a directive. 1186 // A shot at a directive.
1183 ExpressionStatement *e_stat; 1187 ExpressionStatement *e_stat;
1184 Literal *literal; 1188 Literal *literal;
1185 // Still processing directive prologue? 1189 // Still processing directive prologue?
1186 if ((e_stat = stat->AsExpressionStatement()) != NULL && 1190 if ((e_stat = stat->AsExpressionStatement()) != NULL &&
1187 (literal = e_stat->expression()->AsLiteral()) != NULL && 1191 (literal = e_stat->expression()->AsLiteral()) != NULL &&
1188 literal->handle()->IsString()) { 1192 literal->handle()->IsString()) {
1189 Handle<String> directive = Handle<String>::cast(literal->handle()); 1193 Handle<String> directive = Handle<String>::cast(literal->handle());
1190 1194
1191 // Check "use strict" directive (ES5 14.1). 1195 // Check "use strict" directive (ES5 14.1).
1192 if (!top_scope_->is_strict_mode() && 1196 if (!top_scope_->is_strict_or_extended_mode() &&
1193 directive->Equals(isolate()->heap()->use_strict()) && 1197 directive->Equals(isolate()->heap()->use_strict()) &&
1194 token_loc.end_pos - token_loc.beg_pos == 1198 token_loc.end_pos - token_loc.beg_pos ==
1195 isolate()->heap()->use_strict()->length() + 2) { 1199 isolate()->heap()->use_strict()->length() + 2) {
1196 top_scope_->SetStrictModeFlag(kStrictMode); 1200 top_scope_->SetLanguageMode(harmony_scoping_
1201 ? EXTENDED_MODE : STRICT_MODE);
1197 // "use strict" is the only directive for now. 1202 // "use strict" is the only directive for now.
1198 directive_prologue = false; 1203 directive_prologue = false;
1199 } 1204 }
1200 } else { 1205 } else {
1201 // End of the directive prologue. 1206 // End of the directive prologue.
1202 directive_prologue = false; 1207 directive_prologue = false;
1203 } 1208 }
1204 } 1209 }
1205 1210
1206 block_finder.Update(stat); 1211 block_finder.Update(stat);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 } 1329 }
1325 1330
1326 case Token::FUNCTION: { 1331 case Token::FUNCTION: {
1327 // FunctionDeclaration is only allowed in the context of SourceElements 1332 // FunctionDeclaration is only allowed in the context of SourceElements
1328 // (Ecma 262 5th Edition, clause 14): 1333 // (Ecma 262 5th Edition, clause 14):
1329 // SourceElement: 1334 // SourceElement:
1330 // Statement 1335 // Statement
1331 // FunctionDeclaration 1336 // FunctionDeclaration
1332 // Common language extension is to allow function declaration in place 1337 // Common language extension is to allow function declaration in place
1333 // of any statement. This language extension is disabled in strict mode. 1338 // of any statement. This language extension is disabled in strict mode.
1334 if (top_scope_->is_strict_mode() || harmony_scoping_) { 1339 if (top_scope_->is_strict_or_extended_mode()) {
1335 ReportMessageAt(scanner().peek_location(), "strict_function", 1340 ReportMessageAt(scanner().peek_location(), "strict_function",
1336 Vector<const char*>::empty()); 1341 Vector<const char*>::empty());
1337 *ok = false; 1342 *ok = false;
1338 return NULL; 1343 return NULL;
1339 } 1344 }
1340 return ParseFunctionDeclaration(ok); 1345 return ParseFunctionDeclaration(ok);
1341 } 1346 }
1342 1347
1343 case Token::DEBUGGER: 1348 case Token::DEBUGGER:
1344 stmt = ParseDebuggerStatement(ok); 1349 stmt = ParseDebuggerStatement(ok);
(...skipping 27 matching lines...) Expand all
1372 // variable and also set its mode. In any case, a Declaration node 1377 // variable and also set its mode. In any case, a Declaration node
1373 // will be added to the scope so that the declaration can be added 1378 // will be added to the scope so that the declaration can be added
1374 // to the corresponding activation frame at runtime if necessary. 1379 // to the corresponding activation frame at runtime if necessary.
1375 // For instance declarations inside an eval scope need to be added 1380 // For instance declarations inside an eval scope need to be added
1376 // to the calling function context. 1381 // to the calling function context.
1377 // Similarly, strict mode eval scope does not leak variable declarations to 1382 // Similarly, strict mode eval scope does not leak variable declarations to
1378 // the caller's scope so we declare all locals, too. 1383 // the caller's scope so we declare all locals, too.
1379 // Also for block scoped let/const bindings the variable can be 1384 // Also for block scoped let/const bindings the variable can be
1380 // statically declared. 1385 // statically declared.
1381 if (declaration_scope->is_function_scope() || 1386 if (declaration_scope->is_function_scope() ||
1382 declaration_scope->is_strict_mode_eval_scope() || 1387 declaration_scope->is_strict_or_extended_eval_scope() ||
1383 declaration_scope->is_block_scope()) { 1388 declaration_scope->is_block_scope()) {
1384 // Declare the variable in the function scope. 1389 // Declare the variable in the function scope.
1385 var = declaration_scope->LocalLookup(name); 1390 var = declaration_scope->LocalLookup(name);
1386 if (var == NULL) { 1391 if (var == NULL) {
1387 // Declare the name. 1392 // Declare the name.
1388 InitializationFlag init_flag = (fun != NULL || mode == VAR) 1393 InitializationFlag init_flag = (fun != NULL || mode == VAR)
1389 ? kCreatedInitialized : kNeedsInitialization; 1394 ? kCreatedInitialized : kNeedsInitialization;
1390 var = declaration_scope->DeclareLocal(name, mode, init_flag); 1395 var = declaration_scope->DeclareLocal(name, mode, init_flag);
1391 } else { 1396 } else {
1392 // The name was declared in this scope before; check for conflicting 1397 // The name was declared in this scope before; check for conflicting
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 // Even if we're not at the top-level of the global or a function 1569 // Even if we're not at the top-level of the global or a function
1565 // scope, we treat is as such and introduce the function with it's 1570 // scope, we treat is as such and introduce the function with it's
1566 // initial value upon entering the corresponding scope. 1571 // initial value upon entering the corresponding scope.
1567 VariableMode mode = harmony_scoping_ ? LET : VAR; 1572 VariableMode mode = harmony_scoping_ ? LET : VAR;
1568 Declare(name, mode, fun, true, CHECK_OK); 1573 Declare(name, mode, fun, true, CHECK_OK);
1569 return EmptyStatement(); 1574 return EmptyStatement();
1570 } 1575 }
1571 1576
1572 1577
1573 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1578 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
1574 if (harmony_scoping_) return ParseScopedBlock(labels, ok); 1579 if (top_scope_->is_extended_mode()) return ParseScopedBlock(labels, ok);
1575 1580
1576 // Block :: 1581 // Block ::
1577 // '{' Statement* '}' 1582 // '{' Statement* '}'
1578 1583
1579 // Note that a Block does not introduce a new execution scope! 1584 // Note that a Block does not introduce a new execution scope!
1580 // (ECMA-262, 3rd, 12.2) 1585 // (ECMA-262, 3rd, 12.2)
1581 // 1586 //
1582 // Construct block expecting 16 statements. 1587 // Construct block expecting 16 statements.
1583 Block* result = new(zone()) Block(isolate(), labels, 16, false); 1588 Block* result = new(zone()) Block(isolate(), labels, 16, false);
1584 Target target(&this->target_stack_, result); 1589 Target target(&this->target_stack_, result);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 // bindings are created uninitialized by their declaration nodes and 1685 // bindings are created uninitialized by their declaration nodes and
1681 // need initialization. 'var' declared bindings are always initialized 1686 // need initialization. 'var' declared bindings are always initialized
1682 // immediately by their declaration nodes. 1687 // immediately by their declaration nodes.
1683 bool needs_init = false; 1688 bool needs_init = false;
1684 bool is_const = false; 1689 bool is_const = false;
1685 Token::Value init_op = Token::INIT_VAR; 1690 Token::Value init_op = Token::INIT_VAR;
1686 if (peek() == Token::VAR) { 1691 if (peek() == Token::VAR) {
1687 Consume(Token::VAR); 1692 Consume(Token::VAR);
1688 } else if (peek() == Token::CONST) { 1693 } else if (peek() == Token::CONST) {
1689 Consume(Token::CONST); 1694 Consume(Token::CONST);
1690 if (harmony_scoping_) { 1695 switch (top_scope_->language_mode()) {
1691 if (var_context != kSourceElement && 1696 case CLASSIC_MODE:
1692 var_context != kForStatement) { 1697 mode = CONST;
1693 // In harmony mode 'const' declarations are only allowed in source 1698 init_op = Token::INIT_CONST;
1694 // element positions. 1699 break;
1695 ReportMessage("unprotected_const", Vector<const char*>::empty()); 1700 case STRICT_MODE:
1701 ReportMessage("strict_const", Vector<const char*>::empty());
1696 *ok = false; 1702 *ok = false;
1697 return NULL; 1703 return NULL;
1698 } 1704 case EXTENDED_MODE:
1699 mode = CONST_HARMONY; 1705 if (var_context != kSourceElement &&
1700 init_op = Token::INIT_CONST_HARMONY; 1706 var_context != kForStatement) {
1701 } else if (top_scope_->is_strict_mode()) { 1707 // In extended mode 'const' declarations are only allowed in source
1702 ReportMessage("strict_const", Vector<const char*>::empty()); 1708 // element positions.
1703 *ok = false; 1709 ReportMessage("unprotected_const", Vector<const char*>::empty());
1704 return NULL; 1710 *ok = false;
1705 } else { 1711 return NULL;
1706 mode = CONST; 1712 }
1707 init_op = Token::INIT_CONST; 1713 mode = CONST_HARMONY;
1714 init_op = Token::INIT_CONST_HARMONY;
1708 } 1715 }
1709 is_const = true; 1716 is_const = true;
1710 needs_init = true; 1717 needs_init = true;
1711 } else if (peek() == Token::LET) { 1718 } else if (peek() == Token::LET) {
1719 ASSERT(top_scope_->is_extended_mode());
1712 Consume(Token::LET); 1720 Consume(Token::LET);
1713 if (var_context != kSourceElement && 1721 if (var_context != kSourceElement &&
1714 var_context != kForStatement) { 1722 var_context != kForStatement) {
1715 // Let declarations are only allowed in source element positions. 1723 // Let declarations are only allowed in source element positions.
1716 ASSERT(var_context == kStatement); 1724 ASSERT(var_context == kStatement);
1717 ReportMessage("unprotected_let", Vector<const char*>::empty()); 1725 ReportMessage("unprotected_let", Vector<const char*>::empty());
1718 *ok = false; 1726 *ok = false;
1719 return NULL; 1727 return NULL;
1720 } 1728 }
1721 mode = LET; 1729 mode = LET;
(...skipping 23 matching lines...) Expand all
1745 Handle<String> name; 1753 Handle<String> name;
1746 do { 1754 do {
1747 if (fni_ != NULL) fni_->Enter(); 1755 if (fni_ != NULL) fni_->Enter();
1748 1756
1749 // Parse variable name. 1757 // Parse variable name.
1750 if (nvars > 0) Consume(Token::COMMA); 1758 if (nvars > 0) Consume(Token::COMMA);
1751 name = ParseIdentifier(CHECK_OK); 1759 name = ParseIdentifier(CHECK_OK);
1752 if (fni_ != NULL) fni_->PushVariableName(name); 1760 if (fni_ != NULL) fni_->PushVariableName(name);
1753 1761
1754 // Strict mode variables may not be named eval or arguments 1762 // Strict mode variables may not be named eval or arguments
1755 if (declaration_scope->is_strict_mode() && IsEvalOrArguments(name)) { 1763 if (declaration_scope->is_strict_or_extended_mode() &&
1764 IsEvalOrArguments(name)) {
1756 ReportMessage("strict_var_name", Vector<const char*>::empty()); 1765 ReportMessage("strict_var_name", Vector<const char*>::empty());
1757 *ok = false; 1766 *ok = false;
1758 return NULL; 1767 return NULL;
1759 } 1768 }
1760 1769
1761 // Declare variable. 1770 // Declare variable.
1762 // Note that we *always* must treat the initial value via a separate init 1771 // Note that we *always* must treat the initial value via a separate init
1763 // assignment for variables and constants because the value must be assigned 1772 // assignment for variables and constants because the value must be assigned
1764 // when the variable is encountered in the source. But the variable/constant 1773 // when the variable is encountered in the source. But the variable/constant
1765 // is declared (and set to 'undefined') upon entering the function within 1774 // is declared (and set to 'undefined') upon entering the function within
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 // the number of arguments (1 or 2). 1883 // the number of arguments (1 or 2).
1875 initialize = 1884 initialize =
1876 new(zone()) CallRuntime( 1885 new(zone()) CallRuntime(
1877 isolate(), 1886 isolate(),
1878 isolate()->factory()->InitializeConstGlobal_symbol(), 1887 isolate()->factory()->InitializeConstGlobal_symbol(),
1879 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), 1888 Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
1880 arguments); 1889 arguments);
1881 } else { 1890 } else {
1882 // Add strict mode. 1891 // Add strict mode.
1883 // We may want to pass singleton to avoid Literal allocations. 1892 // We may want to pass singleton to avoid Literal allocations.
1884 StrictModeFlag flag = initialization_scope->strict_mode_flag(); 1893 LanguageMode language_mode = initialization_scope->language_mode();
1885 arguments->Add(NewNumberLiteral(flag)); 1894 arguments->Add(NewNumberLiteral(language_mode));
1886 1895
1887 // Be careful not to assign a value to the global variable if 1896 // Be careful not to assign a value to the global variable if
1888 // we're in a with. The initialization value should not 1897 // we're in a with. The initialization value should not
1889 // necessarily be stored in the global object in that case, 1898 // necessarily be stored in the global object in that case,
1890 // which is why we need to generate a separate assignment node. 1899 // which is why we need to generate a separate assignment node.
1891 if (value != NULL && !inside_with()) { 1900 if (value != NULL && !inside_with()) {
1892 arguments->Add(value); 1901 arguments->Add(value);
1893 value = NULL; // zap the value to avoid the unnecessary assignment 1902 value = NULL; // zap the value to avoid the unnecessary assignment
1894 } 1903 }
1895 1904
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 return new(zone()) ReturnStatement(expr); 2140 return new(zone()) ReturnStatement(expr);
2132 } 2141 }
2133 2142
2134 2143
2135 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { 2144 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) {
2136 // WithStatement :: 2145 // WithStatement ::
2137 // 'with' '(' Expression ')' Statement 2146 // 'with' '(' Expression ')' Statement
2138 2147
2139 Expect(Token::WITH, CHECK_OK); 2148 Expect(Token::WITH, CHECK_OK);
2140 2149
2141 if (top_scope_->is_strict_mode()) { 2150 if (top_scope_->is_strict_or_extended_mode()) {
2142 ReportMessage("strict_mode_with", Vector<const char*>::empty()); 2151 ReportMessage("strict_mode_with", Vector<const char*>::empty());
2143 *ok = false; 2152 *ok = false;
2144 return NULL; 2153 return NULL;
2145 } 2154 }
2146 2155
2147 Expect(Token::LPAREN, CHECK_OK); 2156 Expect(Token::LPAREN, CHECK_OK);
2148 Expression* expr = ParseExpression(true, CHECK_OK); 2157 Expression* expr = ParseExpression(true, CHECK_OK);
2149 Expect(Token::RPAREN, CHECK_OK); 2158 Expect(Token::RPAREN, CHECK_OK);
2150 2159
2151 top_scope_->DeclarationScope()->RecordWithStatement(); 2160 top_scope_->DeclarationScope()->RecordWithStatement();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 Block* catch_block = NULL; 2286 Block* catch_block = NULL;
2278 Handle<String> name; 2287 Handle<String> name;
2279 if (tok == Token::CATCH) { 2288 if (tok == Token::CATCH) {
2280 Consume(Token::CATCH); 2289 Consume(Token::CATCH);
2281 2290
2282 Expect(Token::LPAREN, CHECK_OK); 2291 Expect(Token::LPAREN, CHECK_OK);
2283 catch_scope = NewScope(top_scope_, CATCH_SCOPE); 2292 catch_scope = NewScope(top_scope_, CATCH_SCOPE);
2284 catch_scope->set_start_position(scanner().location().beg_pos); 2293 catch_scope->set_start_position(scanner().location().beg_pos);
2285 name = ParseIdentifier(CHECK_OK); 2294 name = ParseIdentifier(CHECK_OK);
2286 2295
2287 if (top_scope_->is_strict_mode() && IsEvalOrArguments(name)) { 2296 if (top_scope_->is_strict_or_extended_mode() && IsEvalOrArguments(name)) {
2288 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); 2297 ReportMessage("strict_catch_variable", Vector<const char*>::empty());
2289 *ok = false; 2298 *ok = false;
2290 return NULL; 2299 return NULL;
2291 } 2300 }
2292 2301
2293 Expect(Token::RPAREN, CHECK_OK); 2302 Expect(Token::RPAREN, CHECK_OK);
2294 2303
2295 if (peek() == Token::LBRACE) { 2304 if (peek() == Token::LBRACE) {
2296 Target target(&this->target_stack_, &catch_collector); 2305 Target target(&this->target_stack_, &catch_collector);
2297 VariableMode mode = harmony_scoping_ ? LET : VAR; 2306 VariableMode mode = harmony_scoping_ ? LET : VAR;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
2623 // Signal a reference error if the expression is an invalid left-hand 2632 // Signal a reference error if the expression is an invalid left-hand
2624 // side expression. We could report this as a syntax error here but 2633 // side expression. We could report this as a syntax error here but
2625 // for compatibility with JSC we choose to report the error at 2634 // for compatibility with JSC we choose to report the error at
2626 // runtime. 2635 // runtime.
2627 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2636 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2628 Handle<String> type = 2637 Handle<String> type =
2629 isolate()->factory()->invalid_lhs_in_assignment_symbol(); 2638 isolate()->factory()->invalid_lhs_in_assignment_symbol();
2630 expression = NewThrowReferenceError(type); 2639 expression = NewThrowReferenceError(type);
2631 } 2640 }
2632 2641
2633 if (top_scope_->is_strict_mode()) { 2642 if (top_scope_->is_strict_or_extended_mode()) {
2634 // Assignment to eval or arguments is disallowed in strict mode. 2643 // Assignment to eval or arguments is disallowed in strict mode.
2635 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK); 2644 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK);
2636 } 2645 }
2637 2646
2638 Token::Value op = Next(); // Get assignment operator. 2647 Token::Value op = Next(); // Get assignment operator.
2639 int pos = scanner().location().beg_pos; 2648 int pos = scanner().location().beg_pos;
2640 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2649 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2641 2650
2642 // TODO(1231235): We try to estimate the set of properties set by 2651 // TODO(1231235): We try to estimate the set of properties set by
2643 // constructors. We define a new property whenever there is an 2652 // constructors. We define a new property whenever there is an
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2832 return NewNumberLiteral(-value); 2841 return NewNumberLiteral(-value);
2833 case Token::BIT_NOT: 2842 case Token::BIT_NOT:
2834 return NewNumberLiteral(~DoubleToInt32(value)); 2843 return NewNumberLiteral(~DoubleToInt32(value));
2835 default: 2844 default:
2836 break; 2845 break;
2837 } 2846 }
2838 } 2847 }
2839 } 2848 }
2840 2849
2841 // "delete identifier" is a syntax error in strict mode. 2850 // "delete identifier" is a syntax error in strict mode.
2842 if (op == Token::DELETE && top_scope_->is_strict_mode()) { 2851 if (op == Token::DELETE && top_scope_->is_strict_or_extended_mode()) {
2843 VariableProxy* operand = expression->AsVariableProxy(); 2852 VariableProxy* operand = expression->AsVariableProxy();
2844 if (operand != NULL && !operand->is_this()) { 2853 if (operand != NULL && !operand->is_this()) {
2845 ReportMessage("strict_delete", Vector<const char*>::empty()); 2854 ReportMessage("strict_delete", Vector<const char*>::empty());
2846 *ok = false; 2855 *ok = false;
2847 return NULL; 2856 return NULL;
2848 } 2857 }
2849 } 2858 }
2850 2859
2851 return new(zone()) UnaryOperation(isolate(), op, expression, position); 2860 return new(zone()) UnaryOperation(isolate(), op, expression, position);
2852 2861
2853 } else if (Token::IsCountOp(op)) { 2862 } else if (Token::IsCountOp(op)) {
2854 op = Next(); 2863 op = Next();
2855 Expression* expression = ParseUnaryExpression(CHECK_OK); 2864 Expression* expression = ParseUnaryExpression(CHECK_OK);
2856 // Signal a reference error if the expression is an invalid 2865 // Signal a reference error if the expression is an invalid
2857 // left-hand side expression. We could report this as a syntax 2866 // left-hand side expression. We could report this as a syntax
2858 // error here but for compatibility with JSC we choose to report the 2867 // error here but for compatibility with JSC we choose to report the
2859 // error at runtime. 2868 // error at runtime.
2860 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2869 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2861 Handle<String> type = 2870 Handle<String> type =
2862 isolate()->factory()->invalid_lhs_in_prefix_op_symbol(); 2871 isolate()->factory()->invalid_lhs_in_prefix_op_symbol();
2863 expression = NewThrowReferenceError(type); 2872 expression = NewThrowReferenceError(type);
2864 } 2873 }
2865 2874
2866 if (top_scope_->is_strict_mode()) { 2875 if (top_scope_->is_strict_or_extended_mode()) {
2867 // Prefix expression operand in strict mode may not be eval or arguments. 2876 // Prefix expression operand in strict mode may not be eval or arguments.
2868 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); 2877 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2869 } 2878 }
2870 2879
2871 int position = scanner().location().beg_pos; 2880 int position = scanner().location().beg_pos;
2872 return new(zone()) CountOperation(isolate(), 2881 return new(zone()) CountOperation(isolate(),
2873 op, 2882 op,
2874 true /* prefix */, 2883 true /* prefix */,
2875 expression, 2884 expression,
2876 position); 2885 position);
(...skipping 14 matching lines...) Expand all
2891 // Signal a reference error if the expression is an invalid 2900 // Signal a reference error if the expression is an invalid
2892 // left-hand side expression. We could report this as a syntax 2901 // left-hand side expression. We could report this as a syntax
2893 // error here but for compatibility with JSC we choose to report the 2902 // error here but for compatibility with JSC we choose to report the
2894 // error at runtime. 2903 // error at runtime.
2895 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2904 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2896 Handle<String> type = 2905 Handle<String> type =
2897 isolate()->factory()->invalid_lhs_in_postfix_op_symbol(); 2906 isolate()->factory()->invalid_lhs_in_postfix_op_symbol();
2898 expression = NewThrowReferenceError(type); 2907 expression = NewThrowReferenceError(type);
2899 } 2908 }
2900 2909
2901 if (top_scope_->is_strict_mode()) { 2910 if (top_scope_->is_strict_or_extended_mode()) {
2902 // Postfix expression operand in strict mode may not be eval or arguments. 2911 // Postfix expression operand in strict mode may not be eval or arguments.
2903 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); 2912 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2904 } 2913 }
2905 2914
2906 Token::Value next = Next(); 2915 Token::Value next = Next();
2907 int position = scanner().location().beg_pos; 2916 int position = scanner().location().beg_pos;
2908 expression = 2917 expression =
2909 new(zone()) CountOperation(isolate(), 2918 new(zone()) CountOperation(isolate(),
2910 next, 2919 next,
2911 false /* postfix */, 2920 false /* postfix */,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
3122 case Token::STRING: 3131 case Token::STRING:
3123 return ReportMessage("unexpected_token_string", 3132 return ReportMessage("unexpected_token_string",
3124 Vector<const char*>::empty()); 3133 Vector<const char*>::empty());
3125 case Token::IDENTIFIER: 3134 case Token::IDENTIFIER:
3126 return ReportMessage("unexpected_token_identifier", 3135 return ReportMessage("unexpected_token_identifier",
3127 Vector<const char*>::empty()); 3136 Vector<const char*>::empty());
3128 case Token::FUTURE_RESERVED_WORD: 3137 case Token::FUTURE_RESERVED_WORD:
3129 return ReportMessage("unexpected_reserved", 3138 return ReportMessage("unexpected_reserved",
3130 Vector<const char*>::empty()); 3139 Vector<const char*>::empty());
3131 case Token::FUTURE_STRICT_RESERVED_WORD: 3140 case Token::FUTURE_STRICT_RESERVED_WORD:
3132 return ReportMessage(top_scope_->is_strict_mode() ? 3141 return ReportMessage(top_scope_->is_strict_or_extended_mode() ?
3133 "unexpected_strict_reserved" : 3142 "unexpected_strict_reserved" :
3134 "unexpected_token_identifier", 3143 "unexpected_token_identifier",
3135 Vector<const char*>::empty()); 3144 Vector<const char*>::empty());
3136 default: 3145 default:
3137 const char* name = Token::String(token); 3146 const char* name = Token::String(token);
3138 ASSERT(name != NULL); 3147 ASSERT(name != NULL);
3139 ReportMessage("unexpected_token", Vector<const char*>(&name, 1)); 3148 ReportMessage("unexpected_token", Vector<const char*>(&name, 1));
3140 } 3149 }
3141 } 3150 }
3142 3151
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
3690 // '{' ( 3699 // '{' (
3691 // ((IdentifierName | String | Number) ':' AssignmentExpression) 3700 // ((IdentifierName | String | Number) ':' AssignmentExpression)
3692 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) 3701 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
3693 // )*[','] '}' 3702 // )*[','] '}'
3694 3703
3695 ZoneList<ObjectLiteral::Property*>* properties = 3704 ZoneList<ObjectLiteral::Property*>* properties =
3696 new(zone()) ZoneList<ObjectLiteral::Property*>(4); 3705 new(zone()) ZoneList<ObjectLiteral::Property*>(4);
3697 int number_of_boilerplate_properties = 0; 3706 int number_of_boilerplate_properties = 0;
3698 bool has_function = false; 3707 bool has_function = false;
3699 3708
3700 ObjectLiteralPropertyChecker checker(this, top_scope_->is_strict_mode()); 3709 ObjectLiteralPropertyChecker checker(
3710 this, top_scope_->is_strict_or_extended_mode());
3701 3711
3702 Expect(Token::LBRACE, CHECK_OK); 3712 Expect(Token::LBRACE, CHECK_OK);
3703 3713
3704 while (peek() != Token::RBRACE) { 3714 while (peek() != Token::RBRACE) {
3705 if (fni_ != NULL) fni_->Enter(); 3715 if (fni_ != NULL) fni_->Enter();
3706 3716
3707 Literal* key = NULL; 3717 Literal* key = NULL;
3708 Token::Value next = peek(); 3718 Token::Value next = peek();
3709 3719
3710 // Location of the property name token 3720 // Location of the property name token
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
4003 if (scope->end_position() <= function_block_pos) { 4013 if (scope->end_position() <= function_block_pos) {
4004 // End position greater than end of stream is safe, and hard to check. 4014 // End position greater than end of stream is safe, and hard to check.
4005 ReportInvalidPreparseData(function_name, CHECK_OK); 4015 ReportInvalidPreparseData(function_name, CHECK_OK);
4006 } 4016 }
4007 isolate()->counters()->total_preparse_skipped()->Increment( 4017 isolate()->counters()->total_preparse_skipped()->Increment(
4008 scope->end_position() - function_block_pos); 4018 scope->end_position() - function_block_pos);
4009 // Seek to position just before terminal '}'. 4019 // Seek to position just before terminal '}'.
4010 scanner().SeekForward(scope->end_position() - 1); 4020 scanner().SeekForward(scope->end_position() - 1);
4011 materialized_literal_count = entry.literal_count(); 4021 materialized_literal_count = entry.literal_count();
4012 expected_property_count = entry.property_count(); 4022 expected_property_count = entry.property_count();
4013 top_scope_->SetStrictModeFlag(entry.strict_mode_flag()); 4023 top_scope_->SetLanguageMode(entry.language_mode());
4014 only_simple_this_property_assignments = false; 4024 only_simple_this_property_assignments = false;
4015 this_property_assignments = isolate()->factory()->empty_fixed_array(); 4025 this_property_assignments = isolate()->factory()->empty_fixed_array();
4016 Expect(Token::RBRACE, CHECK_OK); 4026 Expect(Token::RBRACE, CHECK_OK);
4017 } 4027 }
4018 } 4028 }
4019 4029
4020 if (!is_lazily_compiled) { 4030 if (!is_lazily_compiled) {
4021 ParseSourceElements(body, Token::RBRACE, CHECK_OK); 4031 ParseSourceElements(body, Token::RBRACE, CHECK_OK);
4022 4032
4023 materialized_literal_count = lexical_scope.materialized_literal_count(); 4033 materialized_literal_count = lexical_scope.materialized_literal_count();
4024 expected_property_count = lexical_scope.expected_property_count(); 4034 expected_property_count = lexical_scope.expected_property_count();
4025 only_simple_this_property_assignments = 4035 only_simple_this_property_assignments =
4026 lexical_scope.only_simple_this_property_assignments(); 4036 lexical_scope.only_simple_this_property_assignments();
4027 this_property_assignments = lexical_scope.this_property_assignments(); 4037 this_property_assignments = lexical_scope.this_property_assignments();
4028 4038
4029 Expect(Token::RBRACE, CHECK_OK); 4039 Expect(Token::RBRACE, CHECK_OK);
4030 scope->set_end_position(scanner().location().end_pos); 4040 scope->set_end_position(scanner().location().end_pos);
4031 } 4041 }
4032 4042
4033 // Validate strict mode. 4043 // Validate strict mode.
4034 if (top_scope_->is_strict_mode()) { 4044 if (top_scope_->is_strict_or_extended_mode()) {
4035 if (IsEvalOrArguments(function_name)) { 4045 if (IsEvalOrArguments(function_name)) {
4036 int start_pos = scope->start_position(); 4046 int start_pos = scope->start_position();
4037 int position = function_token_position != RelocInfo::kNoPosition 4047 int position = function_token_position != RelocInfo::kNoPosition
4038 ? function_token_position 4048 ? function_token_position
4039 : (start_pos > 0 ? start_pos - 1 : start_pos); 4049 : (start_pos > 0 ? start_pos - 1 : start_pos);
4040 Scanner::Location location = Scanner::Location(position, start_pos); 4050 Scanner::Location location = Scanner::Location(position, start_pos);
4041 ReportMessageAt(location, 4051 ReportMessageAt(location,
4042 "strict_function_name", Vector<const char*>::empty()); 4052 "strict_function_name", Vector<const char*>::empty());
4043 *ok = false; 4053 *ok = false;
4044 return NULL; 4054 return NULL;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
4209 4219
4210 4220
4211 Literal* Parser::GetLiteralNumber(double value) { 4221 Literal* Parser::GetLiteralNumber(double value) {
4212 return NewNumberLiteral(value); 4222 return NewNumberLiteral(value);
4213 } 4223 }
4214 4224
4215 4225
4216 // Parses an identifier that is valid for the current scope, in particular it 4226 // Parses an identifier that is valid for the current scope, in particular it
4217 // fails on strict mode future reserved keywords in a strict scope. 4227 // fails on strict mode future reserved keywords in a strict scope.
4218 Handle<String> Parser::ParseIdentifier(bool* ok) { 4228 Handle<String> Parser::ParseIdentifier(bool* ok) {
4219 if (top_scope_->is_strict_mode()) { 4229 if (top_scope_->is_strict_or_extended_mode()) {
4220 Expect(Token::IDENTIFIER, ok); 4230 Expect(Token::IDENTIFIER, ok);
4221 } else if (!Check(Token::IDENTIFIER)) { 4231 } else if (!Check(Token::IDENTIFIER)) {
4222 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok); 4232 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok);
4223 } 4233 }
4224 if (!*ok) return Handle<String>(); 4234 if (!*ok) return Handle<String>();
4225 return GetSymbol(ok); 4235 return GetSymbol(ok);
4226 } 4236 }
4227 4237
4228 4238
4229 // Parses and identifier or a strict mode future reserved word, and indicate 4239 // Parses and identifier or a strict mode future reserved word, and indicate
(...skipping 22 matching lines...) Expand all
4252 } 4262 }
4253 return GetSymbol(ok); 4263 return GetSymbol(ok);
4254 } 4264 }
4255 4265
4256 4266
4257 // Checks LHS expression for assignment and prefix/postfix increment/decrement 4267 // Checks LHS expression for assignment and prefix/postfix increment/decrement
4258 // in strict mode. 4268 // in strict mode.
4259 void Parser::CheckStrictModeLValue(Expression* expression, 4269 void Parser::CheckStrictModeLValue(Expression* expression,
4260 const char* error, 4270 const char* error,
4261 bool* ok) { 4271 bool* ok) {
4262 ASSERT(top_scope_->is_strict_mode()); 4272 ASSERT(top_scope_->is_strict_or_extended_mode());
4263 VariableProxy* lhs = expression != NULL 4273 VariableProxy* lhs = expression != NULL
4264 ? expression->AsVariableProxy() 4274 ? expression->AsVariableProxy()
4265 : NULL; 4275 : NULL;
4266 4276
4267 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) { 4277 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) {
4268 ReportMessage(error, Vector<const char*>::empty()); 4278 ReportMessage(error, Vector<const char*>::empty());
4269 *ok = false; 4279 *ok = false;
4270 } 4280 }
4271 } 4281 }
4272 4282
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
5415 DeleteArray(message); 5425 DeleteArray(message);
5416 for (int i = 0; i < args.length(); i++) { 5426 for (int i = 0; i < args.length(); i++) {
5417 DeleteArray(args[i]); 5427 DeleteArray(args[i]);
5418 } 5428 }
5419 DeleteArray(args.start()); 5429 DeleteArray(args.start());
5420 ASSERT(info->isolate()->has_pending_exception()); 5430 ASSERT(info->isolate()->has_pending_exception());
5421 } else { 5431 } else {
5422 Handle<String> source = Handle<String>(String::cast(script->source())); 5432 Handle<String> source = Handle<String>(String::cast(script->source()));
5423 result = parser.ParseProgram(source, 5433 result = parser.ParseProgram(source,
5424 info->is_global(), 5434 info->is_global(),
5425 info->strict_mode_flag()); 5435 info->language_mode());
5426 } 5436 }
5427 } 5437 }
5428 info->SetFunction(result); 5438 info->SetFunction(result);
5429 return (result != NULL); 5439 return (result != NULL);
5430 } 5440 }
5431 5441
5432 } } // namespace v8::internal 5442 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698