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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 DCHECK(false); | 703 DCHECK(false); |
704 } | 704 } |
705 return NULL; | 705 return NULL; |
706 } | 706 } |
707 | 707 |
708 | 708 |
709 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 709 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
710 int pos, Scope* scope, | 710 int pos, Scope* scope, |
711 AstNodeFactory* factory) { | 711 AstNodeFactory* factory) { |
712 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); | 712 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
713 // The name may refer to a module instance object, so its type is unknown. | |
714 #ifdef DEBUG | |
715 if (FLAG_print_interface_details) | |
716 PrintF("# Variable %.*s ", name->length(), name->raw_data()); | |
717 #endif | |
718 Interface* interface = Interface::NewUnknown(parser_->zone()); | |
719 | 713 |
720 // Arrow function parameters are parsed as an expression. When | 714 // Arrow function parameters are parsed as an expression. When |
721 // parsing lazily, it is enough to create a VariableProxy in order | 715 // parsing lazily, it is enough to create a VariableProxy in order |
722 // for Traits::DeclareArrowParametersFromExpression() to be able to | 716 // for Traits::DeclareArrowParametersFromExpression() to be able to |
723 // pick the names of the parameters. | 717 // pick the names of the parameters. |
724 return parser_->parsing_lazy_arrow_parameters_ | 718 return parser_->parsing_lazy_arrow_parameters_ |
725 ? factory->NewVariableProxy(name, false, interface, pos) | 719 ? factory->NewVariableProxy(name, false, pos) |
726 : scope->NewUnresolved(factory, name, interface, pos); | 720 : scope->NewUnresolved(factory, name, pos); |
727 } | 721 } |
728 | 722 |
729 | 723 |
730 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 724 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
731 AstNodeFactory* factory) { | 725 AstNodeFactory* factory) { |
732 const AstRawString* symbol = GetSymbol(scanner); | 726 const AstRawString* symbol = GetSymbol(scanner); |
733 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 727 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
734 return factory->NewStringLiteral(symbol, pos); | 728 return factory->NewStringLiteral(symbol, pos); |
735 } | 729 } |
736 | 730 |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 Interface* interface = scope->interface(); | 1281 Interface* interface = scope->interface(); |
1288 for (Interface::Iterator it = interface->iterator(); | 1282 for (Interface::Iterator it = interface->iterator(); |
1289 !it.done(); it.Advance()) { | 1283 !it.done(); it.Advance()) { |
1290 if (scope->LookupLocal(it.name()) == NULL) { | 1284 if (scope->LookupLocal(it.name()) == NULL) { |
1291 ParserTraits::ReportMessage("module_export_undefined", it.name()); | 1285 ParserTraits::ReportMessage("module_export_undefined", it.name()); |
1292 *ok = false; | 1286 *ok = false; |
1293 return NULL; | 1287 return NULL; |
1294 } | 1288 } |
1295 } | 1289 } |
1296 | 1290 |
1297 interface->MakeModule(ok); | 1291 scope->interface()->Freeze(); |
1298 DCHECK(*ok); | |
1299 interface->Freeze(ok); | |
1300 DCHECK(*ok); | |
1301 return body; | 1292 return body; |
1302 } | 1293 } |
1303 | 1294 |
1304 | 1295 |
1305 Literal* Parser::ParseModuleSpecifier(bool* ok) { | 1296 Literal* Parser::ParseModuleSpecifier(bool* ok) { |
1306 // ModuleSpecifier : | 1297 // ModuleSpecifier : |
1307 // StringLiteral | 1298 // StringLiteral |
1308 | 1299 |
1309 int pos = peek_position(); | 1300 int pos = peek_position(); |
1310 Expect(Token::STRING, CHECK_OK); | 1301 Expect(Token::STRING, CHECK_OK); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1614 // TODO(ES6): Handle 'export from' once imports are properly implemented. | 1605 // TODO(ES6): Handle 'export from' once imports are properly implemented. |
1615 // For now we just drop such exports on the floor. | 1606 // For now we just drop such exports on the floor. |
1616 if (!is_export_from) { | 1607 if (!is_export_from) { |
1617 // Extract declared names into export declarations and interface. | 1608 // Extract declared names into export declarations and interface. |
1618 Interface* interface = scope_->interface(); | 1609 Interface* interface = scope_->interface(); |
1619 for (int i = 0; i < names.length(); ++i) { | 1610 for (int i = 0; i < names.length(); ++i) { |
1620 #ifdef DEBUG | 1611 #ifdef DEBUG |
1621 if (FLAG_print_interface_details) | 1612 if (FLAG_print_interface_details) |
1622 PrintF("# Export %.*s ", names[i]->length(), names[i]->raw_data()); | 1613 PrintF("# Export %.*s ", names[i]->length(), names[i]->raw_data()); |
1623 #endif | 1614 #endif |
1624 Interface* inner = Interface::NewUnknown(zone()); | 1615 // TODO(adamk): Make early errors here provide the right error message |
1625 interface->Add(names[i], inner, zone(), CHECK_OK); | 1616 // (duplicate exported names). |
1626 if (!*ok) return NULL; | 1617 interface->Add(names[i], zone(), CHECK_OK); |
1627 VariableProxy* proxy = NewUnresolved(names[i], LET, inner); | |
1628 USE(proxy); | |
1629 // TODO(rossberg): Rethink whether we actually need to store export | 1618 // TODO(rossberg): Rethink whether we actually need to store export |
1630 // declarations (for compilation?). | 1619 // declarations (for compilation?). |
1631 // ExportDeclaration* declaration = | 1620 // ExportDeclaration* declaration = |
1632 // factory()->NewExportDeclaration(proxy, scope_, position); | 1621 // factory()->NewExportDeclaration(proxy, scope_, position); |
1633 // scope_->AddDeclaration(declaration); | 1622 // scope_->AddDeclaration(declaration); |
1634 } | 1623 } |
1635 } | 1624 } |
1636 | 1625 |
1637 DCHECK(result != NULL); | 1626 DCHECK(result != NULL); |
1638 return result; | 1627 return result; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 } | 1759 } |
1771 | 1760 |
1772 // Fall through. | 1761 // Fall through. |
1773 default: | 1762 default: |
1774 return ParseExpressionOrLabelledStatement(labels, ok); | 1763 return ParseExpressionOrLabelledStatement(labels, ok); |
1775 } | 1764 } |
1776 } | 1765 } |
1777 | 1766 |
1778 | 1767 |
1779 VariableProxy* Parser::NewUnresolved(const AstRawString* name, | 1768 VariableProxy* Parser::NewUnresolved(const AstRawString* name, |
1780 VariableMode mode, Interface* interface) { | 1769 VariableMode mode) { |
1781 // If we are inside a function, a declaration of a var/const variable is a | 1770 // If we are inside a function, a declaration of a var/const variable is a |
1782 // truly local variable, and the scope of the variable is always the function | 1771 // truly local variable, and the scope of the variable is always the function |
1783 // scope. | 1772 // scope. |
1784 // Let/const variables in harmony mode are always added to the immediately | 1773 // Let/const variables in harmony mode are always added to the immediately |
1785 // enclosing scope. | 1774 // enclosing scope. |
1786 return DeclarationScope(mode)->NewUnresolved( | 1775 return DeclarationScope(mode)->NewUnresolved(factory(), name, position()); |
1787 factory(), name, interface, position()); | |
1788 } | 1776 } |
1789 | 1777 |
1790 | 1778 |
1791 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { | 1779 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
1792 VariableProxy* proxy = declaration->proxy(); | 1780 VariableProxy* proxy = declaration->proxy(); |
1793 DCHECK(proxy->raw_name() != NULL); | 1781 DCHECK(proxy->raw_name() != NULL); |
1794 const AstRawString* name = proxy->raw_name(); | 1782 const AstRawString* name = proxy->raw_name(); |
1795 VariableMode mode = declaration->mode(); | 1783 VariableMode mode = declaration->mode(); |
1796 Scope* declaration_scope = DeclarationScope(mode); | 1784 Scope* declaration_scope = DeclarationScope(mode); |
1797 Variable* var = NULL; | 1785 Variable* var = NULL; |
1798 | 1786 |
1799 // If a suitable scope exists, then we can statically declare this | 1787 // If a suitable scope exists, then we can statically declare this |
1800 // variable and also set its mode. In any case, a Declaration node | 1788 // variable and also set its mode. In any case, a Declaration node |
1801 // will be added to the scope so that the declaration can be added | 1789 // will be added to the scope so that the declaration can be added |
1802 // to the corresponding activation frame at runtime if necessary. | 1790 // to the corresponding activation frame at runtime if necessary. |
1803 // For instance declarations inside an eval scope need to be added | 1791 // For instance declarations inside an eval scope need to be added |
1804 // to the calling function context. | 1792 // to the calling function context. |
1805 // Similarly, strict mode eval scope does not leak variable declarations to | 1793 // Similarly, strict mode eval scope does not leak variable declarations to |
1806 // the caller's scope so we declare all locals, too. | 1794 // the caller's scope so we declare all locals, too. |
1807 if (declaration_scope->is_function_scope() || | 1795 if (declaration_scope->is_function_scope() || |
1808 declaration_scope->is_strict_eval_scope() || | 1796 declaration_scope->is_strict_eval_scope() || |
1809 declaration_scope->is_block_scope() || | 1797 declaration_scope->is_block_scope() || |
1810 declaration_scope->is_module_scope() || | 1798 declaration_scope->is_module_scope() || |
1811 declaration_scope->is_script_scope()) { | 1799 declaration_scope->is_script_scope()) { |
1812 // Declare the variable in the declaration scope. | 1800 // Declare the variable in the declaration scope. |
1813 var = declaration_scope->LookupLocal(name); | 1801 var = declaration_scope->LookupLocal(name); |
1814 if (var == NULL) { | 1802 if (var == NULL) { |
1815 // Declare the name. | 1803 // Declare the name. |
1816 var = declaration_scope->DeclareLocal(name, mode, | 1804 var = declaration_scope->DeclareLocal( |
1817 declaration->initialization(), | 1805 name, mode, declaration->initialization(), kNotAssigned); |
1818 kNotAssigned, proxy->interface()); | |
1819 } else if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(var->mode()) | 1806 } else if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(var->mode()) |
1820 || ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && | 1807 || ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && |
1821 !declaration_scope->is_script_scope())) { | 1808 !declaration_scope->is_script_scope())) { |
1822 // The name was declared in this scope before; check for conflicting | 1809 // The name was declared in this scope before; check for conflicting |
1823 // re-declarations. We have a conflict if either of the declarations is | 1810 // re-declarations. We have a conflict if either of the declarations is |
1824 // not a var (in script scope, we also have to ignore legacy const for | 1811 // not a var (in script scope, we also have to ignore legacy const for |
1825 // compatibility). There is similar code in runtime.cc in the Declare | 1812 // compatibility). There is similar code in runtime.cc in the Declare |
1826 // functions. The function CheckConflictingVarDeclarations checks for | 1813 // functions. The function CheckConflictingVarDeclarations checks for |
1827 // var and let bindings from different scopes whereas this is a check for | 1814 // var and let bindings from different scopes whereas this is a check for |
1828 // conflicting declarations within the same scope. This check also covers | 1815 // conflicting declarations within the same scope. This check also covers |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 // same variable if it is declared several times. This is not a | 1850 // same variable if it is declared several times. This is not a |
1864 // semantic issue as long as we keep the source order, but it may be | 1851 // semantic issue as long as we keep the source order, but it may be |
1865 // a performance issue since it may lead to repeated | 1852 // a performance issue since it may lead to repeated |
1866 // RuntimeHidden_DeclareLookupSlot calls. | 1853 // RuntimeHidden_DeclareLookupSlot calls. |
1867 declaration_scope->AddDeclaration(declaration); | 1854 declaration_scope->AddDeclaration(declaration); |
1868 | 1855 |
1869 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) { | 1856 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) { |
1870 // For global const variables we bind the proxy to a variable. | 1857 // For global const variables we bind the proxy to a variable. |
1871 DCHECK(resolve); // should be set by all callers | 1858 DCHECK(resolve); // should be set by all callers |
1872 Variable::Kind kind = Variable::NORMAL; | 1859 Variable::Kind kind = Variable::NORMAL; |
1873 var = new (zone()) | 1860 var = new (zone()) Variable(declaration_scope, name, mode, true, kind, |
1874 Variable(declaration_scope, name, mode, true, kind, | 1861 kNeedsInitialization, kNotAssigned); |
1875 kNeedsInitialization, kNotAssigned, proxy->interface()); | |
1876 } else if (declaration_scope->is_eval_scope() && | 1862 } else if (declaration_scope->is_eval_scope() && |
1877 is_sloppy(declaration_scope->language_mode())) { | 1863 is_sloppy(declaration_scope->language_mode())) { |
1878 // For variable declarations in a sloppy eval scope the proxy is bound | 1864 // For variable declarations in a sloppy eval scope the proxy is bound |
1879 // to a lookup variable to force a dynamic declaration using the | 1865 // to a lookup variable to force a dynamic declaration using the |
1880 // DeclareLookupSlot runtime function. | 1866 // DeclareLookupSlot runtime function. |
1881 Variable::Kind kind = Variable::NORMAL; | 1867 Variable::Kind kind = Variable::NORMAL; |
1882 // TODO(sigurds) figure out if kNotAssigned is OK here | 1868 // TODO(sigurds) figure out if kNotAssigned is OK here |
1883 var = new (zone()) Variable(declaration_scope, name, mode, true, kind, | 1869 var = new (zone()) Variable(declaration_scope, name, mode, true, kind, |
1884 declaration->initialization(), kNotAssigned, | 1870 declaration->initialization(), kNotAssigned); |
1885 proxy->interface()); | |
1886 var->AllocateTo(Variable::LOOKUP, -1); | 1871 var->AllocateTo(Variable::LOOKUP, -1); |
1887 resolve = true; | 1872 resolve = true; |
1888 } | 1873 } |
1889 | 1874 |
1890 // If requested and we have a local variable, bind the proxy to the variable | 1875 // If requested and we have a local variable, bind the proxy to the variable |
1891 // at parse-time. This is used for functions (and consts) declared inside | 1876 // at parse-time. This is used for functions (and consts) declared inside |
1892 // statements: the corresponding function (or const) variable must be in the | 1877 // statements: the corresponding function (or const) variable must be in the |
1893 // function scope and not a statement-local scope, e.g. as provided with a | 1878 // function scope and not a statement-local scope, e.g. as provided with a |
1894 // 'with' statement: | 1879 // 'with' statement: |
1895 // | 1880 // |
(...skipping 10 matching lines...) Expand all Loading... |
1906 // | 1891 // |
1907 // Note that if 'f' is accessed from inside the 'with' statement, it | 1892 // Note that if 'f' is accessed from inside the 'with' statement, it |
1908 // will be allocated in the context (because we must be able to look | 1893 // will be allocated in the context (because we must be able to look |
1909 // it up dynamically) but it will also be accessed statically, i.e., | 1894 // it up dynamically) but it will also be accessed statically, i.e., |
1910 // with a context slot index and a context chain length for this | 1895 // with a context slot index and a context chain length for this |
1911 // initialization code. Thus, inside the 'with' statement, we need | 1896 // initialization code. Thus, inside the 'with' statement, we need |
1912 // both access to the static and the dynamic context chain; the | 1897 // both access to the static and the dynamic context chain; the |
1913 // runtime needs to provide both. | 1898 // runtime needs to provide both. |
1914 if (resolve && var != NULL) { | 1899 if (resolve && var != NULL) { |
1915 proxy->BindTo(var); | 1900 proxy->BindTo(var); |
1916 | |
1917 if (FLAG_harmony_modules) { | |
1918 bool ok; | |
1919 #ifdef DEBUG | |
1920 if (FLAG_print_interface_details) { | |
1921 PrintF("# Declare %.*s ", var->raw_name()->length(), | |
1922 var->raw_name()->raw_data()); | |
1923 } | |
1924 #endif | |
1925 proxy->interface()->Unify(var->interface(), zone(), &ok); | |
1926 if (!ok) { | |
1927 #ifdef DEBUG | |
1928 if (FLAG_print_interfaces) { | |
1929 PrintF("DECLARE TYPE ERROR\n"); | |
1930 PrintF("proxy: "); | |
1931 proxy->interface()->Print(); | |
1932 PrintF("var: "); | |
1933 var->interface()->Print(); | |
1934 } | |
1935 #endif | |
1936 ParserTraits::ReportMessage("module_type_error", name); | |
1937 } | |
1938 } | |
1939 } | 1901 } |
1940 } | 1902 } |
1941 | 1903 |
1942 | 1904 |
1943 // Language extension which is only enabled for source files loaded | 1905 // Language extension which is only enabled for source files loaded |
1944 // through the API's extension mechanism. A native function | 1906 // through the API's extension mechanism. A native function |
1945 // declaration is resolved by looking up the function through a | 1907 // declaration is resolved by looking up the function through a |
1946 // callback provided by the extension. | 1908 // callback provided by the extension. |
1947 Statement* Parser::ParseNativeDeclaration(bool* ok) { | 1909 Statement* Parser::ParseNativeDeclaration(bool* ok) { |
1948 int pos = peek_position(); | 1910 int pos = peek_position(); |
(...skipping 14 matching lines...) Expand all Loading... |
1963 | 1925 |
1964 // Make sure that the function containing the native declaration | 1926 // Make sure that the function containing the native declaration |
1965 // isn't lazily compiled. The extension structures are only | 1927 // isn't lazily compiled. The extension structures are only |
1966 // accessible while parsing the first time not when reparsing | 1928 // accessible while parsing the first time not when reparsing |
1967 // because of lazy compilation. | 1929 // because of lazy compilation. |
1968 DeclarationScope(VAR)->ForceEagerCompilation(); | 1930 DeclarationScope(VAR)->ForceEagerCompilation(); |
1969 | 1931 |
1970 // TODO(1240846): It's weird that native function declarations are | 1932 // TODO(1240846): It's weird that native function declarations are |
1971 // introduced dynamically when we meet their declarations, whereas | 1933 // introduced dynamically when we meet their declarations, whereas |
1972 // other functions are set up when entering the surrounding scope. | 1934 // other functions are set up when entering the surrounding scope. |
1973 VariableProxy* proxy = NewUnresolved(name, VAR, Interface::NewValue()); | 1935 VariableProxy* proxy = NewUnresolved(name, VAR); |
1974 Declaration* declaration = | 1936 Declaration* declaration = |
1975 factory()->NewVariableDeclaration(proxy, VAR, scope_, pos); | 1937 factory()->NewVariableDeclaration(proxy, VAR, scope_, pos); |
1976 Declare(declaration, true, CHECK_OK); | 1938 Declare(declaration, true, CHECK_OK); |
1977 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral( | 1939 NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral( |
1978 name, extension_, RelocInfo::kNoPosition); | 1940 name, extension_, RelocInfo::kNoPosition); |
1979 return factory()->NewExpressionStatement( | 1941 return factory()->NewExpressionStatement( |
1980 factory()->NewAssignment( | 1942 factory()->NewAssignment( |
1981 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition), | 1943 Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition), |
1982 pos); | 1944 pos); |
1983 } | 1945 } |
(...skipping 22 matching lines...) Expand all Loading... |
2006 // scope, we treat it as such and introduce the function with its | 1968 // scope, we treat it as such and introduce the function with its |
2007 // initial value upon entering the corresponding scope. | 1969 // initial value upon entering the corresponding scope. |
2008 // In ES6, a function behaves as a lexical binding, except in | 1970 // In ES6, a function behaves as a lexical binding, except in |
2009 // a script scope, or the initial scope of eval or another function. | 1971 // a script scope, or the initial scope of eval or another function. |
2010 VariableMode mode = | 1972 VariableMode mode = |
2011 allow_harmony_scoping() && is_strict(language_mode()) && | 1973 allow_harmony_scoping() && is_strict(language_mode()) && |
2012 !(scope_->is_script_scope() || scope_->is_eval_scope() || | 1974 !(scope_->is_script_scope() || scope_->is_eval_scope() || |
2013 scope_->is_function_scope()) | 1975 scope_->is_function_scope()) |
2014 ? LET | 1976 ? LET |
2015 : VAR; | 1977 : VAR; |
2016 VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); | 1978 VariableProxy* proxy = NewUnresolved(name, mode); |
2017 Declaration* declaration = | 1979 Declaration* declaration = |
2018 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); | 1980 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); |
2019 Declare(declaration, true, CHECK_OK); | 1981 Declare(declaration, true, CHECK_OK); |
2020 if (names) names->Add(name, zone()); | 1982 if (names) names->Add(name, zone()); |
2021 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 1983 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
2022 } | 1984 } |
2023 | 1985 |
2024 | 1986 |
2025 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 1987 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
2026 bool* ok) { | 1988 bool* ok) { |
(...skipping 17 matching lines...) Expand all Loading... |
2044 return NULL; | 2006 return NULL; |
2045 } | 2007 } |
2046 | 2008 |
2047 int pos = position(); | 2009 int pos = position(); |
2048 bool is_strict_reserved = false; | 2010 bool is_strict_reserved = false; |
2049 const AstRawString* name = | 2011 const AstRawString* name = |
2050 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 2012 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
2051 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), | 2013 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), |
2052 is_strict_reserved, pos, CHECK_OK); | 2014 is_strict_reserved, pos, CHECK_OK); |
2053 | 2015 |
2054 VariableProxy* proxy = NewUnresolved(name, LET, Interface::NewValue()); | 2016 VariableProxy* proxy = NewUnresolved(name, LET); |
2055 Declaration* declaration = | 2017 Declaration* declaration = |
2056 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 2018 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); |
2057 Declare(declaration, true, CHECK_OK); | 2019 Declare(declaration, true, CHECK_OK); |
2058 proxy->var()->set_initializer_position(pos); | 2020 proxy->var()->set_initializer_position(pos); |
2059 | 2021 |
2060 Token::Value init_op = Token::INIT_LET; | 2022 Token::Value init_op = Token::INIT_LET; |
2061 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); | 2023 Assignment* assignment = factory()->NewAssignment(init_op, proxy, value, pos); |
2062 Statement* assignment_statement = | 2024 Statement* assignment_statement = |
2063 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); | 2025 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); |
2064 if (names) names->Add(name, zone()); | 2026 if (names) names->Add(name, zone()); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2253 // For let/const declarations in harmony mode, we can also immediately | 2215 // For let/const declarations in harmony mode, we can also immediately |
2254 // pre-resolve the proxy because it resides in the same scope as the | 2216 // pre-resolve the proxy because it resides in the same scope as the |
2255 // declaration. | 2217 // declaration. |
2256 is_for_iteration_variable = | 2218 is_for_iteration_variable = |
2257 var_context == kForStatement && | 2219 var_context == kForStatement && |
2258 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); | 2220 (peek() == Token::IN || PeekContextualKeyword(CStrVector("of"))); |
2259 if (is_for_iteration_variable && mode == CONST) { | 2221 if (is_for_iteration_variable && mode == CONST) { |
2260 needs_init = false; | 2222 needs_init = false; |
2261 } | 2223 } |
2262 | 2224 |
2263 Interface* interface = | 2225 VariableProxy* proxy = NewUnresolved(name, mode); |
2264 is_const ? Interface::NewConst() : Interface::NewValue(); | |
2265 VariableProxy* proxy = NewUnresolved(name, mode, interface); | |
2266 Declaration* declaration = | 2226 Declaration* declaration = |
2267 factory()->NewVariableDeclaration(proxy, mode, scope_, pos); | 2227 factory()->NewVariableDeclaration(proxy, mode, scope_, pos); |
2268 Declare(declaration, mode != VAR, CHECK_OK); | 2228 Declare(declaration, mode != VAR, CHECK_OK); |
2269 nvars++; | 2229 nvars++; |
2270 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { | 2230 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { |
2271 ReportMessage("too_many_variables"); | 2231 ReportMessage("too_many_variables"); |
2272 *ok = false; | 2232 *ok = false; |
2273 return NULL; | 2233 return NULL; |
2274 } | 2234 } |
2275 if (names) names->Add(name, zone()); | 2235 if (names) names->Add(name, zone()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 } | 2379 } |
2420 | 2380 |
2421 // Add an assignment node to the initialization statement block if we still | 2381 // Add an assignment node to the initialization statement block if we still |
2422 // have a pending initialization value. | 2382 // have a pending initialization value. |
2423 if (value != NULL) { | 2383 if (value != NULL) { |
2424 DCHECK(mode == VAR); | 2384 DCHECK(mode == VAR); |
2425 // 'var' initializations are simply assignments (with all the consequences | 2385 // 'var' initializations are simply assignments (with all the consequences |
2426 // if they are inside a 'with' statement - they may change a 'with' object | 2386 // if they are inside a 'with' statement - they may change a 'with' object |
2427 // property). | 2387 // property). |
2428 VariableProxy* proxy = | 2388 VariableProxy* proxy = |
2429 initialization_scope->NewUnresolved(factory(), name, interface); | 2389 initialization_scope->NewUnresolved(factory(), name); |
2430 Assignment* assignment = | 2390 Assignment* assignment = |
2431 factory()->NewAssignment(init_op, proxy, value, pos); | 2391 factory()->NewAssignment(init_op, proxy, value, pos); |
2432 block->AddStatement( | 2392 block->AddStatement( |
2433 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), | 2393 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), |
2434 zone()); | 2394 zone()); |
2435 } | 2395 } |
2436 | 2396 |
2437 if (fni_ != NULL) fni_->Leave(); | 2397 if (fni_ != NULL) fni_->Leave(); |
2438 } while (peek() == Token::COMMA); | 2398 } while (peek() == Token::COMMA); |
2439 | 2399 |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3055 RelocInfo::kNoPosition); | 3015 RelocInfo::kNoPosition); |
3056 | 3016 |
3057 // Add statement: let x = i. | 3017 // Add statement: let x = i. |
3058 outer_block->AddStatement(init, zone()); | 3018 outer_block->AddStatement(init, zone()); |
3059 | 3019 |
3060 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); | 3020 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); |
3061 | 3021 |
3062 // For each let variable x: | 3022 // For each let variable x: |
3063 // make statement: temp_x = x. | 3023 // make statement: temp_x = x. |
3064 for (int i = 0; i < names->length(); i++) { | 3024 for (int i = 0; i < names->length(); i++) { |
3065 VariableProxy* proxy = | 3025 VariableProxy* proxy = NewUnresolved(names->at(i), LET); |
3066 NewUnresolved(names->at(i), LET, Interface::NewValue()); | |
3067 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name); | 3026 Variable* temp = scope_->DeclarationScope()->NewTemporary(temp_name); |
3068 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); | 3027 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
3069 Assignment* assignment = factory()->NewAssignment( | 3028 Assignment* assignment = factory()->NewAssignment( |
3070 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); | 3029 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); |
3071 Statement* assignment_statement = factory()->NewExpressionStatement( | 3030 Statement* assignment_statement = factory()->NewExpressionStatement( |
3072 assignment, RelocInfo::kNoPosition); | 3031 assignment, RelocInfo::kNoPosition); |
3073 outer_block->AddStatement(assignment_statement, zone()); | 3032 outer_block->AddStatement(assignment_statement, zone()); |
3074 temps.Add(temp, zone()); | 3033 temps.Add(temp, zone()); |
3075 } | 3034 } |
3076 | 3035 |
(...skipping 23 matching lines...) Expand all Loading... |
3100 scope_ = inner_scope; | 3059 scope_ = inner_scope; |
3101 | 3060 |
3102 Block* inner_block = factory()->NewBlock(NULL, names->length() + 4, false, | 3061 Block* inner_block = factory()->NewBlock(NULL, names->length() + 4, false, |
3103 RelocInfo::kNoPosition); | 3062 RelocInfo::kNoPosition); |
3104 int pos = scanner()->location().beg_pos; | 3063 int pos = scanner()->location().beg_pos; |
3105 ZoneList<Variable*> inner_vars(names->length(), zone()); | 3064 ZoneList<Variable*> inner_vars(names->length(), zone()); |
3106 | 3065 |
3107 // For each let variable x: | 3066 // For each let variable x: |
3108 // make statement: let x = temp_x. | 3067 // make statement: let x = temp_x. |
3109 for (int i = 0; i < names->length(); i++) { | 3068 for (int i = 0; i < names->length(); i++) { |
3110 VariableProxy* proxy = | 3069 VariableProxy* proxy = NewUnresolved(names->at(i), LET); |
3111 NewUnresolved(names->at(i), LET, Interface::NewValue()); | |
3112 Declaration* declaration = | 3070 Declaration* declaration = |
3113 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); | 3071 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); |
3114 Declare(declaration, true, CHECK_OK); | 3072 Declare(declaration, true, CHECK_OK); |
3115 inner_vars.Add(declaration->proxy()->var(), zone()); | 3073 inner_vars.Add(declaration->proxy()->var(), zone()); |
3116 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); | 3074 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); |
3117 Assignment* assignment = factory()->NewAssignment( | 3075 Assignment* assignment = factory()->NewAssignment( |
3118 Token::INIT_LET, proxy, temp_proxy, pos); | 3076 Token::INIT_LET, proxy, temp_proxy, pos); |
3119 Statement* assignment_statement = factory()->NewExpressionStatement( | 3077 Statement* assignment_statement = factory()->NewExpressionStatement( |
3120 assignment, pos); | 3078 assignment, pos); |
3121 proxy->var()->set_initializer_position(pos); | 3079 proxy->var()->set_initializer_position(pos); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3252 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); | 3210 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); |
3253 scope_ = for_scope; | 3211 scope_ = for_scope; |
3254 | 3212 |
3255 Expect(Token::FOR, CHECK_OK); | 3213 Expect(Token::FOR, CHECK_OK); |
3256 Expect(Token::LPAREN, CHECK_OK); | 3214 Expect(Token::LPAREN, CHECK_OK); |
3257 for_scope->set_start_position(scanner()->location().beg_pos); | 3215 for_scope->set_start_position(scanner()->location().beg_pos); |
3258 bool is_let_identifier_expression = false; | 3216 bool is_let_identifier_expression = false; |
3259 if (peek() != Token::SEMICOLON) { | 3217 if (peek() != Token::SEMICOLON) { |
3260 if (peek() == Token::VAR || | 3218 if (peek() == Token::VAR || |
3261 (peek() == Token::CONST && is_sloppy(language_mode()))) { | 3219 (peek() == Token::CONST && is_sloppy(language_mode()))) { |
3262 bool is_const = peek() == Token::CONST; | |
3263 const AstRawString* name = NULL; | 3220 const AstRawString* name = NULL; |
3264 VariableDeclarationProperties decl_props = kHasNoInitializers; | 3221 VariableDeclarationProperties decl_props = kHasNoInitializers; |
3265 Block* variable_statement = | 3222 Block* variable_statement = |
3266 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, | 3223 ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, |
3267 CHECK_OK); | 3224 CHECK_OK); |
3268 bool accept_OF = decl_props == kHasNoInitializers; | 3225 bool accept_OF = decl_props == kHasNoInitializers; |
3269 ForEachStatement::VisitMode mode; | 3226 ForEachStatement::VisitMode mode; |
3270 int each_pos = position(); | 3227 int each_pos = position(); |
3271 | 3228 |
3272 if (name != NULL && CheckInOrOf(accept_OF, &mode)) { | 3229 if (name != NULL && CheckInOrOf(accept_OF, &mode)) { |
3273 Interface* interface = | |
3274 is_const ? Interface::NewConst() : Interface::NewValue(); | |
3275 ForEachStatement* loop = | 3230 ForEachStatement* loop = |
3276 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3231 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3277 Target target(&this->target_stack_, loop); | 3232 Target target(&this->target_stack_, loop); |
3278 | 3233 |
3279 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3234 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3280 Expect(Token::RPAREN, CHECK_OK); | 3235 Expect(Token::RPAREN, CHECK_OK); |
3281 | 3236 |
3282 VariableProxy* each = | 3237 VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos); |
3283 scope_->NewUnresolved(factory(), name, interface, each_pos); | |
3284 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3238 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3285 InitializeForEachStatement(loop, each, enumerable, body); | 3239 InitializeForEachStatement(loop, each, enumerable, body); |
3286 Block* result = | 3240 Block* result = |
3287 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); | 3241 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
3288 result->AddStatement(variable_statement, zone()); | 3242 result->AddStatement(variable_statement, zone()); |
3289 result->AddStatement(loop, zone()); | 3243 result->AddStatement(loop, zone()); |
3290 scope_ = saved_scope; | 3244 scope_ = saved_scope; |
3291 for_scope->set_end_position(scanner()->location().end_pos); | 3245 for_scope->set_end_position(scanner()->location().end_pos); |
3292 for_scope = for_scope->FinalizeBlockScope(); | 3246 for_scope = for_scope->FinalizeBlockScope(); |
3293 DCHECK(for_scope == NULL); | 3247 DCHECK(for_scope == NULL); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3331 ForEachStatement* loop = | 3285 ForEachStatement* loop = |
3332 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3286 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3333 Target target(&this->target_stack_, loop); | 3287 Target target(&this->target_stack_, loop); |
3334 | 3288 |
3335 // The expression does not see the loop variable. | 3289 // The expression does not see the loop variable. |
3336 scope_ = saved_scope; | 3290 scope_ = saved_scope; |
3337 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3291 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3338 scope_ = for_scope; | 3292 scope_ = for_scope; |
3339 Expect(Token::RPAREN, CHECK_OK); | 3293 Expect(Token::RPAREN, CHECK_OK); |
3340 | 3294 |
3341 VariableProxy* each = scope_->NewUnresolved( | 3295 VariableProxy* each = scope_->NewUnresolved(factory(), name, each_pos); |
3342 factory(), name, Interface::NewValue(), each_pos); | |
3343 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3296 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3344 Block* body_block = | 3297 Block* body_block = |
3345 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3298 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
3346 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; | 3299 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; |
3347 Assignment* assignment = factory()->NewAssignment( | 3300 Assignment* assignment = factory()->NewAssignment( |
3348 init_op, each, temp_proxy, RelocInfo::kNoPosition); | 3301 init_op, each, temp_proxy, RelocInfo::kNoPosition); |
3349 Statement* assignment_statement = factory()->NewExpressionStatement( | 3302 Statement* assignment_statement = factory()->NewExpressionStatement( |
3350 assignment, RelocInfo::kNoPosition); | 3303 assignment, RelocInfo::kNoPosition); |
3351 body_block->AddStatement(variable_statement, zone()); | 3304 body_block->AddStatement(variable_statement, zone()); |
3352 body_block->AddStatement(assignment_statement, zone()); | 3305 body_block->AddStatement(assignment_statement, zone()); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3773 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { | 3726 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { |
3774 if (allow_harmony_scoping() && is_strict(language_mode())) { | 3727 if (allow_harmony_scoping() && is_strict(language_mode())) { |
3775 fvar_init_op = Token::INIT_CONST; | 3728 fvar_init_op = Token::INIT_CONST; |
3776 } | 3729 } |
3777 VariableMode fvar_mode = | 3730 VariableMode fvar_mode = |
3778 allow_harmony_scoping() && is_strict(language_mode()) ? CONST | 3731 allow_harmony_scoping() && is_strict(language_mode()) ? CONST |
3779 : CONST_LEGACY; | 3732 : CONST_LEGACY; |
3780 DCHECK(function_name != NULL); | 3733 DCHECK(function_name != NULL); |
3781 fvar = new (zone()) | 3734 fvar = new (zone()) |
3782 Variable(scope_, function_name, fvar_mode, true /* is valid LHS */, | 3735 Variable(scope_, function_name, fvar_mode, true /* is valid LHS */, |
3783 Variable::NORMAL, kCreatedInitialized, kNotAssigned, | 3736 Variable::NORMAL, kCreatedInitialized, kNotAssigned); |
3784 Interface::NewConst()); | |
3785 VariableProxy* proxy = factory()->NewVariableProxy(fvar); | 3737 VariableProxy* proxy = factory()->NewVariableProxy(fvar); |
3786 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( | 3738 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( |
3787 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); | 3739 proxy, fvar_mode, scope_, RelocInfo::kNoPosition); |
3788 scope_->DeclareFunctionVar(fvar_declaration); | 3740 scope_->DeclareFunctionVar(fvar_declaration); |
3789 } | 3741 } |
3790 | 3742 |
3791 // Determine if the function can be parsed lazily. Lazy parsing is different | 3743 // Determine if the function can be parsed lazily. Lazy parsing is different |
3792 // from lazy compilation; we need to parse more eagerly than we compile. | 3744 // from lazy compilation; we need to parse more eagerly than we compile. |
3793 | 3745 |
3794 // We can only parse lazily if we also compile lazily. The heuristics for | 3746 // We can only parse lazily if we also compile lazily. The heuristics for |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3965 | 3917 |
3966 | 3918 |
3967 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 3919 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
3968 const AstRawString* function_name, int pos, Variable* fvar, | 3920 const AstRawString* function_name, int pos, Variable* fvar, |
3969 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 3921 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
3970 // Everything inside an eagerly parsed function will be parsed eagerly | 3922 // Everything inside an eagerly parsed function will be parsed eagerly |
3971 // (see comment above). | 3923 // (see comment above). |
3972 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 3924 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
3973 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone()); | 3925 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8, zone()); |
3974 if (fvar != NULL) { | 3926 if (fvar != NULL) { |
3975 VariableProxy* fproxy = scope_->NewUnresolved( | 3927 VariableProxy* fproxy = scope_->NewUnresolved(factory(), function_name); |
3976 factory(), function_name, Interface::NewConst()); | |
3977 fproxy->BindTo(fvar); | 3928 fproxy->BindTo(fvar); |
3978 body->Add(factory()->NewExpressionStatement( | 3929 body->Add(factory()->NewExpressionStatement( |
3979 factory()->NewAssignment(fvar_init_op, | 3930 factory()->NewAssignment(fvar_init_op, |
3980 fproxy, | 3931 fproxy, |
3981 factory()->NewThisFunction(pos), | 3932 factory()->NewThisFunction(pos), |
3982 RelocInfo::kNoPosition), | 3933 RelocInfo::kNoPosition), |
3983 RelocInfo::kNoPosition), zone()); | 3934 RelocInfo::kNoPosition), zone()); |
3984 } | 3935 } |
3985 | 3936 |
3986 | 3937 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4096 } | 4047 } |
4097 | 4048 |
4098 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 4049 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
4099 BlockState block_state(&scope_, block_scope); | 4050 BlockState block_state(&scope_, block_scope); |
4100 scope_->SetLanguageMode( | 4051 scope_->SetLanguageMode( |
4101 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); | 4052 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
4102 scope_->SetScopeName(name); | 4053 scope_->SetScopeName(name); |
4103 | 4054 |
4104 VariableProxy* proxy = NULL; | 4055 VariableProxy* proxy = NULL; |
4105 if (name != NULL) { | 4056 if (name != NULL) { |
4106 proxy = NewUnresolved(name, CONST, Interface::NewConst()); | 4057 proxy = NewUnresolved(name, CONST); |
4107 Declaration* declaration = | 4058 Declaration* declaration = |
4108 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | 4059 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); |
4109 Declare(declaration, true, CHECK_OK); | 4060 Declare(declaration, true, CHECK_OK); |
4110 } | 4061 } |
4111 | 4062 |
4112 Expression* extends = NULL; | 4063 Expression* extends = NULL; |
4113 if (Check(Token::EXTENDS)) { | 4064 if (Check(Token::EXTENDS)) { |
4114 block_scope->set_start_position(scanner()->location().end_pos); | 4065 block_scope->set_start_position(scanner()->location().end_pos); |
4115 extends = ParseLeftHandSideExpression(CHECK_OK); | 4066 extends = ParseLeftHandSideExpression(CHECK_OK); |
4116 } else { | 4067 } else { |
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5493 } else { | 5444 } else { |
5494 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5445 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5495 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5446 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5496 raw_string->length()); | 5447 raw_string->length()); |
5497 } | 5448 } |
5498 } | 5449 } |
5499 | 5450 |
5500 return running_hash; | 5451 return running_hash; |
5501 } | 5452 } |
5502 } } // namespace v8::internal | 5453 } } // namespace v8::internal |
OLD | NEW |