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

Side by Side Diff: src/parsing/parser.cc

Issue 2209573002: Separate Scope into DeclarationScope and Scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 bool call_super, int pos, 213 bool call_super, int pos,
214 int end_pos, 214 int end_pos,
215 LanguageMode language_mode) { 215 LanguageMode language_mode) {
216 int materialized_literal_count = -1; 216 int materialized_literal_count = -1;
217 int expected_property_count = -1; 217 int expected_property_count = -1;
218 int parameter_count = 0; 218 int parameter_count = 0;
219 if (name == nullptr) name = ast_value_factory()->empty_string(); 219 if (name == nullptr) name = ast_value_factory()->empty_string();
220 220
221 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor 221 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor
222 : FunctionKind::kDefaultBaseConstructor; 222 : FunctionKind::kDefaultBaseConstructor;
223 Scope* function_scope = NewFunctionScope(kind); 223 DeclarationScope* function_scope = NewFunctionScope(kind);
224 SetLanguageMode(function_scope, 224 SetLanguageMode(function_scope,
225 static_cast<LanguageMode>(language_mode | STRICT)); 225 static_cast<LanguageMode>(language_mode | STRICT));
226 // Set start and end position to the same value 226 // Set start and end position to the same value
227 function_scope->set_start_position(pos); 227 function_scope->set_start_position(pos);
228 function_scope->set_end_position(pos); 228 function_scope->set_end_position(pos);
229 ZoneList<Statement*>* body = NULL; 229 ZoneList<Statement*>* body = NULL;
230 230
231 { 231 {
232 FunctionState function_state(&function_state_, &scope_state_, 232 FunctionState function_state(&function_state_, &scope_state_,
233 function_scope, kind); 233 function_scope, kind);
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 DCHECK_NULL(scope_state_); 945 DCHECK_NULL(scope_state_);
946 DCHECK_NULL(target_stack_); 946 DCHECK_NULL(target_stack_);
947 947
948 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; 948 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY;
949 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; 949 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY;
950 950
951 FunctionLiteral* result = NULL; 951 FunctionLiteral* result = NULL;
952 { 952 {
953 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native 953 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native
954 // context, which will have the "this" binding for script scopes. 954 // context, which will have the "this" binding for script scopes.
955 Scope* scope = NewScriptScope(); 955 DeclarationScope* scope = NewScriptScope();
956 info->set_script_scope(scope); 956 info->set_script_scope(scope);
957 Scope* inner = scope;
957 if (!info->context().is_null() && !info->context()->IsNativeContext()) { 958 if (!info->context().is_null() && !info->context()->IsNativeContext()) {
958 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), 959 // If we're compiling for eval, this isn't necessarily a declaration
960 // scope.
961 inner = Scope::DeserializeScopeChain(info->isolate(), zone(),
959 *info->context(), scope, 962 *info->context(), scope,
960 ast_value_factory()); 963 ast_value_factory());
961 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this 964 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
962 // means the Parser cannot operate independent of the V8 heap. Tell the 965 // means the Parser cannot operate independent of the V8 heap. Tell the
963 // string table to internalize strings and values right after they're 966 // string table to internalize strings and values right after they're
964 // created. This kind of parsing can only be done in the main thread. 967 // created. This kind of parsing can only be done in the main thread.
965 DCHECK(parsing_on_main_thread_); 968 DCHECK(parsing_on_main_thread_);
966 ast_value_factory()->Internalize(info->isolate()); 969 ast_value_factory()->Internalize(info->isolate());
967 } 970 }
968 original_scope_ = scope; 971 original_scope_ = inner;
969 if (info->is_eval()) { 972 if (info->is_eval()) {
970 if (!scope->is_script_scope() || is_strict(info->language_mode())) { 973 if (!inner->is_script_scope() || is_strict(info->language_mode())) {
971 parsing_mode = PARSE_EAGERLY; 974 parsing_mode = PARSE_EAGERLY;
972 } 975 }
973 scope = NewScopeWithParent(scope, EVAL_SCOPE); 976 inner = NewEvalScope(inner);
974 } else if (info->is_module()) { 977 } else if (info->is_module()) {
975 scope = NewScopeWithParent(scope, MODULE_SCOPE); 978 inner = NewModuleScope(inner);
976 } 979 }
977 980
981 scope = inner->AsDeclarationScope();
982
978 scope->set_start_position(0); 983 scope->set_start_position(0);
979 984
980 // Enter 'scope' with the given parsing mode. 985 // Enter 'scope' with the given parsing mode.
981 ParsingModeScope parsing_mode_scope(this, parsing_mode); 986 ParsingModeScope parsing_mode_scope(this, parsing_mode);
982 FunctionState function_state(&function_state_, &scope_state_, scope, 987 FunctionState function_state(&function_state_, &scope_state_, scope,
983 kNormalFunction); 988 kNormalFunction);
984 989
985 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 990 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
986 bool ok = true; 991 bool ok = true;
987 int beg_pos = scanner()->location().beg_pos; 992 int beg_pos = scanner()->location().beg_pos;
988 parsing_module_ = info->is_module(); 993 parsing_module_ = info->is_module();
989 if (parsing_module_) { 994 if (parsing_module_) {
990 ParseModuleItemList(body, &ok); 995 ParseModuleItemList(body, &ok);
991 ok = ok && 996 ok = ok &&
992 module()->Validate(this->scope(), &pending_error_handler_, zone()); 997 module()->Validate(this->scope()->AsDeclarationScope(),
998 &pending_error_handler_, zone());
993 } else { 999 } else {
994 // Don't count the mode in the use counters--give the program a chance 1000 // Don't count the mode in the use counters--give the program a chance
995 // to enable script-wide strict mode below. 1001 // to enable script-wide strict mode below.
996 this->scope()->SetLanguageMode(info->language_mode()); 1002 this->scope()->SetLanguageMode(info->language_mode());
997 ParseStatementList(body, Token::EOS, &ok); 1003 ParseStatementList(body, Token::EOS, &ok);
998 } 1004 }
999 1005
1000 // The parser will peek but not consume EOS. Our scope logically goes all 1006 // The parser will peek but not consume EOS. Our scope logically goes all
1001 // the way to the EOS, though. 1007 // the way to the EOS, though.
1002 scope->set_end_position(scanner()->peek_location().beg_pos); 1008 scope->set_end_position(scanner()->peek_location().beg_pos);
1003 1009
1004 if (ok && is_strict(language_mode())) { 1010 if (ok && is_strict(language_mode())) {
1005 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 1011 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
1006 CheckDecimalLiteralWithLeadingZero(use_counts_, beg_pos, 1012 CheckDecimalLiteralWithLeadingZero(use_counts_, beg_pos,
1007 scanner()->location().end_pos); 1013 scanner()->location().end_pos);
1008 } 1014 }
1009 if (ok && is_sloppy(language_mode())) { 1015 if (ok && is_sloppy(language_mode())) {
1010 // TODO(littledan): Function bindings on the global object that modify 1016 // TODO(littledan): Function bindings on the global object that modify
1011 // pre-existing bindings should be made writable, enumerable and 1017 // pre-existing bindings should be made writable, enumerable and
1012 // nonconfigurable if possible, whereas this code will leave attributes 1018 // nonconfigurable if possible, whereas this code will leave attributes
1013 // unchanged if the property already exists. 1019 // unchanged if the property already exists.
1014 InsertSloppyBlockFunctionVarBindings(scope, nullptr, &ok); 1020 InsertSloppyBlockFunctionVarBindings(scope, nullptr, &ok);
1015 } 1021 }
1016 if (ok) { 1022 if (ok) {
1017 CheckConflictingVarDeclarations(this->scope(), &ok); 1023 CheckConflictingVarDeclarations(scope, &ok);
1018 } 1024 }
1019 1025
1020 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 1026 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
1021 if (body->length() != 1 || 1027 if (body->length() != 1 ||
1022 !body->at(0)->IsExpressionStatement() || 1028 !body->at(0)->IsExpressionStatement() ||
1023 !body->at(0)->AsExpressionStatement()-> 1029 !body->at(0)->AsExpressionStatement()->
1024 expression()->IsFunctionLiteral()) { 1030 expression()->IsFunctionLiteral()) {
1025 ReportMessage(MessageTemplate::kSingleFunctionLiteral); 1031 ReportMessage(MessageTemplate::kSingleFunctionLiteral);
1026 ok = false; 1032 ok = false;
1027 } 1033 }
1028 } 1034 }
1029 1035
1030 if (ok) { 1036 if (ok) {
1031 ParserTraits::RewriteDestructuringAssignments(); 1037 ParserTraits::RewriteDestructuringAssignments();
1032 result = factory()->NewScriptOrEvalFunctionLiteral( 1038 result = factory()->NewScriptOrEvalFunctionLiteral(
1033 this->scope(), body, function_state.materialized_literal_count(), 1039 scope, body, function_state.materialized_literal_count(),
1034 function_state.expected_property_count()); 1040 function_state.expected_property_count());
1035 } 1041 }
1036 } 1042 }
1037 1043
1038 // Make sure the target stack is empty. 1044 // Make sure the target stack is empty.
1039 DCHECK(target_stack_ == NULL); 1045 DCHECK(target_stack_ == NULL);
1040 1046
1041 return result; 1047 return result;
1042 } 1048 }
1043 1049
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 const AstRawString* raw_name = ast_value_factory()->GetString(name); 1117 const AstRawString* raw_name = ast_value_factory()->GetString(name);
1112 fni_->PushEnclosingName(raw_name); 1118 fni_->PushEnclosingName(raw_name);
1113 1119
1114 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1120 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1115 1121
1116 // Place holder for the result. 1122 // Place holder for the result.
1117 FunctionLiteral* result = nullptr; 1123 FunctionLiteral* result = nullptr;
1118 1124
1119 { 1125 {
1120 // Parse the function literal. 1126 // Parse the function literal.
1121 Scope* scope = NewScriptScope(); 1127 DeclarationScope* script_scope = NewScriptScope();
1122 info->set_script_scope(scope); 1128 Scope* scope = script_scope;
1129 info->set_script_scope(script_scope);
1123 if (!info->context().is_null()) { 1130 if (!info->context().is_null()) {
1124 // Ok to use Isolate here, since lazy function parsing is only done in the 1131 // Ok to use Isolate here, since lazy function parsing is only done in the
1125 // main thread. 1132 // main thread.
1126 DCHECK(parsing_on_main_thread_); 1133 DCHECK(parsing_on_main_thread_);
1127 scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(), 1134 scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(),
1128 scope, ast_value_factory()); 1135 scope, ast_value_factory());
1129 } 1136 }
1130 original_scope_ = scope; 1137 original_scope_ = scope;
1131 FunctionState function_state(&function_state_, &scope_state_, scope, 1138 FunctionState function_state(&function_state_, &scope_state_, scope,
1132 shared_info->kind()); 1139 shared_info->kind());
(...skipping 12 matching lines...) Expand all
1145 CHECK(stack_overflow()); 1152 CHECK(stack_overflow());
1146 return nullptr; 1153 return nullptr;
1147 } 1154 }
1148 if (!(peek_any_identifier() || peek() == Token::LPAREN)) { 1155 if (!(peek_any_identifier() || peek() == Token::LPAREN)) {
1149 CHECK(stack_overflow()); 1156 CHECK(stack_overflow());
1150 return nullptr; 1157 return nullptr;
1151 } 1158 }
1152 } 1159 }
1153 1160
1154 // TODO(adamk): We should construct this scope from the ScopeInfo. 1161 // TODO(adamk): We should construct this scope from the ScopeInfo.
1155 Scope* scope = NewFunctionScope(FunctionKind::kArrowFunction); 1162 DeclarationScope* scope = NewFunctionScope(FunctionKind::kArrowFunction);
1156 1163
1157 // These two bits only need to be explicitly set because we're 1164 // These two bits only need to be explicitly set because we're
1158 // not passing the ScopeInfo to the Scope constructor. 1165 // not passing the ScopeInfo to the Scope constructor.
1159 // TODO(adamk): Remove these calls once the above NewScope call 1166 // TODO(adamk): Remove these calls once the above NewScope call
1160 // passes the ScopeInfo. 1167 // passes the ScopeInfo.
1161 if (shared_info->scope_info()->CallsEval()) { 1168 if (shared_info->scope_info()->CallsEval()) {
1162 scope->RecordEvalCall(); 1169 scope->RecordEvalCall();
1163 } 1170 }
1164 SetLanguageMode(scope, shared_info->language_mode()); 1171 SetLanguageMode(scope, shared_info->language_mode());
1165 1172
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 1934
1928 1935
1929 VariableProxy* Parser::NewUnresolved(const AstRawString* name, 1936 VariableProxy* Parser::NewUnresolved(const AstRawString* name,
1930 VariableMode mode) { 1937 VariableMode mode) {
1931 // If we are inside a function, a declaration of a 'var' variable is a 1938 // If we are inside a function, a declaration of a 'var' variable is a
1932 // truly local variable, and the scope of the variable is always the function 1939 // truly local variable, and the scope of the variable is always the function
1933 // scope. 1940 // scope.
1934 // Let/const variables are always added to the immediately enclosing scope. 1941 // Let/const variables are always added to the immediately enclosing scope.
1935 Scope* scope = IsLexicalVariableMode(mode) 1942 Scope* scope = IsLexicalVariableMode(mode)
1936 ? this->scope() 1943 ? this->scope()
1937 : this->scope()->DeclarationScope(); 1944 : this->scope()->GetDeclarationScope();
1938 return scope->NewUnresolved(factory(), name, Variable::NORMAL, 1945 return scope->NewUnresolved(factory(), name, Variable::NORMAL,
1939 scanner()->location().beg_pos, 1946 scanner()->location().beg_pos,
1940 scanner()->location().end_pos); 1947 scanner()->location().end_pos);
1941 } 1948 }
1942 1949
1943 1950
1944 void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { 1951 void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) {
1945 DCHECK_NOT_NULL(local_name); 1952 DCHECK_NOT_NULL(local_name);
1946 VariableProxy* proxy = NewUnresolved(local_name, IMPORT); 1953 VariableProxy* proxy = NewUnresolved(local_name, IMPORT);
1947 Declaration* declaration = 1954 Declaration* declaration =
1948 factory()->NewVariableDeclaration(proxy, IMPORT, scope(), pos); 1955 factory()->NewVariableDeclaration(proxy, IMPORT, scope(), pos);
1949 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID); 1956 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID);
1950 } 1957 }
1951 1958
1952 1959
1953 Variable* Parser::Declare(Declaration* declaration, 1960 Variable* Parser::Declare(Declaration* declaration,
1954 DeclarationDescriptor::Kind declaration_kind, 1961 DeclarationDescriptor::Kind declaration_kind,
1955 bool resolve, bool* ok, Scope* scope) { 1962 bool resolve, bool* ok, Scope* scope) {
1956 VariableProxy* proxy = declaration->proxy(); 1963 VariableProxy* proxy = declaration->proxy();
1957 DCHECK(proxy->raw_name() != NULL); 1964 DCHECK(proxy->raw_name() != NULL);
1958 const AstRawString* name = proxy->raw_name(); 1965 const AstRawString* name = proxy->raw_name();
1959 VariableMode mode = declaration->mode(); 1966 VariableMode mode = declaration->mode();
1960 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); 1967 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY);
1961 bool is_function_declaration = declaration->IsFunctionDeclaration(); 1968 bool is_function_declaration = declaration->IsFunctionDeclaration();
1962 if (scope == nullptr) scope = this->scope(); 1969 if (scope == nullptr) scope = this->scope();
1963 Scope* declaration_scope = 1970 Scope* declaration_scope =
1964 IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope(); 1971 IsLexicalVariableMode(mode) ? scope : scope->GetDeclarationScope();
1965 Variable* var = NULL; 1972 Variable* var = NULL;
1966 1973
1967 // If a suitable scope exists, then we can statically declare this 1974 // If a suitable scope exists, then we can statically declare this
1968 // variable and also set its mode. In any case, a Declaration node 1975 // variable and also set its mode. In any case, a Declaration node
1969 // will be added to the scope so that the declaration can be added 1976 // will be added to the scope so that the declaration can be added
1970 // to the corresponding activation frame at runtime if necessary. 1977 // to the corresponding activation frame at runtime if necessary.
1971 // For instance, var declarations inside a sloppy eval scope need 1978 // For instance, var declarations inside a sloppy eval scope need
1972 // to be added to the calling function context. Similarly, strict 1979 // to be added to the calling function context. Similarly, strict
1973 // mode eval scope and lexical eval bindings do not leak variable 1980 // mode eval scope and lexical eval bindings do not leak variable
1974 // declarations to the caller's scope so we declare all locals, too. 1981 // declarations to the caller's scope so we declare all locals, too.
(...skipping 21 matching lines...) Expand all
1996 if (is_sloppy(language_mode()) && is_function_declaration && 2003 if (is_sloppy(language_mode()) && is_function_declaration &&
1997 var->is_function()) { 2004 var->is_function()) {
1998 DCHECK(IsLexicalVariableMode(mode) && 2005 DCHECK(IsLexicalVariableMode(mode) &&
1999 IsLexicalVariableMode(var->mode())); 2006 IsLexicalVariableMode(var->mode()));
2000 // If the duplication is allowed, then the var will show up 2007 // If the duplication is allowed, then the var will show up
2001 // in the SloppyBlockFunctionMap and the new FunctionKind 2008 // in the SloppyBlockFunctionMap and the new FunctionKind
2002 // will be a permitted duplicate. 2009 // will be a permitted duplicate.
2003 FunctionKind function_kind = 2010 FunctionKind function_kind =
2004 declaration->AsFunctionDeclaration()->fun()->kind(); 2011 declaration->AsFunctionDeclaration()->fun()->kind();
2005 duplicate_allowed = 2012 duplicate_allowed =
2006 scope->DeclarationScope()->sloppy_block_function_map()->Lookup( 2013 scope->GetDeclarationScope()->sloppy_block_function_map()->Lookup(
2007 const_cast<AstRawString*>(name), name->hash()) != nullptr && 2014 const_cast<AstRawString*>(name), name->hash()) != nullptr &&
2008 !IsAsyncFunction(function_kind) && 2015 !IsAsyncFunction(function_kind) &&
2009 !(allow_harmony_restrictive_generators() && 2016 !(allow_harmony_restrictive_generators() &&
2010 IsGeneratorFunction(function_kind)); 2017 IsGeneratorFunction(function_kind));
2011 } 2018 }
2012 if (duplicate_allowed) { 2019 if (duplicate_allowed) {
2013 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition]; 2020 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition];
2014 } else { 2021 } else {
2015 // The name was declared in this scope before; check for conflicting 2022 // The name was declared in this scope before; check for conflicting
2016 // re-declarations. We have a conflict if either of the declarations 2023 // re-declarations. We have a conflict if either of the declarations
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2123 Expect(Token::COMMA, CHECK_OK); 2130 Expect(Token::COMMA, CHECK_OK);
2124 } 2131 }
2125 } 2132 }
2126 Expect(Token::RPAREN, CHECK_OK); 2133 Expect(Token::RPAREN, CHECK_OK);
2127 Expect(Token::SEMICOLON, CHECK_OK); 2134 Expect(Token::SEMICOLON, CHECK_OK);
2128 2135
2129 // Make sure that the function containing the native declaration 2136 // Make sure that the function containing the native declaration
2130 // isn't lazily compiled. The extension structures are only 2137 // isn't lazily compiled. The extension structures are only
2131 // accessible while parsing the first time not when reparsing 2138 // accessible while parsing the first time not when reparsing
2132 // because of lazy compilation. 2139 // because of lazy compilation.
2133 // TODO(adamk): Should this be ClosureScope()? 2140 // TODO(adamk): Should this be GetClosureScope()?
2134 scope()->DeclarationScope()->ForceEagerCompilation(); 2141 scope()->GetDeclarationScope()->ForceEagerCompilation();
2135 2142
2136 // TODO(1240846): It's weird that native function declarations are 2143 // TODO(1240846): It's weird that native function declarations are
2137 // introduced dynamically when we meet their declarations, whereas 2144 // introduced dynamically when we meet their declarations, whereas
2138 // other functions are set up when entering the surrounding scope. 2145 // other functions are set up when entering the surrounding scope.
2139 VariableProxy* proxy = NewUnresolved(name, VAR); 2146 VariableProxy* proxy = NewUnresolved(name, VAR);
2140 Declaration* declaration = 2147 Declaration* declaration =
2141 factory()->NewVariableDeclaration(proxy, VAR, scope(), pos); 2148 factory()->NewVariableDeclaration(proxy, VAR, scope(), pos);
2142 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2149 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2143 NativeFunctionLiteral* lit = 2150 NativeFunctionLiteral* lit =
2144 factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition); 2151 factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); 2241 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition);
2235 // Async functions don't undergo sloppy mode block scoped hoisting, and don't 2242 // Async functions don't undergo sloppy mode block scoped hoisting, and don't
2236 // allow duplicates in a block. Both are represented by the 2243 // allow duplicates in a block. Both are represented by the
2237 // sloppy_block_function_map. Don't add them to the map for async functions. 2244 // sloppy_block_function_map. Don't add them to the map for async functions.
2238 // Generators are also supposed to be prohibited; currently doing this behind 2245 // Generators are also supposed to be prohibited; currently doing this behind
2239 // a flag and UseCounting violations to assess web compatibility. 2246 // a flag and UseCounting violations to assess web compatibility.
2240 if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() && 2247 if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() &&
2241 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) { 2248 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) {
2242 SloppyBlockFunctionStatement* delegate = 2249 SloppyBlockFunctionStatement* delegate =
2243 factory()->NewSloppyBlockFunctionStatement(empty, scope()); 2250 factory()->NewSloppyBlockFunctionStatement(empty, scope());
2244 scope()->DeclarationScope()->sloppy_block_function_map()->Declare( 2251 scope()->GetDeclarationScope()->sloppy_block_function_map()->Declare(
2245 variable_name, delegate); 2252 variable_name, delegate);
2246 return delegate; 2253 return delegate;
2247 } 2254 }
2248 return empty; 2255 return empty;
2249 } 2256 }
2250 2257
2251 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, 2258 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
2252 bool default_export, bool* ok) { 2259 bool default_export, bool* ok) {
2253 // ClassDeclaration :: 2260 // ClassDeclaration ::
2254 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}' 2261 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
2801 ExpectSemicolon(CHECK_OK); 2808 ExpectSemicolon(CHECK_OK);
2802 2809
2803 if (is_generator()) { 2810 if (is_generator()) {
2804 return_value = BuildIteratorResult(return_value, true); 2811 return_value = BuildIteratorResult(return_value, true);
2805 } else if (is_async_function()) { 2812 } else if (is_async_function()) {
2806 return_value = BuildPromiseResolve(return_value, return_value->position()); 2813 return_value = BuildPromiseResolve(return_value, return_value->position());
2807 } 2814 }
2808 2815
2809 result = factory()->NewReturnStatement(return_value, loc.beg_pos); 2816 result = factory()->NewReturnStatement(return_value, loc.beg_pos);
2810 2817
2811 Scope* decl_scope = scope()->DeclarationScope(); 2818 DeclarationScope* decl_scope = scope()->GetDeclarationScope();
2812 if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) { 2819 if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) {
2813 ReportMessageAt(loc, MessageTemplate::kIllegalReturn); 2820 ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
2814 *ok = false; 2821 *ok = false;
2815 return NULL; 2822 return NULL;
2816 } 2823 }
2817 return result; 2824 return result;
2818 } 2825 }
2819 2826
2820 2827
2821 Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels, 2828 Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels,
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
4201 DoExpression* Parser::ParseDoExpression(bool* ok) { 4208 DoExpression* Parser::ParseDoExpression(bool* ok) {
4202 // AssignmentExpression :: 4209 // AssignmentExpression ::
4203 // do '{' StatementList '}' 4210 // do '{' StatementList '}'
4204 int pos = peek_position(); 4211 int pos = peek_position();
4205 4212
4206 Expect(Token::DO, CHECK_OK); 4213 Expect(Token::DO, CHECK_OK);
4207 Variable* result = 4214 Variable* result =
4208 scope()->NewTemporary(ast_value_factory()->dot_result_string()); 4215 scope()->NewTemporary(ast_value_factory()->dot_result_string());
4209 Block* block = ParseBlock(nullptr, CHECK_OK); 4216 Block* block = ParseBlock(nullptr, CHECK_OK);
4210 DoExpression* expr = factory()->NewDoExpression(block, result, pos); 4217 DoExpression* expr = factory()->NewDoExpression(block, result, pos);
4211 if (!Rewriter::Rewrite(this, scope()->ClosureScope(), expr, 4218 if (!Rewriter::Rewrite(this, scope()->GetClosureScope(), expr,
4212 ast_value_factory())) { 4219 ast_value_factory())) {
4213 *ok = false; 4220 *ok = false;
4214 return nullptr; 4221 return nullptr;
4215 } 4222 }
4216 return expr; 4223 return expr;
4217 } 4224 }
4218 4225
4219 void ParserTraits::ParseArrowFunctionFormalParameterList( 4226 void ParserTraits::ParseArrowFunctionFormalParameterList(
4220 ParserFormalParameters* parameters, Expression* expr, 4227 ParserFormalParameters* parameters, Expression* expr,
4221 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, 4228 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
4350 // - The function literal shouldn't be hinted to eagerly compile. 4357 // - The function literal shouldn't be hinted to eagerly compile.
4351 // - For asm.js functions the body needs to be available when module 4358 // - For asm.js functions the body needs to be available when module
4352 // validation is active, because we examine the entire module at once. 4359 // validation is active, because we examine the entire module at once.
4353 bool use_temp_zone = 4360 bool use_temp_zone =
4354 !is_lazily_parsed && FLAG_lazy && !allow_natives() && 4361 !is_lazily_parsed && FLAG_lazy && !allow_natives() &&
4355 extension_ == NULL && allow_lazy() && 4362 extension_ == NULL && allow_lazy() &&
4356 function_type == FunctionLiteral::kDeclaration && 4363 function_type == FunctionLiteral::kDeclaration &&
4357 eager_compile_hint != FunctionLiteral::kShouldEagerCompile && 4364 eager_compile_hint != FunctionLiteral::kShouldEagerCompile &&
4358 !(FLAG_validate_asm && scope()->asm_module()); 4365 !(FLAG_validate_asm && scope()->asm_module());
4359 4366
4360 Scope* main_scope = nullptr; 4367 DeclarationScope* main_scope = nullptr;
4361 if (use_temp_zone) { 4368 if (use_temp_zone) {
4362 // This Scope lives in the main Zone; we'll migrate data into it later. 4369 // This Scope lives in the main Zone; we'll migrate data into it later.
4363 main_scope = NewFunctionScope(kind); 4370 main_scope = NewFunctionScope(kind);
4364 } 4371 }
4365 4372
4366 ZoneList<Statement*>* body = nullptr; 4373 ZoneList<Statement*>* body = nullptr;
4367 int arity = -1; 4374 int arity = -1;
4368 int materialized_literal_count = -1; 4375 int materialized_literal_count = -1;
4369 int expected_property_count = -1; 4376 int expected_property_count = -1;
4370 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 4377 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
4371 bool should_be_used_once_hint = false; 4378 bool should_be_used_once_hint = false;
4372 bool has_duplicate_parameters; 4379 bool has_duplicate_parameters;
4373 4380
4374 { 4381 {
4375 // Temporary zones can nest. When we migrate free variables (see below), we 4382 // Temporary zones can nest. When we migrate free variables (see below), we
4376 // need to recreate them in the previous Zone. 4383 // need to recreate them in the previous Zone.
4377 AstNodeFactory previous_zone_ast_node_factory(ast_value_factory()); 4384 AstNodeFactory previous_zone_ast_node_factory(ast_value_factory());
4378 previous_zone_ast_node_factory.set_zone(zone()); 4385 previous_zone_ast_node_factory.set_zone(zone());
4379 4386
4380 // Open a new zone scope, which sets our AstNodeFactory to allocate in the 4387 // Open a new zone scope, which sets our AstNodeFactory to allocate in the
4381 // new temporary zone if the preconditions are satisfied, and ensures that 4388 // new temporary zone if the preconditions are satisfied, and ensures that
4382 // the previous zone is always restored after parsing the body. To be able 4389 // the previous zone is always restored after parsing the body. To be able
4383 // to do scope analysis correctly after full parsing, we migrate needed 4390 // to do scope analysis correctly after full parsing, we migrate needed
4384 // information from scope into main_scope when the function has been parsed. 4391 // information from scope into main_scope when the function has been parsed.
4385 Zone temp_zone(zone()->allocator()); 4392 Zone temp_zone(zone()->allocator());
4386 DiscardableZoneScope zone_scope(this, &temp_zone, use_temp_zone); 4393 DiscardableZoneScope zone_scope(this, &temp_zone, use_temp_zone);
4387 4394
4388 Scope* scope = NewFunctionScope(kind); 4395 DeclarationScope* scope = NewFunctionScope(kind);
4389 SetLanguageMode(scope, language_mode); 4396 SetLanguageMode(scope, language_mode);
4390 if (!use_temp_zone) { 4397 if (!use_temp_zone) {
4391 main_scope = scope; 4398 main_scope = scope;
4392 } else { 4399 } else {
4393 DCHECK(main_scope->zone() != scope->zone()); 4400 DCHECK(main_scope->zone() != scope->zone());
4394 } 4401 }
4395 4402
4396 FunctionState function_state(&function_state_, &scope_state_, scope, kind); 4403 FunctionState function_state(&function_state_, &scope_state_, scope, kind);
4397 #ifdef DEBUG 4404 #ifdef DEBUG
4398 this->scope()->SetScopeName(function_name); 4405 scope->SetScopeName(function_name);
4399 #endif 4406 #endif
4400 ExpressionClassifier formals_classifier(this, &duplicate_finder); 4407 ExpressionClassifier formals_classifier(this, &duplicate_finder);
4401 4408
4402 if (is_generator) { 4409 if (is_generator) {
4403 // For generators, allocating variables in contexts is currently a win 4410 // For generators, allocating variables in contexts is currently a win
4404 // because it minimizes the work needed to suspend and resume an 4411 // because it minimizes the work needed to suspend and resume an
4405 // activation. The machine code produced for generators (by full-codegen) 4412 // activation. The machine code produced for generators (by full-codegen)
4406 // relies on this forced context allocation, but not in an essential way. 4413 // relies on this forced context allocation, but not in an essential way.
4407 this->scope()->ForceContextAllocation(); 4414 this->scope()->ForceContextAllocation();
4408 4415
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
4724 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition); 4731 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition);
4725 initial_value = factory()->NewConditional( 4732 initial_value = factory()->NewConditional(
4726 condition, parameter.initializer, initial_value, kNoSourcePosition); 4733 condition, parameter.initializer, initial_value, kNoSourcePosition);
4727 descriptor.initialization_pos = parameter.initializer->position(); 4734 descriptor.initialization_pos = parameter.initializer->position();
4728 initializer_position = parameter.initializer_end_position; 4735 initializer_position = parameter.initializer_end_position;
4729 } 4736 }
4730 4737
4731 Scope* param_scope = scope(); 4738 Scope* param_scope = scope();
4732 Block* param_block = init_block; 4739 Block* param_block = init_block;
4733 if (!parameter.is_simple() && scope()->calls_sloppy_eval()) { 4740 if (!parameter.is_simple() && scope()->calls_sloppy_eval()) {
4734 param_scope = NewScope(BLOCK_SCOPE); 4741 param_scope = NewVarblockScope();
4735 param_scope->set_is_declaration_scope();
4736 param_scope->set_start_position(descriptor.initialization_pos); 4742 param_scope->set_start_position(descriptor.initialization_pos);
4737 param_scope->set_end_position(parameter.initializer_end_position); 4743 param_scope->set_end_position(parameter.initializer_end_position);
4738 param_scope->RecordEvalCall(); 4744 param_scope->RecordEvalCall();
4739 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); 4745 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
4740 param_block->set_scope(param_scope); 4746 param_block->set_scope(param_scope);
4741 descriptor.hoist_scope = scope(); 4747 descriptor.hoist_scope = scope();
4742 // Pass the appropriate scope in so that PatternRewriter can appropriately 4748 // Pass the appropriate scope in so that PatternRewriter can appropriately
4743 // rewrite inner initializers of the pattern to param_scope 4749 // rewrite inner initializers of the pattern to param_scope
4744 descriptor.scope = param_scope; 4750 descriptor.scope = param_scope;
4745 // Rewrite the outer initializer to point to param_scope 4751 // Rewrite the outer initializer to point to param_scope
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
4831 // If we have a named function expression, we add a local variable 4837 // If we have a named function expression, we add a local variable
4832 // declaration to the body of the function with the name of the 4838 // declaration to the body of the function with the name of the
4833 // function and let it refer to the function itself (closure). 4839 // function and let it refer to the function itself (closure).
4834 // Not having parsed the function body, the language mode may still change, 4840 // Not having parsed the function body, the language mode may still change,
4835 // so we reserve a spot and create the actual const assignment later. 4841 // so we reserve a spot and create the actual const assignment later.
4836 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length()); 4842 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length());
4837 result->Add(NULL, zone()); 4843 result->Add(NULL, zone());
4838 } 4844 }
4839 4845
4840 ZoneList<Statement*>* body = result; 4846 ZoneList<Statement*>* body = result;
4841 Scope* inner_scope = scope(); 4847 DeclarationScope* function_scope = scope()->AsDeclarationScope();
4848 DeclarationScope* inner_scope = function_scope;
4842 Block* inner_block = nullptr; 4849 Block* inner_block = nullptr;
4843 if (!parameters.is_simple) { 4850 if (!parameters.is_simple) {
4844 inner_scope = NewScope(BLOCK_SCOPE); 4851 inner_scope = NewVarblockScope();
4845 inner_scope->set_is_declaration_scope();
4846 inner_scope->set_start_position(scanner()->location().beg_pos); 4852 inner_scope->set_start_position(scanner()->location().beg_pos);
4847 inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); 4853 inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
4848 inner_block->set_scope(inner_scope); 4854 inner_block->set_scope(inner_scope);
4849 body = inner_block->statements(); 4855 body = inner_block->statements();
4850 } 4856 }
4851 4857
4852 { 4858 {
4853 BlockState block_state(&scope_state_, inner_scope); 4859 BlockState block_state(&scope_state_, inner_scope);
4854 4860
4855 if (IsGeneratorFunction(kind)) { 4861 if (IsGeneratorFunction(kind)) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4921 kNoSourcePosition), 4927 kNoSourcePosition),
4922 zone()); 4928 zone());
4923 } 4929 }
4924 } 4930 }
4925 4931
4926 Expect(Token::RBRACE, CHECK_OK); 4932 Expect(Token::RBRACE, CHECK_OK);
4927 scope()->set_end_position(scanner()->location().end_pos); 4933 scope()->set_end_position(scanner()->location().end_pos);
4928 4934
4929 if (!parameters.is_simple) { 4935 if (!parameters.is_simple) {
4930 DCHECK_NOT_NULL(inner_scope); 4936 DCHECK_NOT_NULL(inner_scope);
4937 DCHECK_EQ(function_scope, scope());
4938 DCHECK_EQ(function_scope, inner_scope->outer_scope());
4931 DCHECK_EQ(body, inner_block->statements()); 4939 DCHECK_EQ(body, inner_block->statements());
4932 SetLanguageMode(scope(), inner_scope->language_mode()); 4940 SetLanguageMode(function_scope, inner_scope->language_mode());
4933 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); 4941 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK);
4934 4942
4935 if (is_sloppy(inner_scope->language_mode())) { 4943 if (is_sloppy(inner_scope->language_mode())) {
4936 InsertSloppyBlockFunctionVarBindings( 4944 InsertSloppyBlockFunctionVarBindings(inner_scope, function_scope,
4937 inner_scope, inner_scope->outer_scope(), CHECK_OK); 4945 CHECK_OK);
4938 } 4946 }
4939 4947
4940 if (IsAsyncFunction(kind)) { 4948 if (IsAsyncFunction(kind)) {
4941 init_block = BuildRejectPromiseOnException(init_block); 4949 init_block = BuildRejectPromiseOnException(init_block);
4942 } 4950 }
4943 4951
4944 DCHECK_NOT_NULL(init_block); 4952 DCHECK_NOT_NULL(init_block);
4945 4953
4946 inner_scope->set_end_position(scanner()->location().end_pos); 4954 inner_scope->set_end_position(scanner()->location().end_pos);
4947 inner_scope = inner_scope->FinalizeBlockScope(); 4955 if (inner_scope->FinalizeBlockScope() != nullptr) {
adamk 2016/08/04 00:18:51 I don't think it's worth changing this, there's so
Toon Verwaest 2016/08/04 12:01:17 inner_scope is a DeclarationScope, and FinalizeBlo
4948 if (inner_scope != nullptr) {
4949 CheckConflictingVarDeclarations(inner_scope, CHECK_OK); 4956 CheckConflictingVarDeclarations(inner_scope, CHECK_OK);
4950 InsertShadowingVarBindingInitializers(inner_block); 4957 InsertShadowingVarBindingInitializers(inner_block);
4951 } 4958 }
4952 4959
4953 result->Add(init_block, zone()); 4960 result->Add(init_block, zone());
4954 result->Add(inner_block, zone()); 4961 result->Add(inner_block, zone());
4955 } else { 4962 } else {
4956 if (is_sloppy(inner_scope->language_mode())) { 4963 DCHECK_EQ(inner_scope, function_scope);
4957 InsertSloppyBlockFunctionVarBindings(inner_scope, nullptr, CHECK_OK); 4964 if (is_sloppy(function_scope->language_mode())) {
4965 InsertSloppyBlockFunctionVarBindings(function_scope, nullptr, CHECK_OK);
4958 } 4966 }
4959 } 4967 }
4960 4968
4961 if (function_type == FunctionLiteral::kNamedExpression) { 4969 if (function_type == FunctionLiteral::kNamedExpression) {
4962 // Now that we know the language mode, we can create the const assignment 4970 // Now that we know the language mode, we can create the const assignment
4963 // in the previously reserved spot. 4971 // in the previously reserved spot.
4964 // NOTE: We create a proxy and resolve it here so that in the 4972 // NOTE: We create a proxy and resolve it here so that in the
4965 // future we can change the AST to only refer to VariableProxies 4973 // future we can change the AST to only refer to VariableProxies
4966 // instead of Variables and Proxies as is the case now. 4974 // instead of Variables and Proxies as is the case now.
4975 DCHECK_EQ(function_scope, scope());
4967 VariableMode fvar_mode = is_strict(language_mode()) ? CONST : CONST_LEGACY; 4976 VariableMode fvar_mode = is_strict(language_mode()) ? CONST : CONST_LEGACY;
4968 Variable* fvar = new (zone()) 4977 Variable* fvar = new (zone())
4969 Variable(scope(), function_name, fvar_mode, Variable::NORMAL, 4978 Variable(scope(), function_name, fvar_mode, Variable::NORMAL,
4970 kCreatedInitialized, kNotAssigned); 4979 kCreatedInitialized, kNotAssigned);
4971 VariableProxy* proxy = factory()->NewVariableProxy(fvar); 4980 VariableProxy* proxy = factory()->NewVariableProxy(fvar);
4972 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( 4981 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
4973 proxy, fvar_mode, scope(), kNoSourcePosition); 4982 proxy, fvar_mode, scope(), kNoSourcePosition);
4974 scope()->DeclareFunctionVar(fvar_declaration); 4983 function_scope->DeclareFunctionVar(fvar_declaration);
4975 4984
4976 VariableProxy* fproxy = factory()->NewVariableProxy(fvar); 4985 VariableProxy* fproxy = factory()->NewVariableProxy(fvar);
4977 result->Set(kFunctionNameAssignmentIndex, 4986 result->Set(kFunctionNameAssignmentIndex,
4978 factory()->NewExpressionStatement( 4987 factory()->NewExpressionStatement(
4979 factory()->NewAssignment(Token::INIT, fproxy, 4988 factory()->NewAssignment(Token::INIT, fproxy,
4980 factory()->NewThisFunction(pos), 4989 factory()->NewThisFunction(pos),
4981 kNoSourcePosition), 4990 kNoSourcePosition),
4982 kNoSourcePosition)); 4991 kNoSourcePosition));
4983 } 4992 }
4984 4993
(...skipping 23 matching lines...) Expand all
5008 SET_ALLOW(harmony_for_in); 5017 SET_ALLOW(harmony_for_in);
5009 SET_ALLOW(harmony_function_sent); 5018 SET_ALLOW(harmony_function_sent);
5010 SET_ALLOW(harmony_exponentiation_operator); 5019 SET_ALLOW(harmony_exponentiation_operator);
5011 SET_ALLOW(harmony_restrictive_declarations); 5020 SET_ALLOW(harmony_restrictive_declarations);
5012 SET_ALLOW(harmony_async_await); 5021 SET_ALLOW(harmony_async_await);
5013 SET_ALLOW(harmony_trailing_commas); 5022 SET_ALLOW(harmony_trailing_commas);
5014 #undef SET_ALLOW 5023 #undef SET_ALLOW
5015 } 5024 }
5016 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 5025 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
5017 language_mode(), function_state_->kind(), 5026 language_mode(), function_state_->kind(),
5018 scope()->has_simple_parameters(), parsing_module_, logger, bookmark, 5027 scope()->AsDeclarationScope()->has_simple_parameters(), parsing_module_,
5019 use_counts_); 5028 logger, bookmark, use_counts_);
5020 if (pre_parse_timer_ != NULL) { 5029 if (pre_parse_timer_ != NULL) {
5021 pre_parse_timer_->Stop(); 5030 pre_parse_timer_->Stop();
5022 } 5031 }
5023 return result; 5032 return result;
5024 } 5033 }
5025 5034
5026 Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier, 5035 Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
5027 const AstRawString* name, 5036 const AstRawString* name,
5028 Scanner::Location class_name_location, 5037 Scanner::Location class_name_location,
5029 bool name_is_strict_reserved, int pos, 5038 bool name_is_strict_reserved, int pos,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5135 scope()->NewTemporary(ast_value_factory()->empty_string()); 5144 scope()->NewTemporary(ast_value_factory()->empty_string());
5136 do_block->set_scope(block_state.FinalizedBlockScope()); 5145 do_block->set_scope(block_state.FinalizedBlockScope());
5137 DoExpression* do_expr = factory()->NewDoExpression(do_block, result_var, pos); 5146 DoExpression* do_expr = factory()->NewDoExpression(do_block, result_var, pos);
5138 5147
5139 ClassLiteral* class_literal = factory()->NewClassLiteral( 5148 ClassLiteral* class_literal = factory()->NewClassLiteral(
5140 proxy, extends, constructor, properties, pos, end_pos); 5149 proxy, extends, constructor, properties, pos, end_pos);
5141 5150
5142 do_block->statements()->Add( 5151 do_block->statements()->Add(
5143 factory()->NewExpressionStatement(class_literal, pos), zone()); 5152 factory()->NewExpressionStatement(class_literal, pos), zone());
5144 do_expr->set_represented_function(constructor); 5153 do_expr->set_represented_function(constructor);
5145 Rewriter::Rewrite(this, scope()->ClosureScope(), do_expr, 5154 Rewriter::Rewrite(this, scope()->GetClosureScope(), do_expr,
5146 ast_value_factory()); 5155 ast_value_factory());
5147 5156
5148 return do_expr; 5157 return do_expr;
5149 } 5158 }
5150 5159
5151 5160
5152 Expression* Parser::ParseV8Intrinsic(bool* ok) { 5161 Expression* Parser::ParseV8Intrinsic(bool* ok) {
5153 // CallRuntime :: 5162 // CallRuntime ::
5154 // '%' Identifier Arguments 5163 // '%' Identifier Arguments
5155 5164
5156 int pos = peek_position(); 5165 int pos = peek_position();
5157 Expect(Token::MOD, CHECK_OK); 5166 Expect(Token::MOD, CHECK_OK);
5158 // Allow "eval" or "arguments" for backward compatibility. 5167 // Allow "eval" or "arguments" for backward compatibility.
5159 const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers, 5168 const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers,
5160 CHECK_OK); 5169 CHECK_OK);
5161 Scanner::Location spread_pos; 5170 Scanner::Location spread_pos;
5162 ExpressionClassifier classifier(this); 5171 ExpressionClassifier classifier(this);
5163 ZoneList<Expression*>* args = 5172 ZoneList<Expression*>* args =
5164 ParseArguments(&spread_pos, &classifier, CHECK_OK); 5173 ParseArguments(&spread_pos, &classifier, CHECK_OK);
5165 5174
5166 DCHECK(!spread_pos.IsValid()); 5175 DCHECK(!spread_pos.IsValid());
5167 5176
5168 if (extension_ != NULL) { 5177 if (extension_ != NULL) {
5169 // The extension structures are only accessible while parsing the 5178 // The extension structures are only accessible while parsing the
5170 // very first time not when reparsing because of lazy compilation. 5179 // very first time not when reparsing because of lazy compilation.
5171 scope()->DeclarationScope()->ForceEagerCompilation(); 5180 scope()->GetDeclarationScope()->ForceEagerCompilation();
5172 } 5181 }
5173 5182
5174 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 5183 const Runtime::Function* function = Runtime::FunctionForName(name->string());
5175 5184
5176 if (function != NULL) { 5185 if (function != NULL) {
5177 // Check for possible name clash. 5186 // Check for possible name clash.
5178 DCHECK_EQ(Context::kNotFound, 5187 DCHECK_EQ(Context::kNotFound,
5179 Context::IntrinsicIndexForName(name->string())); 5188 Context::IntrinsicIndexForName(name->string()));
5180 // Check for built-in IS_VAR macro. 5189 // Check for built-in IS_VAR macro.
5181 if (function->function_id == Runtime::kIS_VAR) { 5190 if (function->function_id == Runtime::kIS_VAR) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
5254 VariableProxy* to = inner_scope->NewUnresolved(factory(), name); 5263 VariableProxy* to = inner_scope->NewUnresolved(factory(), name);
5255 VariableProxy* from = factory()->NewVariableProxy(parameter); 5264 VariableProxy* from = factory()->NewVariableProxy(parameter);
5256 Expression* assignment = 5265 Expression* assignment =
5257 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition); 5266 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition);
5258 Statement* statement = 5267 Statement* statement =
5259 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 5268 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
5260 inner_block->statements()->InsertAt(0, statement, zone()); 5269 inner_block->statements()->InsertAt(0, statement, zone());
5261 } 5270 }
5262 } 5271 }
5263 5272
5264 void Parser::InsertSloppyBlockFunctionVarBindings(Scope* scope, 5273 void Parser::InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope,
5265 Scope* complex_params_scope, 5274 Scope* complex_params_scope,
5266 bool* ok) { 5275 bool* ok) {
5267 // For each variable which is used as a function declaration in a sloppy 5276 // For each variable which is used as a function declaration in a sloppy
5268 // block, 5277 // block,
5269 DCHECK(scope->is_declaration_scope());
5270 SloppyBlockFunctionMap* map = scope->sloppy_block_function_map(); 5278 SloppyBlockFunctionMap* map = scope->sloppy_block_function_map();
5271 for (ZoneHashMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) { 5279 for (ZoneHashMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) {
5272 AstRawString* name = static_cast<AstRawString*>(p->key); 5280 AstRawString* name = static_cast<AstRawString*>(p->key);
5273 5281
5274 // If the variable wouldn't conflict with a lexical declaration 5282 // If the variable wouldn't conflict with a lexical declaration
5275 // or parameter, 5283 // or parameter,
5276 5284
5277 // Check if there's a conflict with a parameter. 5285 // Check if there's a conflict with a parameter.
5278 // This depends on the fact that functions always have a scope solely to 5286 // This depends on the fact that functions always have a scope solely to
5279 // hold complex parameters, and the names local to that scope are 5287 // hold complex parameters, and the names local to that scope are
(...skipping 11 matching lines...) Expand all
5291 continue; 5299 continue;
5292 } 5300 }
5293 } 5301 }
5294 5302
5295 bool var_created = false; 5303 bool var_created = false;
5296 5304
5297 // Write in assignments to var for each block-scoped function declaration 5305 // Write in assignments to var for each block-scoped function declaration
5298 auto delegates = static_cast<SloppyBlockFunctionMap::Vector*>(p->value); 5306 auto delegates = static_cast<SloppyBlockFunctionMap::Vector*>(p->value);
5299 for (SloppyBlockFunctionStatement* delegate : *delegates) { 5307 for (SloppyBlockFunctionStatement* delegate : *delegates) {
5300 // Check if there's a conflict with a lexical declaration 5308 // Check if there's a conflict with a lexical declaration
5301 Scope* decl_scope = scope; 5309 DeclarationScope* decl_scope = scope;
5302 while (decl_scope->is_eval_scope()) { 5310 while (decl_scope->is_eval_scope()) {
5303 decl_scope = decl_scope->outer_scope()->DeclarationScope(); 5311 decl_scope = decl_scope->outer_scope()->GetDeclarationScope();
5304 } 5312 }
5305 Scope* outer_scope = decl_scope->outer_scope(); 5313 Scope* outer_scope = decl_scope->outer_scope();
5306 Scope* query_scope = delegate->scope()->outer_scope(); 5314 Scope* query_scope = delegate->scope()->outer_scope();
5307 Variable* var = nullptr; 5315 Variable* var = nullptr;
5308 bool should_hoist = true; 5316 bool should_hoist = true;
5309 5317
5310 // Note that we perform this loop for each delegate named 'name', 5318 // Note that we perform this loop for each delegate named 'name',
5311 // which may duplicate work if those delegates share scopes. 5319 // which may duplicate work if those delegates share scopes.
5312 // It is not sufficient to just do a Lookup on query_scope: for 5320 // It is not sufficient to just do a Lookup on query_scope: for
5313 // example, that does not prevent hoisting of the function in 5321 // example, that does not prevent hoisting of the function in
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after
6645 do_block_->statements()->Add(validate_iterator, zone); 6653 do_block_->statements()->Add(validate_iterator, zone);
6646 do_block_->statements()->Add(loop, zone); 6654 do_block_->statements()->Add(loop, zone);
6647 do_block_->statements()->Add(maybe_return_value, zone); 6655 do_block_->statements()->Add(maybe_return_value, zone);
6648 6656
6649 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); 6657 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos);
6650 do_block->statements()->Add(do_block_, zone); 6658 do_block->statements()->Add(do_block_, zone);
6651 do_block->statements()->Add(get_value, zone); 6659 do_block->statements()->Add(get_value, zone);
6652 6660
6653 Variable* dot_result = scope->NewTemporary(avfactory->dot_result_string()); 6661 Variable* dot_result = scope->NewTemporary(avfactory->dot_result_string());
6654 yield_star = factory->NewDoExpression(do_block, dot_result, nopos); 6662 yield_star = factory->NewDoExpression(do_block, dot_result, nopos);
6655 Rewriter::Rewrite(parser_, scope->ClosureScope(), yield_star, avfactory); 6663 Rewriter::Rewrite(parser_, scope->GetClosureScope(), yield_star, avfactory);
6656 } 6664 }
6657 6665
6658 return yield_star; 6666 return yield_star;
6659 } 6667 }
6660 6668
6661 Statement* ParserTraits::CheckCallable(Variable* var, Expression* error, 6669 Statement* ParserTraits::CheckCallable(Variable* var, Expression* error,
6662 int pos) { 6670 int pos) {
6663 auto factory = parser_->factory(); 6671 auto factory = parser_->factory();
6664 auto avfactory = parser_->ast_value_factory(); 6672 auto avfactory = parser_->ast_value_factory();
6665 const int nopos = kNoSourcePosition; 6673 const int nopos = kNoSourcePosition;
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
7122 node->Print(Isolate::Current()); 7130 node->Print(Isolate::Current());
7123 } 7131 }
7124 #endif // DEBUG 7132 #endif // DEBUG
7125 7133
7126 #undef CHECK_OK 7134 #undef CHECK_OK
7127 #undef CHECK_OK_VOID 7135 #undef CHECK_OK_VOID
7128 #undef CHECK_FAILED 7136 #undef CHECK_FAILED
7129 7137
7130 } // namespace internal 7138 } // namespace internal
7131 } // namespace v8 7139 } // namespace v8
OLDNEW
« src/ast/scopes.h ('K') | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698