OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 DCHECK(false); | 704 DCHECK(false); |
705 } | 705 } |
706 return NULL; | 706 return NULL; |
707 } | 707 } |
708 | 708 |
709 | 709 |
710 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 710 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
711 int pos, Scope* scope, | 711 int pos, Scope* scope, |
712 AstNodeFactory* factory) { | 712 AstNodeFactory* factory) { |
713 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); | 713 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
714 // The name may refer to a module instance object, so its type is unknown. | |
715 #ifdef DEBUG | |
716 if (FLAG_print_interface_details) | |
717 PrintF("# Variable %.*s ", name->length(), name->raw_data()); | |
718 #endif | |
719 Interface* interface = Interface::NewUnknown(parser_->zone()); | |
720 | 714 |
721 // Arrow function parameters are parsed as an expression. When | 715 // Arrow function parameters are parsed as an expression. When |
722 // parsing lazily, it is enough to create a VariableProxy in order | 716 // parsing lazily, it is enough to create a VariableProxy in order |
723 // for Traits::DeclareArrowParametersFromExpression() to be able to | 717 // for Traits::DeclareArrowParametersFromExpression() to be able to |
724 // pick the names of the parameters. | 718 // pick the names of the parameters. |
725 return parser_->parsing_lazy_arrow_parameters_ | 719 return parser_->parsing_lazy_arrow_parameters_ |
726 ? factory->NewVariableProxy(name, false, interface, pos) | 720 ? factory->NewVariableProxy(name, false, pos) |
727 : scope->NewUnresolved(factory, name, interface, pos); | 721 : scope->NewUnresolved(factory, name, pos); |
728 } | 722 } |
729 | 723 |
730 | 724 |
731 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 725 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
732 AstNodeFactory* factory) { | 726 AstNodeFactory* factory) { |
733 const AstRawString* symbol = GetSymbol(scanner); | 727 const AstRawString* symbol = GetSymbol(scanner); |
734 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 728 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
735 return factory->NewStringLiteral(symbol, pos); | 729 return factory->NewStringLiteral(symbol, pos); |
736 } | 730 } |
737 | 731 |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 Interface* interface = scope->interface(); | 1282 Interface* interface = scope->interface(); |
1289 for (Interface::Iterator it = interface->iterator(); | 1283 for (Interface::Iterator it = interface->iterator(); |
1290 !it.done(); it.Advance()) { | 1284 !it.done(); it.Advance()) { |
1291 if (scope->LookupLocal(it.name()) == NULL) { | 1285 if (scope->LookupLocal(it.name()) == NULL) { |
1292 ParserTraits::ReportMessage("module_export_undefined", it.name()); | 1286 ParserTraits::ReportMessage("module_export_undefined", it.name()); |
1293 *ok = false; | 1287 *ok = false; |
1294 return NULL; | 1288 return NULL; |
1295 } | 1289 } |
1296 } | 1290 } |
1297 | 1291 |
1298 interface->MakeModule(ok); | |
1299 DCHECK(*ok); | |
1300 interface->Freeze(ok); | |
1301 DCHECK(*ok); | |
1302 return body; | 1292 return body; |
1303 } | 1293 } |
1304 | 1294 |
1305 | 1295 |
1306 Literal* Parser::ParseModuleSpecifier(bool* ok) { | 1296 Literal* Parser::ParseModuleSpecifier(bool* ok) { |
1307 // ModuleSpecifier : | 1297 // ModuleSpecifier : |
1308 // StringLiteral | 1298 // StringLiteral |
1309 | 1299 |
1310 int pos = peek_position(); | 1300 int pos = peek_position(); |
1311 Expect(Token::STRING, CHECK_OK); | 1301 Expect(Token::STRING, CHECK_OK); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 // TODO(ES6): Handle 'export from' once imports are properly implemented. | 1605 // TODO(ES6): Handle 'export from' once imports are properly implemented. |
1616 // For now we just drop such exports on the floor. | 1606 // For now we just drop such exports on the floor. |
1617 if (!is_export_from) { | 1607 if (!is_export_from) { |
1618 // Extract declared names into export declarations and interface. | 1608 // Extract declared names into export declarations and interface. |
1619 Interface* interface = scope_->interface(); | 1609 Interface* interface = scope_->interface(); |
1620 for (int i = 0; i < names.length(); ++i) { | 1610 for (int i = 0; i < names.length(); ++i) { |
1621 #ifdef DEBUG | 1611 #ifdef DEBUG |
1622 if (FLAG_print_interface_details) | 1612 if (FLAG_print_interface_details) |
1623 PrintF("# Export %.*s ", names[i]->length(), names[i]->raw_data()); | 1613 PrintF("# Export %.*s ", names[i]->length(), names[i]->raw_data()); |
1624 #endif | 1614 #endif |
1625 Interface* inner = Interface::NewUnknown(zone()); | 1615 // TODO(adamk): Make early errors here provide the right error message |
1626 interface->Add(names[i], inner, zone(), CHECK_OK); | 1616 // (duplicate exported names). |
1627 if (!*ok) return NULL; | 1617 interface->Add(names[i], zone(), CHECK_OK); |
1628 VariableProxy* proxy = NewUnresolved(names[i], LET, inner); | |
1629 USE(proxy); | |
1630 // TODO(rossberg): Rethink whether we actually need to store export | 1618 // TODO(rossberg): Rethink whether we actually need to store export |
1631 // declarations (for compilation?). | 1619 // declarations (for compilation?). |
1632 // ExportDeclaration* declaration = | 1620 // ExportDeclaration* declaration = |
1633 // factory()->NewExportDeclaration(proxy, scope_, position); | 1621 // factory()->NewExportDeclaration(proxy, scope_, position); |
1634 // scope_->AddDeclaration(declaration); | 1622 // scope_->AddDeclaration(declaration); |
1635 } | 1623 } |
1636 } | 1624 } |
1637 | 1625 |
1638 DCHECK(result != NULL); | 1626 DCHECK(result != NULL); |
1639 return result; | 1627 return result; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1752 } | 1740 } |
1753 | 1741 |
1754 // Fall through. | 1742 // Fall through. |
1755 default: | 1743 default: |
1756 return ParseExpressionOrLabelledStatement(labels, ok); | 1744 return ParseExpressionOrLabelledStatement(labels, ok); |
1757 } | 1745 } |
1758 } | 1746 } |
1759 | 1747 |
1760 | 1748 |
1761 VariableProxy* Parser::NewUnresolved(const AstRawString* name, | 1749 VariableProxy* Parser::NewUnresolved(const AstRawString* name, |
1762 VariableMode mode, Interface* interface) { | 1750 VariableMode mode) { |
1763 // If we are inside a function, a declaration of a var/const variable is a | 1751 // If we are inside a function, a declaration of a var/const variable is a |
1764 // truly local variable, and the scope of the variable is always the function | 1752 // truly local variable, and the scope of the variable is always the function |
1765 // scope. | 1753 // scope. |
1766 // Let/const variables in harmony mode are always added to the immediately | 1754 // Let/const variables in harmony mode are always added to the immediately |
1767 // enclosing scope. | 1755 // enclosing scope. |
1768 return DeclarationScope(mode)->NewUnresolved( | 1756 return DeclarationScope(mode)->NewUnresolved(factory(), name, position()); |
1769 factory(), name, interface, position()); | |
1770 } | 1757 } |
1771 | 1758 |
1772 | 1759 |
1773 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { | 1760 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
1774 VariableProxy* proxy = declaration->proxy(); | 1761 VariableProxy* proxy = declaration->proxy(); |
1775 DCHECK(proxy->raw_name() != NULL); | 1762 DCHECK(proxy->raw_name() != NULL); |
1776 const AstRawString* name = proxy->raw_name(); | 1763 const AstRawString* name = proxy->raw_name(); |
1777 VariableMode mode = declaration->mode(); | 1764 VariableMode mode = declaration->mode(); |
1778 Scope* declaration_scope = DeclarationScope(mode); | 1765 Scope* declaration_scope = DeclarationScope(mode); |
1779 Variable* var = NULL; | 1766 Variable* var = NULL; |
1780 | 1767 |
1781 // If a suitable scope exists, then we can statically declare this | 1768 // If a suitable scope exists, then we can statically declare this |
1782 // variable and also set its mode. In any case, a Declaration node | 1769 // variable and also set its mode. In any case, a Declaration node |
1783 // will be added to the scope so that the declaration can be added | 1770 // will be added to the scope so that the declaration can be added |
1784 // to the corresponding activation frame at runtime if necessary. | 1771 // to the corresponding activation frame at runtime if necessary. |
1785 // For instance declarations inside an eval scope need to be added | 1772 // For instance declarations inside an eval scope need to be added |
1786 // to the calling function context. | 1773 // to the calling function context. |
1787 // Similarly, strict mode eval scope does not leak variable declarations to | 1774 // Similarly, strict mode eval scope does not leak variable declarations to |
1788 // the caller's scope so we declare all locals, too. | 1775 // the caller's scope so we declare all locals, too. |
1789 if (declaration_scope->is_function_scope() || | 1776 if (declaration_scope->is_function_scope() || |
1790 declaration_scope->is_strict_eval_scope() || | 1777 declaration_scope->is_strict_eval_scope() || |
1791 declaration_scope->is_block_scope() || | 1778 declaration_scope->is_block_scope() || |
1792 declaration_scope->is_module_scope() || | 1779 declaration_scope->is_module_scope() || |
1793 declaration_scope->is_script_scope()) { | 1780 declaration_scope->is_script_scope()) { |
1794 // Declare the variable in the declaration scope. | 1781 // Declare the variable in the declaration scope. |
1795 var = declaration_scope->LookupLocal(name); | 1782 var = declaration_scope->LookupLocal(name); |
1796 if (var == NULL) { | 1783 if (var == NULL) { |
1797 // Declare the name. | 1784 // Declare the name. |
1798 var = declaration_scope->DeclareLocal(name, mode, | 1785 var = declaration_scope->DeclareLocal( |
1799 declaration->initialization(), | 1786 name, mode, declaration->initialization(), kNotAssigned); |
1800 kNotAssigned, proxy->interface()); | |
1801 } else if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(var->mode()) | 1787 } else if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(var->mode()) |
1802 || ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && | 1788 || ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && |
1803 !declaration_scope->is_script_scope())) { | 1789 !declaration_scope->is_script_scope())) { |
1804 // The name was declared in this scope before; check for conflicting | 1790 // The name was declared in this scope before; check for conflicting |
1805 // re-declarations. We have a conflict if either of the declarations is | 1791 // re-declarations. We have a conflict if either of the declarations is |
1806 // not a var (in script scope, we also have to ignore legacy const for | 1792 // not a var (in script scope, we also have to ignore legacy const for |
1807 // compatibility). There is similar code in runtime.cc in the Declare | 1793 // compatibility). There is similar code in runtime.cc in the Declare |
1808 // functions. The function CheckConflictingVarDeclarations checks for | 1794 // functions. The function CheckConflictingVarDeclarations checks for |
1809 // var and let bindings from different scopes whereas this is a check for | 1795 // var and let bindings from different scopes whereas this is a check for |
1810 // conflicting declarations within the same scope. This check also covers | 1796 // conflicting declarations within the same scope. This check also covers |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1845 // same variable if it is declared several times. This is not a | 1831 // same variable if it is declared several times. This is not a |
1846 // semantic issue as long as we keep the source order, but it may be | 1832 // semantic issue as long as we keep the source order, but it may be |
1847 // a performance issue since it may lead to repeated | 1833 // a performance issue since it may lead to repeated |
1848 // RuntimeHidden_DeclareLookupSlot calls. | 1834 // RuntimeHidden_DeclareLookupSlot calls. |
1849 declaration_scope->AddDeclaration(declaration); | 1835 declaration_scope->AddDeclaration(declaration); |
1850 | 1836 |
1851 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) { | 1837 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) { |
1852 // For global const variables we bind the proxy to a variable. | 1838 // For global const variables we bind the proxy to a variable. |
1853 DCHECK(resolve); // should be set by all callers | 1839 DCHECK(resolve); // should be set by all callers |
1854 Variable::Kind kind = Variable::NORMAL; | 1840 Variable::Kind kind = Variable::NORMAL; |
1855 var = new (zone()) | 1841 var = new (zone()) Variable(declaration_scope, name, mode, true, kind, |
1856 Variable(declaration_scope, name, mode, true, kind, | 1842 kNeedsInitialization, kNotAssigned); |
1857 kNeedsInitialization, kNotAssigned, proxy->interface()); | |
1858 } else if (declaration_scope->is_eval_scope() && | 1843 } else if (declaration_scope->is_eval_scope() && |
1859 is_sloppy(declaration_scope->language_mode())) { | 1844 is_sloppy(declaration_scope->language_mode())) { |
1860 // For variable declarations in a sloppy eval scope the proxy is bound | 1845 // For variable declarations in a sloppy eval scope the proxy is bound |
1861 // to a lookup variable to force a dynamic declaration using the | 1846 // to a lookup variable to force a dynamic declaration using the |
1862 // DeclareLookupSlot runtime function. | 1847 // DeclareLookupSlot runtime function. |
1863 Variable::Kind kind = Variable::NORMAL; | 1848 Variable::Kind kind = Variable::NORMAL; |
1864 // TODO(sigurds) figure out if kNotAssigned is OK here | 1849 // TODO(sigurds) figure out if kNotAssigned is OK here |
1865 var = new (zone()) Variable(declaration_scope, name, mode, true, kind, | 1850 var = new (zone()) Variable(declaration_scope, name, mode, true, kind, |
1866 declaration->initialization(), kNotAssigned, | 1851 declaration->initialization(), kNotAssigned); |
1867 proxy->interface()); | |
1868 var->AllocateTo(Variable::LOOKUP, -1); | 1852 var->AllocateTo(Variable::LOOKUP, -1); |
1869 resolve = true; | 1853 resolve = true; |
1870 } | 1854 } |
1871 | 1855 |
1872 // If requested and we have a local variable, bind the proxy to the variable | 1856 // If requested and we have a local variable, bind the proxy to the variable |
1873 // at parse-time. This is used for functions (and consts) declared inside | 1857 // at parse-time. This is used for functions (and consts) declared inside |
1874 // statements: the corresponding function (or const) variable must be in the | 1858 // statements: the corresponding function (or const) variable must be in the |
1875 // function scope and not a statement-local scope, e.g. as provided with a | 1859 // function scope and not a statement-local scope, e.g. as provided with a |
1876 // 'with' statement: | 1860 // 'with' statement: |
1877 // | 1861 // |
(...skipping 10 matching lines...) Expand all Loading... |
1888 // | 1872 // |
1889 // Note that if 'f' is accessed from inside the 'with' statement, it | 1873 // Note that if 'f' is accessed from inside the 'with' statement, it |
1890 // will be allocated in the context (because we must be able to look | 1874 // will be allocated in the context (because we must be able to look |
1891 // it up dynamically) but it will also be accessed statically, i.e., | 1875 // it up dynamically) but it will also be accessed statically, i.e., |
1892 // with a context slot index and a context chain length for this | 1876 // with a context slot index and a context chain length for this |
1893 // initialization code. Thus, inside the 'with' statement, we need | 1877 // initialization code. Thus, inside the 'with' statement, we need |
1894 // both access to the static and the dynamic context chain; the | 1878 // both access to the static and the dynamic context chain; the |
1895 // runtime needs to provide both. | 1879 // runtime needs to provide both. |
1896 if (resolve && var != NULL) { | 1880 if (resolve && var != NULL) { |
1897 proxy->BindTo(var); | 1881 proxy->BindTo(var); |
1898 | |
1899 if (FLAG_harmony_modules) { | |
1900 bool ok; | |
1901 #ifdef DEBUG | |
1902 if (FLAG_print_interface_details) { | |
1903 PrintF("# Declare %.*s ", var->raw_name()->length(), | |
1904 var->raw_name()->raw_data()); | |
1905 } | |
1906 #endif | |
1907 proxy->interface()->Unify(var->interface(), zone(), &ok); | |
1908 if (!ok) { | |
1909 #ifdef DEBUG | |
1910 if (FLAG_print_interfaces) { | |
1911 PrintF("DECLARE TYPE ERROR\n"); | |
1912 PrintF("proxy: "); | |
1913 proxy->interface()->Print(); | |
1914 PrintF("var: "); | |
1915 var->interface()->Print(); | |
1916 } | |
1917 #endif | |
1918 ParserTraits::ReportMessage("module_type_error", name); | |
1919 } | |
1920 } | |
1921 } | 1882 } |
1922 } | 1883 } |
1923 | 1884 |
1924 | 1885 |
1925 // Language extension which is only enabled for source files loaded | 1886 // Language extension which is only enabled for source files loaded |
1926 // through the API's extension mechanism. A native function | 1887 // through the API's extension mechanism. A native function |
1927 // declaration is resolved by looking up the function through a | 1888 // declaration is resolved by looking up the function through a |
1928 // callback provided by the extension. | 1889 // callback provided by the extension. |
1929 Statement* Parser::ParseNativeDeclaration(bool* ok) { | 1890 Statement* Parser::ParseNativeDeclaration(bool* ok) { |
1930 int pos = peek_position(); | 1891 int pos = peek_position(); |
(...skipping 14 matching lines...) Expand all Loading... |
1945 | 1906 |
1946 // Make sure that the function containing the native declaration | 1907 // Make sure that the function containing the native declaration |
1947 // isn't lazily compiled. The extension structures are only | 1908 // isn't lazily compiled. The extension structures are only |
1948 // accessible while parsing the first time not when reparsing | 1909 // accessible while parsing the first time not when reparsing |
1949 // because of lazy compilation. | 1910 // because of lazy compilation. |
1950 DeclarationScope(VAR)->ForceEagerCompilation(); | 1911 DeclarationScope(VAR)->ForceEagerCompilation(); |
1951 | 1912 |
1952 // TODO(1240846): It's weird that native function declarations are | 1913 // TODO(1240846): It's weird that native function declarations are |
1953 // introduced dynamically when we meet their declarations, whereas | 1914 // introduced dynamically when we meet their declarations, whereas |
1954 // other functions are set up when entering the surrounding scope. | 1915 // other functions are set up when entering the surrounding scope. |
1955 VariableProxy* proxy = NewUnresolved(name, VAR, Interface::NewValue()); | 1916 VariableProxy* proxy = NewUnresolved(name, VAR); |
1956 Declaration* declaration = | 1917 Declaration* declaration = |
1957 factory()->NewVariableDeclaration(proxy, VAR, scope_, pos); | 1918 factory()->NewVariableDeclaration(proxy, VAR, scope_, pos); |
1958 Declare(declaration, true, CHECK_OK); | 1919 Declare(declaration, true, CHECK_OK); |
1959 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral( | 1920 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral( |
1960 name, extension_, RelocInfo::kNoPosition); | 1921 name, extension_, RelocInfo::kNoPosition); |
1961 return factory()->NewExpressionStatement( | 1922 return factory()->NewExpressionStatement( |
1962 factory()->NewAssignment( | 1923 factory()->NewAssignment( |
1963 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition), | 1924 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition), |
1964 pos); | 1925 pos); |
1965 } | 1926 } |
(...skipping 22 matching lines...) Expand all Loading... |
1988 // scope, we treat it as such and introduce the function with its | 1949 // scope, we treat it as such and introduce the function with its |
1989 // initial value upon entering the corresponding scope. | 1950 // initial value upon entering the corresponding scope. |
1990 // In ES6, a function behaves as a lexical binding, except in | 1951 // In ES6, a function behaves as a lexical binding, except in |
1991 // a script scope, or the initial scope of eval or another function. | 1952 // a script scope, or the initial scope of eval or another function. |
1992 VariableMode mode = | 1953 VariableMode mode = |
1993 allow_harmony_scoping() && is_strict(language_mode()) && | 1954 allow_harmony_scoping() && is_strict(language_mode()) && |
1994 !(scope_->is_script_scope() || scope_->is_eval_scope() || | 1955 !(scope_->is_script_scope() || scope_->is_eval_scope() || |
1995 scope_->is_function_scope()) | 1956 scope_->is_function_scope()) |
1996 ? LET | 1957 ? LET |
1997 : VAR; | 1958 : VAR; |
1998 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); | 1959 VariableProxy* proxy = NewUnresolved(name, mode); |
1999 Declaration* declaration = | 1960 Declaration* declaration = |
2000 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); | 1961 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); |
2001 Declare(declaration, true, CHECK_OK); | 1962 Declare(declaration, true, CHECK_OK); |
2002 if (names) names->Add(name, zone()); | 1963 if (names) names->Add(name, zone()); |
2003 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1964 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
2004 } | 1965 } |
2005 | 1966 |
2006 | 1967 |
2007 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 1968 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
2008 bool* ok) { | 1969 bool* ok) { |
(...skipping 17 matching lines...) Expand all Loading... |
2026 return NULL; | 1987 return NULL; |
2027 } | 1988 } |
2028 | 1989 |
2029 int pos = position(); | 1990 int pos = position(); |
2030 bool is_strict_reserved = false; | 1991 bool is_strict_reserved = false; |
2031 const AstRawString* name = | 1992 const AstRawString* name = |
2032 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 1993 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
2033 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), | 1994 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), |
2034 is_strict_reserved, pos, CHECK_OK); | 1995 is_strict_reserved, pos, CHECK_OK); |
2035 | 1996 |
2036 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); | 1997 VariableProxy* proxy = NewUnresolved(name, LET); |
2037 Declaration* declaration = | 1998 Declaration* declaration = |
2038 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 1999 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); |
2039 Declare(declaration, true, CHECK_OK); | 2000 Declare(declaration, true, CHECK_OK); |
2040 proxy->var()->set_initializer_position(pos); | 2001 proxy->var()->set_initializer_position(pos); |
2041 | 2002 |
2042 Token::Value init_op = Token::INIT_LET; | 2003 Token::Value init_op = Token::INIT_LET; |
2043 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); | 2004 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); |
2044 Statement* assignment_statement = | 2005 Statement* assignment_statement = |
2045 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 2006 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
2046 if (names) names->Add(name, zone()); | 2007 if (names) names->Add(name, zone()); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 // For let/const declarations in harmony mode, we can also immediately | 2190 // For let/const declarations in harmony mode, we can also immediately |
2230 // pre-resolve the proxy because it resides in the same scope as the | 2191 // pre-resolve the proxy because it resides in the same scope as the |
2231 // declaration. | 2192 // declaration. |
2232 is_for_iteration_variable = | 2193 is_for_iteration_variable = |
2233 var_context == kForStatement && | 2194 var_context == kForStatement && |
2234 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); | 2195 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); |
2235 if (is_for_iteration_variable && mode == CONST) { | 2196 if (is_for_iteration_variable && mode == CONST) { |
2236 needs_init = false; | 2197 needs_init = false; |
2237 } | 2198 } |
2238 | 2199 |
2239 Interface* interface = | 2200 VariableProxy* proxy = NewUnresolved(name, mode); |
2240 is_const ? Interface::NewConst() : Interface::NewValue(); | |
2241 VariableProxy* proxy = NewUnresolved(name, mode, interface); | |
2242 Declaration* declaration = | 2201 Declaration* declaration = |
2243 factory()->NewVariableDeclaration(proxy, mode, scope_, pos); | 2202 factory()->NewVariableDeclaration(proxy, mode, scope_, pos); |
2244 Declare(declaration, mode != VAR, CHECK_OK); | 2203 Declare(declaration, mode != VAR, CHECK_OK); |
2245 nvars++; | 2204 nvars++; |
2246 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { | 2205 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { |
2247 ReportMessage("too_many_variables"); | 2206 ReportMessage("too_many_variables"); |
2248 *ok = false; | 2207 *ok = false; |
2249 return NULL; | 2208 return NULL; |
2250 } | 2209 } |
2251 if (names) names->Add(name, zone()); | 2210 if (names) names->Add(name, zone()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2395 } | 2354 } |
2396 | 2355 |
2397 // Add an assignment node to the initialization statement block if we still | 2356 // Add an assignment node to the initialization statement block if we still |
2398 // have a pending initialization value. | 2357 // have a pending initialization value. |
2399 if (value != NULL) { | 2358 if (value != NULL) { |
2400 DCHECK(mode == VAR); | 2359 DCHECK(mode == VAR); |
2401 // 'var' initializations are simply assignments (with all the consequences | 2360 // 'var' initializations are simply assignments (with all the consequences |
2402 // if they are inside a 'with' statement - they may change a 'with' object | 2361 // if they are inside a 'with' statement - they may change a 'with' object |
2403 // property). | 2362 // property). |
2404 VariableProxy* proxy = | 2363 VariableProxy* proxy = |
2405 initialization_scope->NewUnresolved(factory(), name, interface); | 2364 initialization_scope->NewUnresolved(factory(), name); |
2406 Assignment* assignment = | 2365 Assignment* assignment = |
2407 factory()->NewAssignment(init_op, proxy, value, pos); | 2366 factory()->NewAssignment(init_op, proxy, value, pos); |
2408 block->AddStatement( | 2367 block->AddStatement( |
2409 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), | 2368 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), |
2410 zone()); | 2369 zone()); |
2411 } | 2370 } |
2412 | 2371 |
2413 if (fni_ != NULL) fni_->Leave(); | 2372 if (fni_ != NULL) fni_->Leave(); |
2414 } while (peek() == Token::COMMA); | 2373 } while (peek() == Token::COMMA); |
2415 | 2374 |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3031 RelocInfo::kNoPosition); | 2990 RelocInfo::kNoPosition); |
3032 | 2991 |
3033 // Add statement: let x = i. | 2992 // Add statement: let x = i. |
3034 outer_block->AddStatement(init, zone()); | 2993 outer_block->AddStatement(init, zone()); |
3035 | 2994 |
3036 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); | 2995 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); |
3037 | 2996 |
3038 // For each let variable x: | 2997 // For each let variable x: |
3039 // make statement: temp_x = x. | 2998 // make statement: temp_x = x. |
3040 for (int i = 0; i < names->length(); i++) { | 2999 for (int i = 0; i < names->length(); i++) { |
3041 VariableProxy* proxy = | 3000 VariableProxy* proxy = NewUnresolved(names->at(i), LET); |
3042 NewUnresolved(names->at(i), LET, Interface::NewValue()); | |
3043 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name); | 3001 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name); |
3044 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); | 3002 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
3045 Assignment* assignment = factory()->NewAssignment( | 3003 Assignment* assignment = factory()->NewAssignment( |
3046 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); | 3004 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); |
3047 Statement* assignment_statement = factory()->NewExpressionStatement( | 3005 Statement* assignment_statement = factory()->NewExpressionStatement( |
3048 assignment, RelocInfo::kNoPosition); | 3006 assignment, RelocInfo::kNoPosition); |
3049 outer_block->AddStatement(assignment_statement, zone()); | 3007 outer_block->AddStatement(assignment_statement, zone()); |
3050 temps.Add(temp, zone()); | 3008 temps.Add(temp, zone()); |
3051 } | 3009 } |
3052 | 3010 |
(...skipping 23 matching lines...) Expand all Loading... |
3076 scope_ = inner_scope; | 3034 scope_ = inner_scope; |
3077 | 3035 |
3078 Block* inner_block = factory()->NewBlock(NULL, names->length() + 4, false, | 3036 Block* inner_block = factory()->NewBlock(NULL, names->length() + 4, false, |
3079 RelocInfo::kNoPosition); | 3037 RelocInfo::kNoPosition); |
3080 int pos = scanner()->location().beg_pos; | 3038 int pos = scanner()->location().beg_pos; |
3081 ZoneList<Variable*> inner_vars(names->length(), zone()); | 3039 ZoneList<Variable*> inner_vars(names->length(), zone()); |
3082 | 3040 |
3083 // For each let variable x: | 3041 // For each let variable x: |
3084 // make statement: let x = temp_x. | 3042 // make statement: let x = temp_x. |
3085 for (int i = 0; i < names->length(); i++) { | 3043 for (int i = 0; i < names->length(); i++) { |
3086 VariableProxy* proxy = | 3044 VariableProxy* proxy = NewUnresolved(names->at(i), LET); |
3087 NewUnresolved(names->at(i), LET, Interface::NewValue()); | |
3088 Declaration* declaration = | 3045 Declaration* declaration = |
3089 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 3046 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); |
3090 Declare(declaration, true, CHECK_OK); | 3047 Declare(declaration, true, CHECK_OK); |
3091 inner_vars.Add(declaration->proxy()->var(), zone()); | 3048 inner_vars.Add(declaration->proxy()->var(), zone()); |
3092 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); | 3049 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); |
3093 Assignment* assignment = factory()->NewAssignment( | 3050 Assignment* assignment = factory()->NewAssignment( |
3094 Token::INIT_LET, proxy, temp_proxy, pos); | 3051 Token::INIT_LET, proxy, temp_proxy, pos); |
3095 Statement* assignment_statement = factory()->NewExpressionStatement( | 3052 Statement* assignment_statement = factory()->NewExpressionStatement( |
3096 assignment, pos); | 3053 assignment, pos); |
3097 proxy->var()->set_initializer_position(pos); | 3054 proxy->var()->set_initializer_position(pos); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3228 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); | 3185 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); |
3229 scope_ = for_scope; | 3186 scope_ = for_scope; |
3230 | 3187 |
3231 Expect(Token::FOR, CHECK_OK); | 3188 Expect(Token::FOR, CHECK_OK); |
3232 Expect(Token::LPAREN, CHECK_OK); | 3189 Expect(Token::LPAREN, CHECK_OK); |
3233 for_scope->set_start_position(scanner()->location().beg_pos); | 3190 for_scope->set_start_position(scanner()->location().beg_pos); |
3234 bool is_let_identifier_expression = false; | 3191 bool is_let_identifier_expression = false; |
3235 if (peek() != Token::SEMICOLON) { | 3192 if (peek() != Token::SEMICOLON) { |
3236 if (peek() == Token::VAR || | 3193 if (peek() == Token::VAR || |
3237 (peek() == Token::CONST && is_sloppy(language_mode()))) { | 3194 (peek() == Token::CONST && is_sloppy(language_mode()))) { |
3238 bool is_const = peek() == Token::CONST; | |
3239 const AstRawString* name = NULL; | 3195 const AstRawString* name = NULL; |
3240 VariableDeclarationProperties decl_props = kHasNoInitializers; | 3196 VariableDeclarationProperties decl_props = kHasNoInitializers; |
3241 Block* variable_statement = | 3197 Block* variable_statement = |
3242 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, | 3198 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, |
3243 CHECK_OK); | 3199 CHECK_OK); |
3244 bool accept_OF = decl_props == kHasNoInitializers; | 3200 bool accept_OF = decl_props == kHasNoInitializers; |
3245 ForEachStatement::VisitMode mode; | 3201 ForEachStatement::VisitMode mode; |
3246 int each_pos = position(); | 3202 int each_pos = position(); |
3247 | 3203 |
3248 if (name != NULL && CheckInOrOf(accept_OF, &mode)) { | 3204 if (name != NULL && CheckInOrOf(accept_OF, &mode)) { |
3249 Interface* interface = | |
3250 is_const ? Interface::NewConst() : Interface::NewValue(); | |
3251 ForEachStatement* loop = | 3205 ForEachStatement* loop = |
3252 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3206 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3253 Target target(&this->target_stack_, loop); | 3207 Target target(&this->target_stack_, loop); |
3254 | 3208 |
3255 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3209 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3256 Expect(Token::RPAREN, CHECK_OK); | 3210 Expect(Token::RPAREN, CHECK_OK); |
3257 | 3211 |
3258 VariableProxy* each = | 3212 VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos); |
3259 scope_->NewUnresolved(factory(), name, interface, each_pos); | |
3260 Statement* body = ParseStatement(NULL, CHECK_OK); | 3213 Statement* body = ParseStatement(NULL, CHECK_OK); |
3261 InitializeForEachStatement(loop, each, enumerable, body); | 3214 InitializeForEachStatement(loop, each, enumerable, body); |
3262 Block* result = | 3215 Block* result = |
3263 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | 3216 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
3264 result->AddStatement(variable_statement, zone()); | 3217 result->AddStatement(variable_statement, zone()); |
3265 result->AddStatement(loop, zone()); | 3218 result->AddStatement(loop, zone()); |
3266 scope_ = saved_scope; | 3219 scope_ = saved_scope; |
3267 for_scope->set_end_position(scanner()->location().end_pos); | 3220 for_scope->set_end_position(scanner()->location().end_pos); |
3268 for_scope = for_scope->FinalizeBlockScope(); | 3221 for_scope = for_scope->FinalizeBlockScope(); |
3269 DCHECK(for_scope == NULL); | 3222 DCHECK(for_scope == NULL); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3307 ForEachStatement* loop = | 3260 ForEachStatement* loop = |
3308 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3261 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3309 Target target(&this->target_stack_, loop); | 3262 Target target(&this->target_stack_, loop); |
3310 | 3263 |
3311 // The expression does not see the loop variable. | 3264 // The expression does not see the loop variable. |
3312 scope_ = saved_scope; | 3265 scope_ = saved_scope; |
3313 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3266 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3314 scope_ = for_scope; | 3267 scope_ = for_scope; |
3315 Expect(Token::RPAREN, CHECK_OK); | 3268 Expect(Token::RPAREN, CHECK_OK); |
3316 | 3269 |
3317 VariableProxy* each = scope_->NewUnresolved( | 3270 VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos); |
3318 factory(), name, Interface::NewValue(), each_pos); | |
3319 Statement* body = ParseStatement(NULL, CHECK_OK); | 3271 Statement* body = ParseStatement(NULL, CHECK_OK); |
3320 Block* body_block = | 3272 Block* body_block = |
3321 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3273 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
3322 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; | 3274 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; |
3323 Assignment* assignment = factory()->NewAssignment( | 3275 Assignment* assignment = factory()->NewAssignment( |
3324 init_op, each, temp_proxy, RelocInfo::kNoPosition); | 3276 init_op, each, temp_proxy, RelocInfo::kNoPosition); |
3325 Statement* assignment_statement = factory()->NewExpressionStatement( | 3277 Statement* assignment_statement = factory()->NewExpressionStatement( |
3326 assignment, RelocInfo::kNoPosition); | 3278 assignment, RelocInfo::kNoPosition); |
3327 body_block->AddStatement(variable_statement, zone()); | 3279 body_block->AddStatement(variable_statement, zone()); |
3328 body_block->AddStatement(assignment_statement, zone()); | 3280 body_block->AddStatement(assignment_statement, zone()); |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3748 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { | 3700 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { |
3749 if (allow_harmony_scoping() && is_strict(language_mode())) { | 3701 if (allow_harmony_scoping() && is_strict(language_mode())) { |
3750 fvar_init_op = Token::INIT_CONST; | 3702 fvar_init_op = Token::INIT_CONST; |
3751 } | 3703 } |
3752 VariableMode fvar_mode = | 3704 VariableMode fvar_mode = |
3753 allow_harmony_scoping() && is_strict(language_mode()) ? CONST | 3705 allow_harmony_scoping() && is_strict(language_mode()) ? CONST |
3754 : CONST_LEGACY; | 3706 : CONST_LEGACY; |
3755 DCHECK(function_name != NULL); | 3707 DCHECK(function_name != NULL); |
3756 fvar = new (zone()) | 3708 fvar = new (zone()) |
3757 Variable(scope_, function_name, fvar_mode, true /* is valid LHS */, | 3709 Variable(scope_, function_name, fvar_mode, true /* is valid LHS */, |
3758 Variable::NORMAL, kCreatedInitialized, kNotAssigned, | 3710 Variable::NORMAL, kCreatedInitialized, kNotAssigned); |
3759 Interface::NewConst()); | |
3760 VariableProxy* proxy = factory()->NewVariableProxy(fvar); | 3711 VariableProxy* proxy = factory()->NewVariableProxy(fvar); |
3761 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( | 3712 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( |
3762 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); | 3713 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); |
3763 scope_->DeclareFunctionVar(fvar_declaration); | 3714 scope_->DeclareFunctionVar(fvar_declaration); |
3764 } | 3715 } |
3765 | 3716 |
3766 // Determine if the function can be parsed lazily. Lazy parsing is different | 3717 // Determine if the function can be parsed lazily. Lazy parsing is different |
3767 // from lazy compilation; we need to parse more eagerly than we compile. | 3718 // from lazy compilation; we need to parse more eagerly than we compile. |
3768 | 3719 |
3769 // We can only parse lazily if we also compile lazily. The heuristics for | 3720 // We can only parse lazily if we also compile lazily. The heuristics for |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3930 | 3881 |
3931 | 3882 |
3932 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 3883 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
3933 const AstRawString* function_name, int pos, Variable* fvar, | 3884 const AstRawString* function_name, int pos, Variable* fvar, |
3934 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 3885 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
3935 // Everything inside an eagerly parsed function will be parsed eagerly | 3886 // Everything inside an eagerly parsed function will be parsed eagerly |
3936 // (see comment above). | 3887 // (see comment above). |
3937 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 3888 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
3938 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone()); | 3889 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone()); |
3939 if (fvar != NULL) { | 3890 if (fvar != NULL) { |
3940 VariableProxy* fproxy = scope_->NewUnresolved( | 3891 VariableProxy* fproxy = scope_->NewUnresolved(factory(), function_name); |
3941 factory(), function_name, Interface::NewConst()); | |
3942 fproxy->BindTo(fvar); | 3892 fproxy->BindTo(fvar); |
3943 body->Add(factory()->NewExpressionStatement( | 3893 body->Add(factory()->NewExpressionStatement( |
3944 factory()->NewAssignment(fvar_init_op, | 3894 factory()->NewAssignment(fvar_init_op, |
3945 fproxy, | 3895 fproxy, |
3946 factory()->NewThisFunction(pos), | 3896 factory()->NewThisFunction(pos), |
3947 RelocInfo::kNoPosition), | 3897 RelocInfo::kNoPosition), |
3948 RelocInfo::kNoPosition), zone()); | 3898 RelocInfo::kNoPosition), zone()); |
3949 } | 3899 } |
3950 | 3900 |
3951 | 3901 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4061 } | 4011 } |
4062 | 4012 |
4063 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 4013 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
4064 BlockState block_state(&scope_, block_scope); | 4014 BlockState block_state(&scope_, block_scope); |
4065 scope_->SetLanguageMode( | 4015 scope_->SetLanguageMode( |
4066 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); | 4016 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
4067 scope_->SetScopeName(name); | 4017 scope_->SetScopeName(name); |
4068 | 4018 |
4069 VariableProxy* proxy = NULL; | 4019 VariableProxy* proxy = NULL; |
4070 if (name != NULL) { | 4020 if (name != NULL) { |
4071 proxy = NewUnresolved(name, CONST, Interface::NewConst()); | 4021 proxy = NewUnresolved(name, CONST); |
4072 Declaration* declaration = | 4022 Declaration* declaration = |
4073 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | 4023 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); |
4074 Declare(declaration, true, CHECK_OK); | 4024 Declare(declaration, true, CHECK_OK); |
4075 } | 4025 } |
4076 | 4026 |
4077 Expression* extends = NULL; | 4027 Expression* extends = NULL; |
4078 if (Check(Token::EXTENDS)) { | 4028 if (Check(Token::EXTENDS)) { |
4079 block_scope->set_start_position(scanner()->location().end_pos); | 4029 block_scope->set_start_position(scanner()->location().end_pos); |
4080 extends = ParseLeftHandSideExpression(CHECK_OK); | 4030 extends = ParseLeftHandSideExpression(CHECK_OK); |
4081 } else { | 4031 } else { |
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5458 } else { | 5408 } else { |
5459 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5409 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5460 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5410 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5461 raw_string->length()); | 5411 raw_string->length()); |
5462 } | 5412 } |
5463 } | 5413 } |
5464 | 5414 |
5465 return running_hash; | 5415 return running_hash; |
5466 } | 5416 } |
5467 } } // namespace v8::internal | 5417 } } // namespace v8::internal |
OLD | NEW |