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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 Handle<String> no_name = isolate()->factory()->empty_string(); | 675 Handle<String> no_name = isolate()->factory()->empty_string(); |
676 | 676 |
677 FunctionLiteral* result = NULL; | 677 FunctionLiteral* result = NULL; |
678 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE); | 678 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE); |
679 info->SetGlobalScope(scope); | 679 info->SetGlobalScope(scope); |
680 if (!info->context().is_null()) { | 680 if (!info->context().is_null()) { |
681 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); | 681 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); |
682 } | 682 } |
683 original_scope_ = scope; | 683 original_scope_ = scope; |
684 if (info->is_eval()) { | 684 if (info->is_eval()) { |
685 if (!scope->is_global_scope() || info->language_mode() != SLOPPY_MODE) { | 685 if (!scope->is_global_scope() || info->strict_mode() == STRICT) { |
686 scope = NewScope(scope, EVAL_SCOPE); | 686 scope = NewScope(scope, EVAL_SCOPE); |
687 } | 687 } |
688 } else if (info->is_global()) { | 688 } else if (info->is_global()) { |
689 scope = NewScope(scope, GLOBAL_SCOPE); | 689 scope = NewScope(scope, GLOBAL_SCOPE); |
690 } | 690 } |
691 scope->set_start_position(0); | 691 scope->set_start_position(0); |
692 scope->set_end_position(source->length()); | 692 scope->set_end_position(source->length()); |
693 | 693 |
694 // Compute the parsing mode. | 694 // Compute the parsing mode. |
695 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; | 695 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; |
696 if (allow_natives_syntax() || | 696 if (allow_natives_syntax() || |
697 extension_ != NULL || | 697 extension_ != NULL || |
698 scope->is_eval_scope()) { | 698 scope->is_eval_scope()) { |
699 mode = PARSE_EAGERLY; | 699 mode = PARSE_EAGERLY; |
700 } | 700 } |
701 ParsingModeScope parsing_mode(this, mode); | 701 ParsingModeScope parsing_mode(this, mode); |
702 | 702 |
703 // Enters 'scope'. | 703 // Enters 'scope'. |
704 FunctionState function_state(&function_state_, &scope_, scope, zone()); | 704 FunctionState function_state(&function_state_, &scope_, scope, zone()); |
705 | 705 |
706 scope_->SetLanguageMode(info->language_mode()); | 706 scope_->SetStrictMode(info->strict_mode()); |
707 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 707 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
708 bool ok = true; | 708 bool ok = true; |
709 int beg_pos = scanner()->location().beg_pos; | 709 int beg_pos = scanner()->location().beg_pos; |
710 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); | 710 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); |
711 if (ok && !scope_->is_sloppy_mode()) { | 711 if (ok && strict_mode() == STRICT) { |
712 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); | 712 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); |
713 } | 713 } |
714 | 714 |
715 if (ok && is_extended_mode()) { | 715 if (ok && FLAG_harmony_scoping && strict_mode() == STRICT) { |
716 CheckConflictingVarDeclarations(scope_, &ok); | 716 CheckConflictingVarDeclarations(scope_, &ok); |
717 } | 717 } |
718 | 718 |
719 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { | 719 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { |
720 if (body->length() != 1 || | 720 if (body->length() != 1 || |
721 !body->at(0)->IsExpressionStatement() || | 721 !body->at(0)->IsExpressionStatement() || |
722 !body->at(0)->AsExpressionStatement()-> | 722 !body->at(0)->AsExpressionStatement()-> |
723 expression()->IsFunctionLiteral()) { | 723 expression()->IsFunctionLiteral()) { |
724 ReportMessage("single_function_literal", Vector<const char*>::empty()); | 724 ReportMessage("single_function_literal", Vector<const char*>::empty()); |
725 ok = false; | 725 ok = false; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 { | 810 { |
811 // Parse the function literal. | 811 // Parse the function literal. |
812 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); | 812 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); |
813 info()->SetGlobalScope(scope); | 813 info()->SetGlobalScope(scope); |
814 if (!info()->closure().is_null()) { | 814 if (!info()->closure().is_null()) { |
815 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, | 815 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, |
816 zone()); | 816 zone()); |
817 } | 817 } |
818 original_scope_ = scope; | 818 original_scope_ = scope; |
819 FunctionState function_state(&function_state_, &scope_, scope, zone()); | 819 FunctionState function_state(&function_state_, &scope_, scope, zone()); |
820 ASSERT(scope->language_mode() != STRICT_MODE || !info()->is_sloppy_mode()); | 820 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); |
821 ASSERT(scope->language_mode() != EXTENDED_MODE || | 821 ASSERT(info()->strict_mode() == shared_info->strict_mode()); |
822 info()->is_extended_mode()); | 822 scope->SetStrictMode(shared_info->strict_mode()); |
823 ASSERT(info()->language_mode() == shared_info->language_mode()); | |
824 scope->SetLanguageMode(shared_info->language_mode()); | |
825 FunctionLiteral::FunctionType function_type = shared_info->is_expression() | 823 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
826 ? (shared_info->is_anonymous() | 824 ? (shared_info->is_anonymous() |
827 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 825 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
828 : FunctionLiteral::NAMED_EXPRESSION) | 826 : FunctionLiteral::NAMED_EXPRESSION) |
829 : FunctionLiteral::DECLARATION; | 827 : FunctionLiteral::DECLARATION; |
830 bool ok = true; | 828 bool ok = true; |
831 result = ParseFunctionLiteral(name, | 829 result = ParseFunctionLiteral(name, |
832 Scanner::Location::invalid(), | 830 Scanner::Location::invalid(), |
833 false, // Strict mode name already checked. | 831 false, // Strict mode name already checked. |
834 shared_info->is_generator(), | 832 shared_info->is_generator(), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 // A shot at a directive. | 888 // A shot at a directive. |
891 ExpressionStatement* e_stat; | 889 ExpressionStatement* e_stat; |
892 Literal* literal; | 890 Literal* literal; |
893 // Still processing directive prologue? | 891 // Still processing directive prologue? |
894 if ((e_stat = stat->AsExpressionStatement()) != NULL && | 892 if ((e_stat = stat->AsExpressionStatement()) != NULL && |
895 (literal = e_stat->expression()->AsLiteral()) != NULL && | 893 (literal = e_stat->expression()->AsLiteral()) != NULL && |
896 literal->value()->IsString()) { | 894 literal->value()->IsString()) { |
897 Handle<String> directive = Handle<String>::cast(literal->value()); | 895 Handle<String> directive = Handle<String>::cast(literal->value()); |
898 | 896 |
899 // Check "use strict" directive (ES5 14.1). | 897 // Check "use strict" directive (ES5 14.1). |
900 if (scope_->is_sloppy_mode() && | 898 if (strict_mode() == SLOPPY && |
901 directive->Equals(isolate()->heap()->use_strict_string()) && | 899 directive->Equals(isolate()->heap()->use_strict_string()) && |
902 token_loc.end_pos - token_loc.beg_pos == | 900 token_loc.end_pos - token_loc.beg_pos == |
903 isolate()->heap()->use_strict_string()->length() + 2) { | 901 isolate()->heap()->use_strict_string()->length() + 2) { |
904 // TODO(mstarzinger): Global strict eval calls, need their own scope | 902 // TODO(mstarzinger): Global strict eval calls, need their own scope |
905 // as specified in ES5 10.4.2(3). The correct fix would be to always | 903 // as specified in ES5 10.4.2(3). The correct fix would be to always |
906 // add this scope in DoParseProgram(), but that requires adaptations | 904 // add this scope in DoParseProgram(), but that requires adaptations |
907 // all over the code base, so we go with a quick-fix for now. | 905 // all over the code base, so we go with a quick-fix for now. |
908 // In the same manner, we have to patch the parsing mode. | 906 // In the same manner, we have to patch the parsing mode. |
909 if (is_eval && !scope_->is_eval_scope()) { | 907 if (is_eval && !scope_->is_eval_scope()) { |
910 ASSERT(scope_->is_global_scope()); | 908 ASSERT(scope_->is_global_scope()); |
911 Scope* scope = NewScope(scope_, EVAL_SCOPE); | 909 Scope* scope = NewScope(scope_, EVAL_SCOPE); |
912 scope->set_start_position(scope_->start_position()); | 910 scope->set_start_position(scope_->start_position()); |
913 scope->set_end_position(scope_->end_position()); | 911 scope->set_end_position(scope_->end_position()); |
914 scope_ = scope; | 912 scope_ = scope; |
915 mode_ = PARSE_EAGERLY; | 913 mode_ = PARSE_EAGERLY; |
916 } | 914 } |
917 // TODO(ES6): Fix entering extended mode, once it is specified. | 915 scope_->SetStrictMode(STRICT); |
918 scope_->SetLanguageMode(allow_harmony_scoping() | |
919 ? EXTENDED_MODE : STRICT_MODE); | |
920 // "use strict" is the only directive for now. | 916 // "use strict" is the only directive for now. |
921 directive_prologue = false; | 917 directive_prologue = false; |
922 } | 918 } |
923 } else { | 919 } else { |
924 // End of the directive prologue. | 920 // End of the directive prologue. |
925 directive_prologue = false; | 921 directive_prologue = false; |
926 } | 922 } |
927 } | 923 } |
928 | 924 |
929 processor->Add(stat, zone()); | 925 processor->Add(stat, zone()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 int pos = peek_position(); | 1047 int pos = peek_position(); |
1052 // Construct block expecting 16 statements. | 1048 // Construct block expecting 16 statements. |
1053 Block* body = factory()->NewBlock(NULL, 16, false, RelocInfo::kNoPosition); | 1049 Block* body = factory()->NewBlock(NULL, 16, false, RelocInfo::kNoPosition); |
1054 #ifdef DEBUG | 1050 #ifdef DEBUG |
1055 if (FLAG_print_interface_details) PrintF("# Literal "); | 1051 if (FLAG_print_interface_details) PrintF("# Literal "); |
1056 #endif | 1052 #endif |
1057 Scope* scope = NewScope(scope_, MODULE_SCOPE); | 1053 Scope* scope = NewScope(scope_, MODULE_SCOPE); |
1058 | 1054 |
1059 Expect(Token::LBRACE, CHECK_OK); | 1055 Expect(Token::LBRACE, CHECK_OK); |
1060 scope->set_start_position(scanner()->location().beg_pos); | 1056 scope->set_start_position(scanner()->location().beg_pos); |
1061 scope->SetLanguageMode(EXTENDED_MODE); | 1057 scope->SetStrictMode(STRICT); |
1062 | 1058 |
1063 { | 1059 { |
1064 BlockState block_state(&scope_, scope); | 1060 BlockState block_state(&scope_, scope); |
1065 TargetCollector collector(zone()); | 1061 TargetCollector collector(zone()); |
1066 Target target(&this->target_stack_, &collector); | 1062 Target target(&this->target_stack_, &collector); |
1067 Target target_body(&this->target_stack_, body); | 1063 Target target_body(&this->target_stack_, body); |
1068 | 1064 |
1069 while (peek() != Token::RBRACE) { | 1065 while (peek() != Token::RBRACE) { |
1070 Statement* stat = ParseModuleElement(NULL, CHECK_OK); | 1066 Statement* stat = ParseModuleElement(NULL, CHECK_OK); |
1071 if (stat && !stat->IsEmpty()) { | 1067 if (stat && !stat->IsEmpty()) { |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 // (Ecma 262 5th Edition, clause 14): | 1432 // (Ecma 262 5th Edition, clause 14): |
1437 // SourceElement: | 1433 // SourceElement: |
1438 // Statement | 1434 // Statement |
1439 // FunctionDeclaration | 1435 // FunctionDeclaration |
1440 // Common language extension is to allow function declaration in place | 1436 // Common language extension is to allow function declaration in place |
1441 // of any statement. This language extension is disabled in strict mode. | 1437 // of any statement. This language extension is disabled in strict mode. |
1442 // | 1438 // |
1443 // In Harmony mode, this case also handles the extension: | 1439 // In Harmony mode, this case also handles the extension: |
1444 // Statement: | 1440 // Statement: |
1445 // GeneratorDeclaration | 1441 // GeneratorDeclaration |
1446 if (!scope_->is_sloppy_mode()) { | 1442 if (strict_mode() == STRICT) { |
1447 ReportMessageAt(scanner()->peek_location(), "strict_function"); | 1443 ReportMessageAt(scanner()->peek_location(), "strict_function"); |
1448 *ok = false; | 1444 *ok = false; |
1449 return NULL; | 1445 return NULL; |
1450 } | 1446 } |
1451 return ParseFunctionDeclaration(NULL, ok); | 1447 return ParseFunctionDeclaration(NULL, ok); |
1452 } | 1448 } |
1453 | 1449 |
1454 case Token::DEBUGGER: | 1450 case Token::DEBUGGER: |
1455 return ParseDebuggerStatement(ok); | 1451 return ParseDebuggerStatement(ok); |
1456 | 1452 |
(...skipping 24 matching lines...) Expand all Loading... |
1481 | 1477 |
1482 // If a suitable scope exists, then we can statically declare this | 1478 // If a suitable scope exists, then we can statically declare this |
1483 // variable and also set its mode. In any case, a Declaration node | 1479 // variable and also set its mode. In any case, a Declaration node |
1484 // will be added to the scope so that the declaration can be added | 1480 // will be added to the scope so that the declaration can be added |
1485 // to the corresponding activation frame at runtime if necessary. | 1481 // to the corresponding activation frame at runtime if necessary. |
1486 // For instance declarations inside an eval scope need to be added | 1482 // For instance declarations inside an eval scope need to be added |
1487 // to the calling function context. | 1483 // to the calling function context. |
1488 // Similarly, strict mode eval scope does not leak variable declarations to | 1484 // Similarly, strict mode eval scope does not leak variable declarations to |
1489 // the caller's scope so we declare all locals, too. | 1485 // the caller's scope so we declare all locals, too. |
1490 if (declaration_scope->is_function_scope() || | 1486 if (declaration_scope->is_function_scope() || |
1491 declaration_scope->is_strict_or_extended_eval_scope() || | 1487 declaration_scope->is_strict_eval_scope() || |
1492 declaration_scope->is_block_scope() || | 1488 declaration_scope->is_block_scope() || |
1493 declaration_scope->is_module_scope() || | 1489 declaration_scope->is_module_scope() || |
1494 declaration_scope->is_global_scope()) { | 1490 declaration_scope->is_global_scope()) { |
1495 // Declare the variable in the declaration scope. | 1491 // Declare the variable in the declaration scope. |
1496 // For the global scope, we have to check for collisions with earlier | 1492 // For the global scope, we have to check for collisions with earlier |
1497 // (i.e., enclosing) global scopes, to maintain the illusion of a single | 1493 // (i.e., enclosing) global scopes, to maintain the illusion of a single |
1498 // global scope. | 1494 // global scope. |
1499 var = declaration_scope->is_global_scope() | 1495 var = declaration_scope->is_global_scope() |
1500 ? declaration_scope->Lookup(name) | 1496 ? declaration_scope->Lookup(name) |
1501 : declaration_scope->LocalLookup(name); | 1497 : declaration_scope->LocalLookup(name); |
(...skipping 12 matching lines...) Expand all Loading... |
1514 // functions. The function CheckNonConflictingScope checks for conflicting | 1510 // functions. The function CheckNonConflictingScope checks for conflicting |
1515 // var and let bindings from different scopes whereas this is a check for | 1511 // var and let bindings from different scopes whereas this is a check for |
1516 // conflicting declarations within the same scope. This check also covers | 1512 // conflicting declarations within the same scope. This check also covers |
1517 // the special case | 1513 // the special case |
1518 // | 1514 // |
1519 // function () { let x; { var x; } } | 1515 // function () { let x; { var x; } } |
1520 // | 1516 // |
1521 // because the var declaration is hoisted to the function scope where 'x' | 1517 // because the var declaration is hoisted to the function scope where 'x' |
1522 // is already bound. | 1518 // is already bound. |
1523 ASSERT(IsDeclaredVariableMode(var->mode())); | 1519 ASSERT(IsDeclaredVariableMode(var->mode())); |
1524 if (is_extended_mode()) { | 1520 if (FLAG_harmony_scoping && strict_mode() == STRICT) { |
1525 // In harmony mode we treat re-declarations as early errors. See | 1521 // In harmony we treat re-declarations as early errors. See |
1526 // ES5 16 for a definition of early errors. | 1522 // ES5 16 for a definition of early errors. |
1527 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); | 1523 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); |
1528 const char* elms[2] = { "Variable", c_string.get() }; | 1524 const char* elms[2] = { "Variable", c_string.get() }; |
1529 Vector<const char*> args(elms, 2); | 1525 Vector<const char*> args(elms, 2); |
1530 ReportMessage("redeclaration", args); | 1526 ReportMessage("redeclaration", args); |
1531 *ok = false; | 1527 *ok = false; |
1532 return; | 1528 return; |
1533 } | 1529 } |
1534 Handle<String> message_string = | 1530 Handle<String> message_string = |
1535 isolate()->factory()->NewStringFromUtf8(CStrVector("Variable"), | 1531 isolate()->factory()->NewStringFromUtf8(CStrVector("Variable"), |
(...skipping 16 matching lines...) Expand all Loading... |
1552 // bound during variable resolution time unless it was pre-bound | 1548 // bound during variable resolution time unless it was pre-bound |
1553 // below. | 1549 // below. |
1554 // | 1550 // |
1555 // WARNING: This will lead to multiple declaration nodes for the | 1551 // WARNING: This will lead to multiple declaration nodes for the |
1556 // same variable if it is declared several times. This is not a | 1552 // same variable if it is declared several times. This is not a |
1557 // semantic issue as long as we keep the source order, but it may be | 1553 // semantic issue as long as we keep the source order, but it may be |
1558 // a performance issue since it may lead to repeated | 1554 // a performance issue since it may lead to repeated |
1559 // Runtime::DeclareContextSlot() calls. | 1555 // Runtime::DeclareContextSlot() calls. |
1560 declaration_scope->AddDeclaration(declaration); | 1556 declaration_scope->AddDeclaration(declaration); |
1561 | 1557 |
1562 if (mode == CONST && declaration_scope->is_global_scope()) { | 1558 if (mode == CONST_LEGACY && declaration_scope->is_global_scope()) { |
1563 // For global const variables we bind the proxy to a variable. | 1559 // For global const variables we bind the proxy to a variable. |
1564 ASSERT(resolve); // should be set by all callers | 1560 ASSERT(resolve); // should be set by all callers |
1565 Variable::Kind kind = Variable::NORMAL; | 1561 Variable::Kind kind = Variable::NORMAL; |
1566 var = new(zone()) Variable( | 1562 var = new(zone()) Variable( |
1567 declaration_scope, name, mode, true, kind, | 1563 declaration_scope, name, mode, true, kind, |
1568 kNeedsInitialization, proxy->interface()); | 1564 kNeedsInitialization, proxy->interface()); |
1569 } else if (declaration_scope->is_eval_scope() && | 1565 } else if (declaration_scope->is_eval_scope() && |
1570 declaration_scope->is_sloppy_mode()) { | 1566 declaration_scope->strict_mode() == SLOPPY) { |
1571 // For variable declarations in a sloppy eval scope the proxy is bound | 1567 // For variable declarations in a sloppy eval scope the proxy is bound |
1572 // to a lookup variable to force a dynamic declaration using the | 1568 // to a lookup variable to force a dynamic declaration using the |
1573 // DeclareContextSlot runtime function. | 1569 // DeclareContextSlot runtime function. |
1574 Variable::Kind kind = Variable::NORMAL; | 1570 Variable::Kind kind = Variable::NORMAL; |
1575 var = new(zone()) Variable( | 1571 var = new(zone()) Variable( |
1576 declaration_scope, name, mode, true, kind, | 1572 declaration_scope, name, mode, true, kind, |
1577 declaration->initialization(), proxy->interface()); | 1573 declaration->initialization(), proxy->interface()); |
1578 var->AllocateTo(Variable::LOOKUP, -1); | 1574 var->AllocateTo(Variable::LOOKUP, -1); |
1579 resolve = true; | 1575 resolve = true; |
1580 } | 1576 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 is_generator, | 1688 is_generator, |
1693 pos, | 1689 pos, |
1694 FunctionLiteral::DECLARATION, | 1690 FunctionLiteral::DECLARATION, |
1695 CHECK_OK); | 1691 CHECK_OK); |
1696 // Even if we're not at the top-level of the global or a function | 1692 // Even if we're not at the top-level of the global or a function |
1697 // scope, we treat it as such and introduce the function with its | 1693 // scope, we treat it as such and introduce the function with its |
1698 // initial value upon entering the corresponding scope. | 1694 // initial value upon entering the corresponding scope. |
1699 // In extended mode, a function behaves as a lexical binding, except in the | 1695 // In extended mode, a function behaves as a lexical binding, except in the |
1700 // global scope. | 1696 // global scope. |
1701 VariableMode mode = | 1697 VariableMode mode = |
1702 is_extended_mode() && !scope_->is_global_scope() ? LET : VAR; | 1698 FLAG_harmony_scoping && |
| 1699 strict_mode() == STRICT && !scope_->is_global_scope() ? LET : VAR; |
1703 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); | 1700 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); |
1704 Declaration* declaration = | 1701 Declaration* declaration = |
1705 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); | 1702 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); |
1706 Declare(declaration, true, CHECK_OK); | 1703 Declare(declaration, true, CHECK_OK); |
1707 if (names) names->Add(name, zone()); | 1704 if (names) names->Add(name, zone()); |
1708 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1705 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
1709 } | 1706 } |
1710 | 1707 |
1711 | 1708 |
1712 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { | 1709 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { |
1713 if (scope_->is_extended_mode()) return ParseScopedBlock(labels, ok); | 1710 if (FLAG_harmony_scoping && strict_mode() == STRICT) { |
| 1711 return ParseScopedBlock(labels, ok); |
| 1712 } |
1714 | 1713 |
1715 // Block :: | 1714 // Block :: |
1716 // '{' Statement* '}' | 1715 // '{' Statement* '}' |
1717 | 1716 |
1718 // Note that a Block does not introduce a new execution scope! | 1717 // Note that a Block does not introduce a new execution scope! |
1719 // (ECMA-262, 3rd, 12.2) | 1718 // (ECMA-262, 3rd, 12.2) |
1720 // | 1719 // |
1721 // Construct block expecting 16 statements. | 1720 // Construct block expecting 16 statements. |
1722 Block* result = | 1721 Block* result = |
1723 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); | 1722 factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1823 // | 1822 // |
1824 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' | 1823 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' |
1825 // | 1824 // |
1826 // * It is a Syntax Error if the code that matches this production is not | 1825 // * It is a Syntax Error if the code that matches this production is not |
1827 // contained in extended code. | 1826 // contained in extended code. |
1828 // | 1827 // |
1829 // However disallowing const in sloppy mode will break compatibility with | 1828 // However disallowing const in sloppy mode will break compatibility with |
1830 // existing pages. Therefore we keep allowing const with the old | 1829 // existing pages. Therefore we keep allowing const with the old |
1831 // non-harmony semantics in sloppy mode. | 1830 // non-harmony semantics in sloppy mode. |
1832 Consume(Token::CONST); | 1831 Consume(Token::CONST); |
1833 switch (scope_->language_mode()) { | 1832 switch (strict_mode()) { |
1834 case SLOPPY_MODE: | 1833 case SLOPPY: |
1835 mode = CONST; | 1834 mode = CONST_LEGACY; |
1836 init_op = Token::INIT_CONST; | 1835 init_op = Token::INIT_CONST_LEGACY; |
1837 break; | 1836 break; |
1838 case STRICT_MODE: | 1837 case STRICT: |
1839 ReportMessage("strict_const", Vector<const char*>::empty()); | 1838 if (FLAG_harmony_scoping) { |
1840 *ok = false; | 1839 if (var_context == kStatement) { |
1841 return NULL; | 1840 // In strict mode 'const' declarations are only allowed in source |
1842 case EXTENDED_MODE: | 1841 // element positions. |
1843 if (var_context == kStatement) { | 1842 ReportMessage("unprotected_const", Vector<const char*>::empty()); |
1844 // In extended mode 'const' declarations are only allowed in source | 1843 *ok = false; |
1845 // element positions. | 1844 return NULL; |
1846 ReportMessage("unprotected_const", Vector<const char*>::empty()); | 1845 } |
| 1846 mode = CONST; |
| 1847 init_op = Token::INIT_CONST; |
| 1848 } else { |
| 1849 ReportMessage("strict_const", Vector<const char*>::empty()); |
1847 *ok = false; | 1850 *ok = false; |
1848 return NULL; | 1851 return NULL; |
1849 } | 1852 } |
1850 mode = CONST_HARMONY; | |
1851 init_op = Token::INIT_CONST_HARMONY; | |
1852 } | 1853 } |
1853 is_const = true; | 1854 is_const = true; |
1854 needs_init = true; | 1855 needs_init = true; |
1855 } else if (peek() == Token::LET) { | 1856 } else if (peek() == Token::LET) { |
1856 // ES6 Draft Rev4 section 12.2.1: | 1857 // ES6 Draft Rev4 section 12.2.1: |
1857 // | 1858 // |
1858 // LetDeclaration : let LetBindingList ; | 1859 // LetDeclaration : let LetBindingList ; |
1859 // | 1860 // |
1860 // * It is a Syntax Error if the code that matches this production is not | 1861 // * It is a Syntax Error if the code that matches this production is not |
1861 // contained in extended code. | 1862 // contained in extended code. |
1862 if (!is_extended_mode()) { | 1863 // |
| 1864 // TODO(rossberg): make 'let' a legal identifier in sloppy mode. |
| 1865 if (!FLAG_harmony_scoping || strict_mode() == SLOPPY) { |
1863 ReportMessage("illegal_let", Vector<const char*>::empty()); | 1866 ReportMessage("illegal_let", Vector<const char*>::empty()); |
1864 *ok = false; | 1867 *ok = false; |
1865 return NULL; | 1868 return NULL; |
1866 } | 1869 } |
1867 Consume(Token::LET); | 1870 Consume(Token::LET); |
1868 if (var_context == kStatement) { | 1871 if (var_context == kStatement) { |
1869 // Let declarations are only allowed in source element positions. | 1872 // Let declarations are only allowed in source element positions. |
1870 ReportMessage("unprotected_let", Vector<const char*>::empty()); | 1873 ReportMessage("unprotected_let", Vector<const char*>::empty()); |
1871 *ok = false; | 1874 *ok = false; |
1872 return NULL; | 1875 return NULL; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1957 // const c; c = x; | 1960 // const c; c = x; |
1958 // | 1961 // |
1959 // The "variable" c initialized to x is the same as the declared | 1962 // The "variable" c initialized to x is the same as the declared |
1960 // one - there is no re-lookup (see the last parameter of the | 1963 // one - there is no re-lookup (see the last parameter of the |
1961 // Declare() call above). | 1964 // Declare() call above). |
1962 | 1965 |
1963 Scope* initialization_scope = is_const ? declaration_scope : scope_; | 1966 Scope* initialization_scope = is_const ? declaration_scope : scope_; |
1964 Expression* value = NULL; | 1967 Expression* value = NULL; |
1965 int pos = -1; | 1968 int pos = -1; |
1966 // Harmony consts have non-optional initializers. | 1969 // Harmony consts have non-optional initializers. |
1967 if (peek() == Token::ASSIGN || mode == CONST_HARMONY) { | 1970 if (peek() == Token::ASSIGN || mode == CONST) { |
1968 Expect(Token::ASSIGN, CHECK_OK); | 1971 Expect(Token::ASSIGN, CHECK_OK); |
1969 pos = position(); | 1972 pos = position(); |
1970 value = ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); | 1973 value = ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); |
1971 // Don't infer if it is "a = function(){...}();"-like expression. | 1974 // Don't infer if it is "a = function(){...}();"-like expression. |
1972 if (fni_ != NULL && | 1975 if (fni_ != NULL && |
1973 value->AsCall() == NULL && | 1976 value->AsCall() == NULL && |
1974 value->AsCallNew() == NULL) { | 1977 value->AsCallNew() == NULL) { |
1975 fni_->Infer(); | 1978 fni_->Infer(); |
1976 } else { | 1979 } else { |
1977 fni_->RemoveLastFunction(); | 1980 fni_->RemoveLastFunction(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2025 // and add it to the initialization statement block. | 2028 // and add it to the initialization statement block. |
2026 // Note that the function does different things depending on | 2029 // Note that the function does different things depending on |
2027 // the number of arguments (1 or 2). | 2030 // the number of arguments (1 or 2). |
2028 initialize = factory()->NewCallRuntime( | 2031 initialize = factory()->NewCallRuntime( |
2029 isolate()->factory()->InitializeConstGlobal_string(), | 2032 isolate()->factory()->InitializeConstGlobal_string(), |
2030 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), | 2033 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), |
2031 arguments, pos); | 2034 arguments, pos); |
2032 } else { | 2035 } else { |
2033 // Add strict mode. | 2036 // Add strict mode. |
2034 // We may want to pass singleton to avoid Literal allocations. | 2037 // We may want to pass singleton to avoid Literal allocations. |
2035 LanguageMode language_mode = initialization_scope->language_mode(); | 2038 StrictMode strict_mode = initialization_scope->strict_mode(); |
2036 arguments->Add(factory()->NewNumberLiteral(language_mode, pos), zone()); | 2039 arguments->Add(factory()->NewNumberLiteral(strict_mode, pos), zone()); |
2037 | 2040 |
2038 // Be careful not to assign a value to the global variable if | 2041 // Be careful not to assign a value to the global variable if |
2039 // we're in a with. The initialization value should not | 2042 // we're in a with. The initialization value should not |
2040 // necessarily be stored in the global object in that case, | 2043 // necessarily be stored in the global object in that case, |
2041 // which is why we need to generate a separate assignment node. | 2044 // which is why we need to generate a separate assignment node. |
2042 if (value != NULL && !inside_with()) { | 2045 if (value != NULL && !inside_with()) { |
2043 arguments->Add(value, zone()); | 2046 arguments->Add(value, zone()); |
2044 value = NULL; // zap the value to avoid the unnecessary assignment | 2047 value = NULL; // zap the value to avoid the unnecessary assignment |
2045 } | 2048 } |
2046 | 2049 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2326 } | 2329 } |
2327 | 2330 |
2328 | 2331 |
2329 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { | 2332 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { |
2330 // WithStatement :: | 2333 // WithStatement :: |
2331 // 'with' '(' Expression ')' Statement | 2334 // 'with' '(' Expression ')' Statement |
2332 | 2335 |
2333 Expect(Token::WITH, CHECK_OK); | 2336 Expect(Token::WITH, CHECK_OK); |
2334 int pos = position(); | 2337 int pos = position(); |
2335 | 2338 |
2336 if (!scope_->is_sloppy_mode()) { | 2339 if (strict_mode() == STRICT) { |
2337 ReportMessage("strict_mode_with", Vector<const char*>::empty()); | 2340 ReportMessage("strict_mode_with", Vector<const char*>::empty()); |
2338 *ok = false; | 2341 *ok = false; |
2339 return NULL; | 2342 return NULL; |
2340 } | 2343 } |
2341 | 2344 |
2342 Expect(Token::LPAREN, CHECK_OK); | 2345 Expect(Token::LPAREN, CHECK_OK); |
2343 Expression* expr = ParseExpression(true, CHECK_OK); | 2346 Expression* expr = ParseExpression(true, CHECK_OK); |
2344 Expect(Token::RPAREN, CHECK_OK); | 2347 Expect(Token::RPAREN, CHECK_OK); |
2345 | 2348 |
2346 scope_->DeclarationScope()->RecordWithStatement(); | 2349 scope_->DeclarationScope()->RecordWithStatement(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2478 Consume(Token::CATCH); | 2481 Consume(Token::CATCH); |
2479 | 2482 |
2480 Expect(Token::LPAREN, CHECK_OK); | 2483 Expect(Token::LPAREN, CHECK_OK); |
2481 catch_scope = NewScope(scope_, CATCH_SCOPE); | 2484 catch_scope = NewScope(scope_, CATCH_SCOPE); |
2482 catch_scope->set_start_position(scanner()->location().beg_pos); | 2485 catch_scope->set_start_position(scanner()->location().beg_pos); |
2483 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 2486 name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
2484 | 2487 |
2485 Expect(Token::RPAREN, CHECK_OK); | 2488 Expect(Token::RPAREN, CHECK_OK); |
2486 | 2489 |
2487 Target target(&this->target_stack_, &catch_collector); | 2490 Target target(&this->target_stack_, &catch_collector); |
2488 VariableMode mode = is_extended_mode() ? LET : VAR; | 2491 VariableMode mode = |
| 2492 FLAG_harmony_scoping && strict_mode() == STRICT ? LET : VAR; |
2489 catch_variable = | 2493 catch_variable = |
2490 catch_scope->DeclareLocal(name, mode, kCreatedInitialized); | 2494 catch_scope->DeclareLocal(name, mode, kCreatedInitialized); |
2491 | 2495 |
2492 BlockState block_state(&scope_, catch_scope); | 2496 BlockState block_state(&scope_, catch_scope); |
2493 catch_block = ParseBlock(NULL, CHECK_OK); | 2497 catch_block = ParseBlock(NULL, CHECK_OK); |
2494 | 2498 |
2495 catch_scope->set_end_position(scanner()->location().end_pos); | 2499 catch_scope->set_end_position(scanner()->location().end_pos); |
2496 tok = peek(); | 2500 tok = peek(); |
2497 } | 2501 } |
2498 | 2502 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2900 // side expression. We could report this as a syntax error here but | 2904 // side expression. We could report this as a syntax error here but |
2901 // for compatibility with JSC we choose to report the error at | 2905 // for compatibility with JSC we choose to report the error at |
2902 // runtime. | 2906 // runtime. |
2903 // TODO(ES5): Should change parsing for spec conformance. | 2907 // TODO(ES5): Should change parsing for spec conformance. |
2904 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2908 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
2905 Handle<String> message = | 2909 Handle<String> message = |
2906 isolate()->factory()->invalid_lhs_in_assignment_string(); | 2910 isolate()->factory()->invalid_lhs_in_assignment_string(); |
2907 expression = NewThrowReferenceError(message); | 2911 expression = NewThrowReferenceError(message); |
2908 } | 2912 } |
2909 | 2913 |
2910 if (!scope_->is_sloppy_mode()) { | 2914 if (strict_mode() == STRICT) { |
2911 // Assignment to eval or arguments is disallowed in strict mode. | 2915 // Assignment to eval or arguments is disallowed in strict mode. |
2912 CheckStrictModeLValue(expression, CHECK_OK); | 2916 CheckStrictModeLValue(expression, CHECK_OK); |
2913 } | 2917 } |
2914 MarkAsLValue(expression); | 2918 MarkAsLValue(expression); |
2915 | 2919 |
2916 Token::Value op = Next(); // Get assignment operator. | 2920 Token::Value op = Next(); // Get assignment operator. |
2917 int pos = position(); | 2921 int pos = position(); |
2918 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); | 2922 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); |
2919 | 2923 |
2920 // TODO(1231235): We try to estimate the set of properties set by | 2924 // TODO(1231235): We try to estimate the set of properties set by |
(...skipping 13 matching lines...) Expand all Loading... |
2934 // literal so it can be added as a constant function property. | 2938 // literal so it can be added as a constant function property. |
2935 if (property != NULL && right->AsFunctionLiteral() != NULL) { | 2939 if (property != NULL && right->AsFunctionLiteral() != NULL) { |
2936 right->AsFunctionLiteral()->set_pretenure(); | 2940 right->AsFunctionLiteral()->set_pretenure(); |
2937 } | 2941 } |
2938 | 2942 |
2939 if (fni_ != NULL) { | 2943 if (fni_ != NULL) { |
2940 // Check if the right hand side is a call to avoid inferring a | 2944 // Check if the right hand side is a call to avoid inferring a |
2941 // name if we're dealing with "a = function(){...}();"-like | 2945 // name if we're dealing with "a = function(){...}();"-like |
2942 // expression. | 2946 // expression. |
2943 if ((op == Token::INIT_VAR | 2947 if ((op == Token::INIT_VAR |
2944 || op == Token::INIT_CONST | 2948 || op == Token::INIT_CONST_LEGACY |
2945 || op == Token::ASSIGN) | 2949 || op == Token::ASSIGN) |
2946 && (right->AsCall() == NULL && right->AsCallNew() == NULL)) { | 2950 && (right->AsCall() == NULL && right->AsCallNew() == NULL)) { |
2947 fni_->Infer(); | 2951 fni_->Infer(); |
2948 } else { | 2952 } else { |
2949 fni_->RemoveLastFunction(); | 2953 fni_->RemoveLastFunction(); |
2950 } | 2954 } |
2951 fni_->Leave(); | 2955 fni_->Leave(); |
2952 } | 2956 } |
2953 | 2957 |
2954 return factory()->NewAssignment(op, expression, right, pos); | 2958 return factory()->NewAssignment(op, expression, right, pos); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3124 return factory()->NewNumberLiteral(-value, pos); | 3128 return factory()->NewNumberLiteral(-value, pos); |
3125 case Token::BIT_NOT: | 3129 case Token::BIT_NOT: |
3126 return factory()->NewNumberLiteral(~DoubleToInt32(value), pos); | 3130 return factory()->NewNumberLiteral(~DoubleToInt32(value), pos); |
3127 default: | 3131 default: |
3128 break; | 3132 break; |
3129 } | 3133 } |
3130 } | 3134 } |
3131 } | 3135 } |
3132 | 3136 |
3133 // "delete identifier" is a syntax error in strict mode. | 3137 // "delete identifier" is a syntax error in strict mode. |
3134 if (op == Token::DELETE && !scope_->is_sloppy_mode()) { | 3138 if (op == Token::DELETE && strict_mode() == STRICT) { |
3135 VariableProxy* operand = expression->AsVariableProxy(); | 3139 VariableProxy* operand = expression->AsVariableProxy(); |
3136 if (operand != NULL && !operand->is_this()) { | 3140 if (operand != NULL && !operand->is_this()) { |
3137 ReportMessage("strict_delete", Vector<const char*>::empty()); | 3141 ReportMessage("strict_delete", Vector<const char*>::empty()); |
3138 *ok = false; | 3142 *ok = false; |
3139 return NULL; | 3143 return NULL; |
3140 } | 3144 } |
3141 } | 3145 } |
3142 | 3146 |
3143 // Desugar '+foo' into 'foo*1', this enables the collection of type feedback | 3147 // Desugar '+foo' into 'foo*1', this enables the collection of type feedback |
3144 // without any special stub and the multiplication is removed later in | 3148 // without any special stub and the multiplication is removed later in |
(...skipping 27 matching lines...) Expand all Loading... |
3172 // Signal a reference error if the expression is an invalid | 3176 // Signal a reference error if the expression is an invalid |
3173 // left-hand side expression. We could report this as a syntax | 3177 // left-hand side expression. We could report this as a syntax |
3174 // error here but for compatibility with JSC we choose to report the | 3178 // error here but for compatibility with JSC we choose to report the |
3175 // error at runtime. | 3179 // error at runtime. |
3176 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 3180 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
3177 Handle<String> message = | 3181 Handle<String> message = |
3178 isolate()->factory()->invalid_lhs_in_prefix_op_string(); | 3182 isolate()->factory()->invalid_lhs_in_prefix_op_string(); |
3179 expression = NewThrowReferenceError(message); | 3183 expression = NewThrowReferenceError(message); |
3180 } | 3184 } |
3181 | 3185 |
3182 if (!scope_->is_sloppy_mode()) { | 3186 if (strict_mode() == STRICT) { |
3183 // Prefix expression operand in strict mode may not be eval or arguments. | 3187 // Prefix expression operand in strict mode may not be eval or arguments. |
3184 CheckStrictModeLValue(expression, CHECK_OK); | 3188 CheckStrictModeLValue(expression, CHECK_OK); |
3185 } | 3189 } |
3186 MarkAsLValue(expression); | 3190 MarkAsLValue(expression); |
3187 | 3191 |
3188 return factory()->NewCountOperation(op, | 3192 return factory()->NewCountOperation(op, |
3189 true /* prefix */, | 3193 true /* prefix */, |
3190 expression, | 3194 expression, |
3191 position()); | 3195 position()); |
3192 | 3196 |
(...skipping 13 matching lines...) Expand all Loading... |
3206 // Signal a reference error if the expression is an invalid | 3210 // Signal a reference error if the expression is an invalid |
3207 // left-hand side expression. We could report this as a syntax | 3211 // left-hand side expression. We could report this as a syntax |
3208 // error here but for compatibility with JSC we choose to report the | 3212 // error here but for compatibility with JSC we choose to report the |
3209 // error at runtime. | 3213 // error at runtime. |
3210 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 3214 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
3211 Handle<String> message = | 3215 Handle<String> message = |
3212 isolate()->factory()->invalid_lhs_in_postfix_op_string(); | 3216 isolate()->factory()->invalid_lhs_in_postfix_op_string(); |
3213 expression = NewThrowReferenceError(message); | 3217 expression = NewThrowReferenceError(message); |
3214 } | 3218 } |
3215 | 3219 |
3216 if (!scope_->is_sloppy_mode()) { | 3220 if (strict_mode() == STRICT) { |
3217 // Postfix expression operand in strict mode may not be eval or arguments. | 3221 // Postfix expression operand in strict mode may not be eval or arguments. |
3218 CheckStrictModeLValue(expression, CHECK_OK); | 3222 CheckStrictModeLValue(expression, CHECK_OK); |
3219 } | 3223 } |
3220 MarkAsLValue(expression); | 3224 MarkAsLValue(expression); |
3221 | 3225 |
3222 Token::Value next = Next(); | 3226 Token::Value next = Next(); |
3223 expression = | 3227 expression = |
3224 factory()->NewCountOperation(next, | 3228 factory()->NewCountOperation(next, |
3225 false /* postfix */, | 3229 false /* postfix */, |
3226 expression, | 3230 expression, |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3496 // ((IdentifierName | String | Number) ':' AssignmentExpression) | 3500 // ((IdentifierName | String | Number) ':' AssignmentExpression) |
3497 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) | 3501 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) |
3498 // )*[','] '}' | 3502 // )*[','] '}' |
3499 | 3503 |
3500 int pos = peek_position(); | 3504 int pos = peek_position(); |
3501 ZoneList<ObjectLiteral::Property*>* properties = | 3505 ZoneList<ObjectLiteral::Property*>* properties = |
3502 new(zone()) ZoneList<ObjectLiteral::Property*>(4, zone()); | 3506 new(zone()) ZoneList<ObjectLiteral::Property*>(4, zone()); |
3503 int number_of_boilerplate_properties = 0; | 3507 int number_of_boilerplate_properties = 0; |
3504 bool has_function = false; | 3508 bool has_function = false; |
3505 | 3509 |
3506 ObjectLiteralChecker checker(this, scope_->language_mode()); | 3510 ObjectLiteralChecker checker(this, strict_mode()); |
3507 | 3511 |
3508 Expect(Token::LBRACE, CHECK_OK); | 3512 Expect(Token::LBRACE, CHECK_OK); |
3509 | 3513 |
3510 while (peek() != Token::RBRACE) { | 3514 while (peek() != Token::RBRACE) { |
3511 if (fni_ != NULL) fni_->Enter(); | 3515 if (fni_ != NULL) fni_->Enter(); |
3512 | 3516 |
3513 Literal* key = NULL; | 3517 Literal* key = NULL; |
3514 Token::Value next = peek(); | 3518 Token::Value next = peek(); |
3515 int next_pos = peek_position(); | 3519 int next_pos = peek_position(); |
3516 | 3520 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3684 public: | 3688 public: |
3685 SingletonLogger() : has_error_(false), start_(-1), end_(-1) { } | 3689 SingletonLogger() : has_error_(false), start_(-1), end_(-1) { } |
3686 virtual ~SingletonLogger() { } | 3690 virtual ~SingletonLogger() { } |
3687 | 3691 |
3688 void Reset() { has_error_ = false; } | 3692 void Reset() { has_error_ = false; } |
3689 | 3693 |
3690 virtual void LogFunction(int start, | 3694 virtual void LogFunction(int start, |
3691 int end, | 3695 int end, |
3692 int literals, | 3696 int literals, |
3693 int properties, | 3697 int properties, |
3694 LanguageMode mode) { | 3698 StrictMode strict_mode) { |
3695 ASSERT(!has_error_); | 3699 ASSERT(!has_error_); |
3696 start_ = start; | 3700 start_ = start; |
3697 end_ = end; | 3701 end_ = end; |
3698 literals_ = literals; | 3702 literals_ = literals; |
3699 properties_ = properties; | 3703 properties_ = properties; |
3700 mode_ = mode; | 3704 strict_mode_ = strict_mode; |
3701 }; | 3705 }; |
3702 | 3706 |
3703 // Logs a symbol creation of a literal or identifier. | 3707 // Logs a symbol creation of a literal or identifier. |
3704 virtual void LogAsciiSymbol(int start, Vector<const char> literal) { } | 3708 virtual void LogAsciiSymbol(int start, Vector<const char> literal) { } |
3705 virtual void LogUtf16Symbol(int start, Vector<const uc16> literal) { } | 3709 virtual void LogUtf16Symbol(int start, Vector<const uc16> literal) { } |
3706 | 3710 |
3707 // Logs an error message and marks the log as containing an error. | 3711 // Logs an error message and marks the log as containing an error. |
3708 // Further logging will be ignored, and ExtractData will return a vector | 3712 // Further logging will be ignored, and ExtractData will return a vector |
3709 // representing the error only. | 3713 // representing the error only. |
3710 virtual void LogMessage(int start, | 3714 virtual void LogMessage(int start, |
(...skipping 28 matching lines...) Expand all Loading... |
3739 int start() { return start_; } | 3743 int start() { return start_; } |
3740 int end() { return end_; } | 3744 int end() { return end_; } |
3741 int literals() { | 3745 int literals() { |
3742 ASSERT(!has_error_); | 3746 ASSERT(!has_error_); |
3743 return literals_; | 3747 return literals_; |
3744 } | 3748 } |
3745 int properties() { | 3749 int properties() { |
3746 ASSERT(!has_error_); | 3750 ASSERT(!has_error_); |
3747 return properties_; | 3751 return properties_; |
3748 } | 3752 } |
3749 LanguageMode language_mode() { | 3753 StrictMode strict_mode() { |
3750 ASSERT(!has_error_); | 3754 ASSERT(!has_error_); |
3751 return mode_; | 3755 return strict_mode_; |
3752 } | 3756 } |
3753 const char* message() { | 3757 const char* message() { |
3754 ASSERT(has_error_); | 3758 ASSERT(has_error_); |
3755 return message_; | 3759 return message_; |
3756 } | 3760 } |
3757 const char* argument_opt() { | 3761 const char* argument_opt() { |
3758 ASSERT(has_error_); | 3762 ASSERT(has_error_); |
3759 return argument_opt_; | 3763 return argument_opt_; |
3760 } | 3764 } |
3761 | 3765 |
3762 private: | 3766 private: |
3763 bool has_error_; | 3767 bool has_error_; |
3764 int start_; | 3768 int start_; |
3765 int end_; | 3769 int end_; |
3766 // For function entries. | 3770 // For function entries. |
3767 int literals_; | 3771 int literals_; |
3768 int properties_; | 3772 int properties_; |
3769 LanguageMode mode_; | 3773 StrictMode strict_mode_; |
3770 // For error messages. | 3774 // For error messages. |
3771 const char* message_; | 3775 const char* message_; |
3772 const char* argument_opt_; | 3776 const char* argument_opt_; |
3773 }; | 3777 }; |
3774 | 3778 |
3775 | 3779 |
3776 FunctionLiteral* Parser::ParseFunctionLiteral( | 3780 FunctionLiteral* Parser::ParseFunctionLiteral( |
3777 Handle<String> function_name, | 3781 Handle<String> function_name, |
3778 Scanner::Location function_name_location, | 3782 Scanner::Location function_name_location, |
3779 bool name_is_strict_reserved, | 3783 bool name_is_strict_reserved, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3821 // under which we compile is _not_ a declaration scope. This holds because | 3825 // under which we compile is _not_ a declaration scope. This holds because |
3822 // in all normal cases, function declarations are fully hoisted to a | 3826 // in all normal cases, function declarations are fully hoisted to a |
3823 // declaration scope and compiled relative to that. | 3827 // declaration scope and compiled relative to that. |
3824 // - (2) is the case iff the current declaration scope is still the original | 3828 // - (2) is the case iff the current declaration scope is still the original |
3825 // one relative to the deserialized scope chain. Otherwise we must be | 3829 // one relative to the deserialized scope chain. Otherwise we must be |
3826 // compiling a function in an inner declaration scope in the eval, e.g. a | 3830 // compiling a function in an inner declaration scope in the eval, e.g. a |
3827 // nested function, and hoisting works normally relative to that. | 3831 // nested function, and hoisting works normally relative to that. |
3828 Scope* declaration_scope = scope_->DeclarationScope(); | 3832 Scope* declaration_scope = scope_->DeclarationScope(); |
3829 Scope* original_declaration_scope = original_scope_->DeclarationScope(); | 3833 Scope* original_declaration_scope = original_scope_->DeclarationScope(); |
3830 Scope* scope = | 3834 Scope* scope = |
3831 function_type == FunctionLiteral::DECLARATION && !is_extended_mode() && | 3835 function_type == FunctionLiteral::DECLARATION && |
| 3836 (!FLAG_harmony_scoping || strict_mode() == SLOPPY) && |
3832 (original_scope_ == original_declaration_scope || | 3837 (original_scope_ == original_declaration_scope || |
3833 declaration_scope != original_declaration_scope) | 3838 declaration_scope != original_declaration_scope) |
3834 ? NewScope(declaration_scope, FUNCTION_SCOPE) | 3839 ? NewScope(declaration_scope, FUNCTION_SCOPE) |
3835 : NewScope(scope_, FUNCTION_SCOPE); | 3840 : NewScope(scope_, FUNCTION_SCOPE); |
3836 ZoneList<Statement*>* body = NULL; | 3841 ZoneList<Statement*>* body = NULL; |
3837 int materialized_literal_count = -1; | 3842 int materialized_literal_count = -1; |
3838 int expected_property_count = -1; | 3843 int expected_property_count = -1; |
3839 int handler_count = 0; | 3844 int handler_count = 0; |
3840 FunctionLiteral::ParameterFlag duplicate_parameters = | 3845 FunctionLiteral::ParameterFlag duplicate_parameters = |
3841 FunctionLiteral::kNoDuplicateParameters; | 3846 FunctionLiteral::kNoDuplicateParameters; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3910 | 3915 |
3911 Expect(Token::LBRACE, CHECK_OK); | 3916 Expect(Token::LBRACE, CHECK_OK); |
3912 | 3917 |
3913 // If we have a named function expression, we add a local variable | 3918 // If we have a named function expression, we add a local variable |
3914 // declaration to the body of the function with the name of the | 3919 // declaration to the body of the function with the name of the |
3915 // function and let it refer to the function itself (closure). | 3920 // function and let it refer to the function itself (closure). |
3916 // NOTE: We create a proxy and resolve it here so that in the | 3921 // NOTE: We create a proxy and resolve it here so that in the |
3917 // future we can change the AST to only refer to VariableProxies | 3922 // future we can change the AST to only refer to VariableProxies |
3918 // instead of Variables and Proxis as is the case now. | 3923 // instead of Variables and Proxis as is the case now. |
3919 Variable* fvar = NULL; | 3924 Variable* fvar = NULL; |
3920 Token::Value fvar_init_op = Token::INIT_CONST; | 3925 Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; |
3921 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { | 3926 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { |
3922 if (is_extended_mode()) fvar_init_op = Token::INIT_CONST_HARMONY; | 3927 if (FLAG_harmony_scoping && strict_mode() == STRICT) { |
3923 VariableMode fvar_mode = is_extended_mode() ? CONST_HARMONY : CONST; | 3928 fvar_init_op = Token::INIT_CONST; |
| 3929 } |
| 3930 VariableMode fvar_mode = FLAG_harmony_scoping && strict_mode() == STRICT |
| 3931 ? CONST : CONST_LEGACY; |
3924 fvar = new(zone()) Variable(scope_, | 3932 fvar = new(zone()) Variable(scope_, |
3925 function_name, fvar_mode, true /* is valid LHS */, | 3933 function_name, fvar_mode, true /* is valid LHS */, |
3926 Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); | 3934 Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); |
3927 VariableProxy* proxy = factory()->NewVariableProxy(fvar); | 3935 VariableProxy* proxy = factory()->NewVariableProxy(fvar); |
3928 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( | 3936 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( |
3929 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); | 3937 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); |
3930 scope_->DeclareFunctionVar(fvar_declaration); | 3938 scope_->DeclareFunctionVar(fvar_declaration); |
3931 } | 3939 } |
3932 | 3940 |
3933 // Determine if the function can be parsed lazily. Lazy parsing is different | 3941 // Determine if the function can be parsed lazily. Lazy parsing is different |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3983 ReportInvalidPreparseData(function_name, CHECK_OK); | 3991 ReportInvalidPreparseData(function_name, CHECK_OK); |
3984 } | 3992 } |
3985 scanner()->SeekForward(entry.end_pos() - 1); | 3993 scanner()->SeekForward(entry.end_pos() - 1); |
3986 | 3994 |
3987 scope->set_end_position(entry.end_pos()); | 3995 scope->set_end_position(entry.end_pos()); |
3988 Expect(Token::RBRACE, CHECK_OK); | 3996 Expect(Token::RBRACE, CHECK_OK); |
3989 isolate()->counters()->total_preparse_skipped()->Increment( | 3997 isolate()->counters()->total_preparse_skipped()->Increment( |
3990 scope->end_position() - function_block_pos); | 3998 scope->end_position() - function_block_pos); |
3991 materialized_literal_count = entry.literal_count(); | 3999 materialized_literal_count = entry.literal_count(); |
3992 expected_property_count = entry.property_count(); | 4000 expected_property_count = entry.property_count(); |
3993 scope_->SetLanguageMode(entry.language_mode()); | 4001 scope_->SetStrictMode(entry.strict_mode()); |
3994 } else { | 4002 } else { |
3995 // This case happens when we have preparse data but it doesn't contain | 4003 // This case happens when we have preparse data but it doesn't contain |
3996 // an entry for the function. As a safety net, fall back to eager | 4004 // an entry for the function. As a safety net, fall back to eager |
3997 // parsing. It is unclear whether PreParser's laziness analysis can | 4005 // parsing. It is unclear whether PreParser's laziness analysis can |
3998 // produce different results than the Parser's laziness analysis (see | 4006 // produce different results than the Parser's laziness analysis (see |
3999 // https://codereview.chromium.org/7565003 ). This safety net is | 4007 // https://codereview.chromium.org/7565003 ). This safety net is |
4000 // guarding against the case where Parser thinks a function should be | 4008 // guarding against the case where Parser thinks a function should be |
4001 // lazily parsed, but PreParser thinks it should be eagerly parsed -- | 4009 // lazily parsed, but PreParser thinks it should be eagerly parsed -- |
4002 // in that case we fall back to eager parsing in Parser, too. Note | 4010 // in that case we fall back to eager parsing in Parser, too. Note |
4003 // that the opposite case is worse: if PreParser thinks a function | 4011 // that the opposite case is worse: if PreParser thinks a function |
(...skipping 27 matching lines...) Expand all Loading... |
4031 args); | 4039 args); |
4032 *ok = false; | 4040 *ok = false; |
4033 return NULL; | 4041 return NULL; |
4034 } | 4042 } |
4035 scope->set_end_position(logger.end()); | 4043 scope->set_end_position(logger.end()); |
4036 Expect(Token::RBRACE, CHECK_OK); | 4044 Expect(Token::RBRACE, CHECK_OK); |
4037 isolate()->counters()->total_preparse_skipped()->Increment( | 4045 isolate()->counters()->total_preparse_skipped()->Increment( |
4038 scope->end_position() - function_block_pos); | 4046 scope->end_position() - function_block_pos); |
4039 materialized_literal_count = logger.literals(); | 4047 materialized_literal_count = logger.literals(); |
4040 expected_property_count = logger.properties(); | 4048 expected_property_count = logger.properties(); |
4041 scope_->SetLanguageMode(logger.language_mode()); | 4049 scope_->SetStrictMode(logger.strict_mode()); |
4042 } | 4050 } |
4043 } | 4051 } |
4044 | 4052 |
4045 if (!is_lazily_parsed) { | 4053 if (!is_lazily_parsed) { |
4046 // Everything inside an eagerly parsed function will be parsed eagerly | 4054 // Everything inside an eagerly parsed function will be parsed eagerly |
4047 // (see comment above). | 4055 // (see comment above). |
4048 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 4056 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
4049 body = new(zone()) ZoneList<Statement*>(8, zone()); | 4057 body = new(zone()) ZoneList<Statement*>(8, zone()); |
4050 if (fvar != NULL) { | 4058 if (fvar != NULL) { |
4051 VariableProxy* fproxy = scope_->NewUnresolved( | 4059 VariableProxy* fproxy = scope_->NewUnresolved( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4095 materialized_literal_count = function_state.materialized_literal_count(); | 4103 materialized_literal_count = function_state.materialized_literal_count(); |
4096 expected_property_count = function_state.expected_property_count(); | 4104 expected_property_count = function_state.expected_property_count(); |
4097 handler_count = function_state.handler_count(); | 4105 handler_count = function_state.handler_count(); |
4098 | 4106 |
4099 Expect(Token::RBRACE, CHECK_OK); | 4107 Expect(Token::RBRACE, CHECK_OK); |
4100 scope->set_end_position(scanner()->location().end_pos); | 4108 scope->set_end_position(scanner()->location().end_pos); |
4101 } | 4109 } |
4102 | 4110 |
4103 // Validate strict mode. We can do this only after parsing the function, | 4111 // Validate strict mode. We can do this only after parsing the function, |
4104 // since the function can declare itself strict. | 4112 // since the function can declare itself strict. |
4105 if (!scope_->is_sloppy_mode()) { | 4113 if (strict_mode() == STRICT) { |
4106 if (IsEvalOrArguments(function_name)) { | 4114 if (IsEvalOrArguments(function_name)) { |
4107 ReportMessageAt(function_name_location, "strict_eval_arguments"); | 4115 ReportMessageAt(function_name_location, "strict_eval_arguments"); |
4108 *ok = false; | 4116 *ok = false; |
4109 return NULL; | 4117 return NULL; |
4110 } | 4118 } |
4111 if (name_is_strict_reserved) { | 4119 if (name_is_strict_reserved) { |
4112 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); | 4120 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); |
4113 *ok = false; | 4121 *ok = false; |
4114 return NULL; | 4122 return NULL; |
4115 } | 4123 } |
(...skipping 14 matching lines...) Expand all Loading... |
4130 } | 4138 } |
4131 CheckOctalLiteral(scope->start_position(), | 4139 CheckOctalLiteral(scope->start_position(), |
4132 scope->end_position(), | 4140 scope->end_position(), |
4133 CHECK_OK); | 4141 CHECK_OK); |
4134 } | 4142 } |
4135 ast_properties = *factory()->visitor()->ast_properties(); | 4143 ast_properties = *factory()->visitor()->ast_properties(); |
4136 slot_processor = factory()->visitor()->slot_processor(); | 4144 slot_processor = factory()->visitor()->slot_processor(); |
4137 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); | 4145 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); |
4138 } | 4146 } |
4139 | 4147 |
4140 if (is_extended_mode()) { | 4148 if (FLAG_harmony_scoping && strict_mode() == STRICT) { |
4141 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4149 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4142 } | 4150 } |
4143 | 4151 |
4144 FunctionLiteral* function_literal = | 4152 FunctionLiteral* function_literal = |
4145 factory()->NewFunctionLiteral(function_name, | 4153 factory()->NewFunctionLiteral(function_name, |
4146 scope, | 4154 scope, |
4147 body, | 4155 body, |
4148 materialized_literal_count, | 4156 materialized_literal_count, |
4149 expected_property_count, | 4157 expected_property_count, |
4150 handler_count, | 4158 handler_count, |
(...skipping 25 matching lines...) Expand all Loading... |
4176 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 4184 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
4177 reusable_preparser_->set_allow_modules(allow_modules()); | 4185 reusable_preparser_->set_allow_modules(allow_modules()); |
4178 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 4186 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
4179 reusable_preparser_->set_allow_lazy(true); | 4187 reusable_preparser_->set_allow_lazy(true); |
4180 reusable_preparser_->set_allow_generators(allow_generators()); | 4188 reusable_preparser_->set_allow_generators(allow_generators()); |
4181 reusable_preparser_->set_allow_for_of(allow_for_of()); | 4189 reusable_preparser_->set_allow_for_of(allow_for_of()); |
4182 reusable_preparser_->set_allow_harmony_numeric_literals( | 4190 reusable_preparser_->set_allow_harmony_numeric_literals( |
4183 allow_harmony_numeric_literals()); | 4191 allow_harmony_numeric_literals()); |
4184 } | 4192 } |
4185 PreParser::PreParseResult result = | 4193 PreParser::PreParseResult result = |
4186 reusable_preparser_->PreParseLazyFunction(scope_->language_mode(), | 4194 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
4187 is_generator(), | 4195 is_generator(), |
4188 logger); | 4196 logger); |
4189 return result; | 4197 return result; |
4190 } | 4198 } |
4191 | 4199 |
4192 | 4200 |
4193 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 4201 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
4194 // CallRuntime :: | 4202 // CallRuntime :: |
4195 // '%' Identifier Arguments | 4203 // '%' Identifier Arguments |
4196 | 4204 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4258 : NULL; | 4266 : NULL; |
4259 | 4267 |
4260 if (proxy != NULL) proxy->MarkAsLValue(); | 4268 if (proxy != NULL) proxy->MarkAsLValue(); |
4261 } | 4269 } |
4262 | 4270 |
4263 | 4271 |
4264 // Checks LHS expression for assignment and prefix/postfix increment/decrement | 4272 // Checks LHS expression for assignment and prefix/postfix increment/decrement |
4265 // in strict mode. | 4273 // in strict mode. |
4266 void Parser::CheckStrictModeLValue(Expression* expression, | 4274 void Parser::CheckStrictModeLValue(Expression* expression, |
4267 bool* ok) { | 4275 bool* ok) { |
4268 ASSERT(!scope_->is_sloppy_mode()); | 4276 ASSERT(strict_mode() == STRICT); |
4269 VariableProxy* lhs = expression != NULL | 4277 VariableProxy* lhs = expression != NULL |
4270 ? expression->AsVariableProxy() | 4278 ? expression->AsVariableProxy() |
4271 : NULL; | 4279 : NULL; |
4272 | 4280 |
4273 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) { | 4281 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) { |
4274 ReportMessage("strict_eval_arguments", Vector<const char*>::empty()); | 4282 ReportMessage("strict_eval_arguments", Vector<const char*>::empty()); |
4275 *ok = false; | 4283 *ok = false; |
4276 } | 4284 } |
4277 } | 4285 } |
4278 | 4286 |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5353 ASSERT(info()->isolate()->has_pending_exception()); | 5361 ASSERT(info()->isolate()->has_pending_exception()); |
5354 } else { | 5362 } else { |
5355 result = ParseProgram(); | 5363 result = ParseProgram(); |
5356 } | 5364 } |
5357 } | 5365 } |
5358 info()->SetFunction(result); | 5366 info()->SetFunction(result); |
5359 return (result != NULL); | 5367 return (result != NULL); |
5360 } | 5368 } |
5361 | 5369 |
5362 } } // namespace v8::internal | 5370 } } // namespace v8::internal |
OLD | NEW |