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

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

Issue 2160593002: Introduce parent ScopeState class and track the scope through the state in the parser (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 5 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
« no previous file with comments | « no previous file | src/parsing/parser-base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind); 192 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind);
193 SetLanguageMode(function_scope, 193 SetLanguageMode(function_scope,
194 static_cast<LanguageMode>(language_mode | STRICT)); 194 static_cast<LanguageMode>(language_mode | STRICT));
195 // Set start and end position to the same value 195 // Set start and end position to the same value
196 function_scope->set_start_position(pos); 196 function_scope->set_start_position(pos);
197 function_scope->set_end_position(pos); 197 function_scope->set_end_position(pos);
198 ZoneList<Statement*>* body = NULL; 198 ZoneList<Statement*>* body = NULL;
199 199
200 { 200 {
201 AstNodeFactory function_factory(ast_value_factory()); 201 AstNodeFactory function_factory(ast_value_factory());
202 FunctionState function_state(&function_state_, &scope_, function_scope, 202 FunctionState function_state(&function_state_, &scope_state_,
203 kind, &function_factory); 203 function_scope, kind, &function_factory);
204 204
205 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); 205 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone());
206 if (call_super) { 206 if (call_super) {
207 // $super_constructor = %_GetSuperConstructor(<this-function>) 207 // $super_constructor = %_GetSuperConstructor(<this-function>)
208 // %reflect_construct( 208 // %reflect_construct(
209 // $super_constructor, InternalArray(...args), new.target) 209 // $super_constructor, InternalArray(...args), new.target)
210 auto constructor_args_name = ast_value_factory()->empty_string(); 210 auto constructor_args_name = ast_value_factory()->empty_string();
211 bool is_duplicate; 211 bool is_duplicate;
212 bool is_rest = true; 212 bool is_rest = true;
213 bool is_optional = false; 213 bool is_optional = false;
214 Variable* constructor_args = 214 Variable* constructor_args =
215 function_scope->DeclareParameter(constructor_args_name, TEMPORARY, 215 function_scope->DeclareParameter(constructor_args_name, TEMPORARY,
216 is_optional, is_rest, &is_duplicate); 216 is_optional, is_rest, &is_duplicate);
217 217
218 ZoneList<Expression*>* args = 218 ZoneList<Expression*>* args =
219 new (zone()) ZoneList<Expression*>(2, zone()); 219 new (zone()) ZoneList<Expression*>(2, zone());
220 VariableProxy* this_function_proxy = scope_->NewUnresolved( 220 VariableProxy* this_function_proxy = this->scope()->NewUnresolved(
221 factory(), ast_value_factory()->this_function_string(), 221 factory(), ast_value_factory()->this_function_string(),
222 Variable::NORMAL, pos); 222 Variable::NORMAL, pos);
223 ZoneList<Expression*>* tmp = 223 ZoneList<Expression*>* tmp =
224 new (zone()) ZoneList<Expression*>(1, zone()); 224 new (zone()) ZoneList<Expression*>(1, zone());
225 tmp->Add(this_function_proxy, zone()); 225 tmp->Add(this_function_proxy, zone());
226 Expression* super_constructor = factory()->NewCallRuntime( 226 Expression* super_constructor = factory()->NewCallRuntime(
227 Runtime::kInlineGetSuperConstructor, tmp, pos); 227 Runtime::kInlineGetSuperConstructor, tmp, pos);
228 args->Add(super_constructor, zone()); 228 args->Add(super_constructor, zone());
229 Spread* spread_args = factory()->NewSpread( 229 Spread* spread_args = factory()->NewSpread(
230 factory()->NewVariableProxy(constructor_args), pos, pos); 230 factory()->NewVariableProxy(constructor_args), pos, pos);
231 ZoneList<Expression*>* spread_args_expr = 231 ZoneList<Expression*>* spread_args_expr =
232 new (zone()) ZoneList<Expression*>(1, zone()); 232 new (zone()) ZoneList<Expression*>(1, zone());
233 spread_args_expr->Add(spread_args, zone()); 233 spread_args_expr->Add(spread_args, zone());
234 args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone()); 234 args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone());
235 VariableProxy* new_target_proxy = scope_->NewUnresolved( 235 VariableProxy* new_target_proxy = this->scope()->NewUnresolved(
236 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, 236 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL,
237 pos); 237 pos);
238 args->Add(new_target_proxy, zone()); 238 args->Add(new_target_proxy, zone());
239 CallRuntime* call = factory()->NewCallRuntime( 239 CallRuntime* call = factory()->NewCallRuntime(
240 Context::REFLECT_CONSTRUCT_INDEX, args, pos); 240 Context::REFLECT_CONSTRUCT_INDEX, args, pos);
241 body->Add(factory()->NewReturnStatement(call, pos), zone()); 241 body->Add(factory()->NewReturnStatement(call, pos), zone());
242 } 242 }
243 243
244 materialized_literal_count = function_state.materialized_literal_count(); 244 materialized_literal_count = function_state.materialized_literal_count();
245 expected_property_count = function_state.expected_property_count(); 245 expected_property_count = function_state.expected_property_count();
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 log_ = NULL; 902 log_ = NULL;
903 } 903 }
904 return result; 904 return result;
905 } 905 }
906 906
907 907
908 FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { 908 FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
909 // Note that this function can be called from the main thread or from a 909 // Note that this function can be called from the main thread or from a
910 // background thread. We should not access anything Isolate / heap dependent 910 // background thread. We should not access anything Isolate / heap dependent
911 // via ParseInfo, and also not pass it forward. 911 // via ParseInfo, and also not pass it forward.
912 DCHECK(scope_ == NULL); 912 DCHECK_NULL(scope_state_);
913 DCHECK(target_stack_ == NULL); 913 DCHECK_NULL(target_stack_);
914 914
915 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; 915 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY;
916 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; 916 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY;
917 917
918 FunctionLiteral* result = NULL; 918 FunctionLiteral* result = NULL;
919 { 919 {
920 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native 920 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native
921 // context, which will have the "this" binding for script scopes. 921 // context, which will have the "this" binding for script scopes.
922 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); 922 Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
923 info->set_script_scope(scope); 923 info->set_script_scope(scope);
924 if (!info->context().is_null() && !info->context()->IsNativeContext()) { 924 if (!info->context().is_null() && !info->context()->IsNativeContext()) {
925 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), 925 scope = Scope::DeserializeScopeChain(info->isolate(), zone(),
926 *info->context(), scope); 926 *info->context(), scope);
927 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this 927 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
928 // means the Parser cannot operate independent of the V8 heap. Tell the 928 // means the Parser cannot operate independent of the V8 heap. Tell the
929 // string table to internalize strings and values right after they're 929 // string table to internalize strings and values right after they're
930 // created. This kind of parsing can only be done in the main thread. 930 // created. This kind of parsing can only be done in the main thread.
931 DCHECK(parsing_on_main_thread_); 931 DCHECK(parsing_on_main_thread_);
932 ast_value_factory()->Internalize(info->isolate()); 932 ast_value_factory()->Internalize(info->isolate());
933 } 933 }
934 original_scope_ = scope; 934 original_scope_ = scope;
935 if (info->is_eval()) { 935 if (info->is_eval()) {
936 if (!scope->is_script_scope() || is_strict(info->language_mode())) { 936 if (!scope->is_script_scope() || is_strict(info->language_mode())) {
937 parsing_mode = PARSE_EAGERLY; 937 parsing_mode = PARSE_EAGERLY;
938 } 938 }
939 scope = NewScope(scope, EVAL_SCOPE); 939 scope = NewScope(scope, EVAL_SCOPE);
940 } else if (info->is_module()) { 940 } else if (info->is_module()) {
941 scope = NewScope(scope, MODULE_SCOPE); 941 scope = NewScope(scope, MODULE_SCOPE);
942 } 942 }
943 943
944 scope->set_start_position(0); 944 scope->set_start_position(0);
945 945
946 // Enter 'scope' with the given parsing mode. 946 // Enter 'scope' with the given parsing mode.
947 ParsingModeScope parsing_mode_scope(this, parsing_mode); 947 ParsingModeScope parsing_mode_scope(this, parsing_mode);
948 AstNodeFactory function_factory(ast_value_factory()); 948 AstNodeFactory function_factory(ast_value_factory());
949 FunctionState function_state(&function_state_, &scope_, scope, 949 FunctionState function_state(&function_state_, &scope_state_, scope,
950 kNormalFunction, &function_factory); 950 kNormalFunction, &function_factory);
951 951
952 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 952 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
953 bool ok = true; 953 bool ok = true;
954 int beg_pos = scanner()->location().beg_pos; 954 int beg_pos = scanner()->location().beg_pos;
955 parsing_module_ = info->is_module(); 955 parsing_module_ = info->is_module();
956 if (parsing_module_) { 956 if (parsing_module_) {
957 ParseModuleItemList(body, &ok); 957 ParseModuleItemList(body, &ok);
958 ok = ok && 958 ok = ok &&
959 scope_->module()->Validate(scope_, &pending_error_handler_, zone()); 959 module()->Validate(this->scope(), &pending_error_handler_, zone());
960 } else { 960 } else {
961 // Don't count the mode in the use counters--give the program a chance 961 // Don't count the mode in the use counters--give the program a chance
962 // to enable script-wide strict mode below. 962 // to enable script-wide strict mode below.
963 scope_->SetLanguageMode(info->language_mode()); 963 this->scope()->SetLanguageMode(info->language_mode());
964 ParseStatementList(body, Token::EOS, &ok); 964 ParseStatementList(body, Token::EOS, &ok);
965 } 965 }
966 966
967 // The parser will peek but not consume EOS. Our scope logically goes all 967 // The parser will peek but not consume EOS. Our scope logically goes all
968 // the way to the EOS, though. 968 // the way to the EOS, though.
969 scope->set_end_position(scanner()->peek_location().beg_pos); 969 scope->set_end_position(scanner()->peek_location().beg_pos);
970 970
971 if (ok && is_strict(language_mode())) { 971 if (ok && is_strict(language_mode())) {
972 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 972 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
973 CheckDecimalLiteralWithLeadingZero(use_counts_, beg_pos, 973 CheckDecimalLiteralWithLeadingZero(use_counts_, beg_pos,
974 scanner()->location().end_pos); 974 scanner()->location().end_pos);
975 } 975 }
976 if (ok && is_sloppy(language_mode())) { 976 if (ok && is_sloppy(language_mode())) {
977 // TODO(littledan): Function bindings on the global object that modify 977 // TODO(littledan): Function bindings on the global object that modify
978 // pre-existing bindings should be made writable, enumerable and 978 // pre-existing bindings should be made writable, enumerable and
979 // nonconfigurable if possible, whereas this code will leave attributes 979 // nonconfigurable if possible, whereas this code will leave attributes
980 // unchanged if the property already exists. 980 // unchanged if the property already exists.
981 InsertSloppyBlockFunctionVarBindings(scope, nullptr, &ok); 981 InsertSloppyBlockFunctionVarBindings(scope, nullptr, &ok);
982 } 982 }
983 if (ok) { 983 if (ok) {
984 CheckConflictingVarDeclarations(scope_, &ok); 984 CheckConflictingVarDeclarations(this->scope(), &ok);
985 } 985 }
986 986
987 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 987 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
988 if (body->length() != 1 || 988 if (body->length() != 1 ||
989 !body->at(0)->IsExpressionStatement() || 989 !body->at(0)->IsExpressionStatement() ||
990 !body->at(0)->AsExpressionStatement()-> 990 !body->at(0)->AsExpressionStatement()->
991 expression()->IsFunctionLiteral()) { 991 expression()->IsFunctionLiteral()) {
992 ReportMessage(MessageTemplate::kSingleFunctionLiteral); 992 ReportMessage(MessageTemplate::kSingleFunctionLiteral);
993 ok = false; 993 ok = false;
994 } 994 }
995 } 995 }
996 996
997 if (ok) { 997 if (ok) {
998 ParserTraits::RewriteDestructuringAssignments(); 998 ParserTraits::RewriteDestructuringAssignments();
999 result = factory()->NewScriptOrEvalFunctionLiteral( 999 result = factory()->NewScriptOrEvalFunctionLiteral(
1000 scope_, body, function_state.materialized_literal_count(), 1000 this->scope(), body, function_state.materialized_literal_count(),
1001 function_state.expected_property_count()); 1001 function_state.expected_property_count());
1002 } 1002 }
1003 } 1003 }
1004 1004
1005 // Make sure the target stack is empty. 1005 // Make sure the target stack is empty.
1006 DCHECK(target_stack_ == NULL); 1006 DCHECK(target_stack_ == NULL);
1007 1007
1008 return result; 1008 return result;
1009 } 1009 }
1010 1010
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 IsAccessorFunction(shared_info->kind())) { 1059 IsAccessorFunction(shared_info->kind())) {
1060 return FunctionLiteral::kAccessorOrMethod; 1060 return FunctionLiteral::kAccessorOrMethod;
1061 } 1061 }
1062 return FunctionLiteral::kAnonymousExpression; 1062 return FunctionLiteral::kAnonymousExpression;
1063 } 1063 }
1064 1064
1065 FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, 1065 FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
1066 Utf16CharacterStream* source) { 1066 Utf16CharacterStream* source) {
1067 Handle<SharedFunctionInfo> shared_info = info->shared_info(); 1067 Handle<SharedFunctionInfo> shared_info = info->shared_info();
1068 scanner_.Initialize(source); 1068 scanner_.Initialize(source);
1069 DCHECK(scope_ == NULL); 1069 DCHECK_NULL(scope_state_);
1070 DCHECK(target_stack_ == NULL); 1070 DCHECK_NULL(target_stack_);
1071 1071
1072 Handle<String> name(String::cast(shared_info->name())); 1072 Handle<String> name(String::cast(shared_info->name()));
1073 DCHECK(ast_value_factory()); 1073 DCHECK(ast_value_factory());
1074 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); 1074 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone());
1075 const AstRawString* raw_name = ast_value_factory()->GetString(name); 1075 const AstRawString* raw_name = ast_value_factory()->GetString(name);
1076 fni_->PushEnclosingName(raw_name); 1076 fni_->PushEnclosingName(raw_name);
1077 1077
1078 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1078 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1079 1079
1080 // Place holder for the result. 1080 // Place holder for the result.
1081 FunctionLiteral* result = NULL; 1081 FunctionLiteral* result = nullptr;
1082 1082
1083 { 1083 {
1084 // Parse the function literal. 1084 // Parse the function literal.
1085 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); 1085 Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
1086 info->set_script_scope(scope); 1086 info->set_script_scope(scope);
1087 if (!info->context().is_null()) { 1087 if (!info->context().is_null()) {
1088 // Ok to use Isolate here, since lazy function parsing is only done in the 1088 // Ok to use Isolate here, since lazy function parsing is only done in the
1089 // main thread. 1089 // main thread.
1090 DCHECK(parsing_on_main_thread_); 1090 DCHECK(parsing_on_main_thread_);
1091 scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(), 1091 scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(),
1092 scope); 1092 scope);
1093 } 1093 }
1094 original_scope_ = scope; 1094 original_scope_ = scope;
1095 AstNodeFactory function_factory(ast_value_factory()); 1095 AstNodeFactory function_factory(ast_value_factory());
1096 FunctionState function_state(&function_state_, &scope_, scope, 1096 FunctionState function_state(&function_state_, &scope_state_, scope,
1097 shared_info->kind(), &function_factory); 1097 shared_info->kind(), &function_factory);
1098 DCHECK(is_sloppy(scope->language_mode()) || 1098 DCHECK(is_sloppy(scope->language_mode()) ||
1099 is_strict(info->language_mode())); 1099 is_strict(info->language_mode()));
1100 DCHECK(info->language_mode() == shared_info->language_mode()); 1100 DCHECK(info->language_mode() == shared_info->language_mode());
1101 FunctionLiteral::FunctionType function_type = 1101 FunctionLiteral::FunctionType function_type =
1102 ComputeFunctionType(shared_info); 1102 ComputeFunctionType(shared_info);
1103 bool ok = true; 1103 bool ok = true;
1104 1104
1105 if (shared_info->is_arrow()) { 1105 if (shared_info->is_arrow()) {
1106 bool is_async = allow_harmony_async_await() && shared_info->is_async(); 1106 bool is_async = allow_harmony_async_await() && shared_info->is_async();
1107 if (is_async) { 1107 if (is_async) {
1108 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); 1108 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext());
1109 if (!Check(Token::ASYNC)) { 1109 if (!Check(Token::ASYNC)) {
1110 CHECK(stack_overflow()); 1110 CHECK(stack_overflow());
1111 return nullptr; 1111 return nullptr;
1112 } 1112 }
1113 if (!(peek_any_identifier() || peek() == Token::LPAREN)) { 1113 if (!(peek_any_identifier() || peek() == Token::LPAREN)) {
1114 CHECK(stack_overflow()); 1114 CHECK(stack_overflow());
1115 return nullptr; 1115 return nullptr;
1116 } 1116 }
1117 } 1117 }
1118 1118
1119 // TODO(adamk): We should construct this scope from the ScopeInfo. 1119 // TODO(adamk): We should construct this scope from the ScopeInfo.
1120 Scope* scope = 1120 Scope* scope =
1121 NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); 1121 NewScope(this->scope(), FUNCTION_SCOPE, FunctionKind::kArrowFunction);
1122 1122
1123 // These two bits only need to be explicitly set because we're 1123 // These two bits only need to be explicitly set because we're
1124 // not passing the ScopeInfo to the Scope constructor. 1124 // not passing the ScopeInfo to the Scope constructor.
1125 // TODO(adamk): Remove these calls once the above NewScope call 1125 // TODO(adamk): Remove these calls once the above NewScope call
1126 // passes the ScopeInfo. 1126 // passes the ScopeInfo.
1127 if (shared_info->scope_info()->CallsEval()) { 1127 if (shared_info->scope_info()->CallsEval()) {
1128 scope->RecordEvalCall(); 1128 scope->RecordEvalCall();
1129 } 1129 }
1130 SetLanguageMode(scope, shared_info->language_mode()); 1130 SetLanguageMode(scope, shared_info->language_mode());
1131 1131
1132 scope->set_start_position(shared_info->start_position()); 1132 scope->set_start_position(shared_info->start_position());
1133 ExpressionClassifier formals_classifier(this); 1133 ExpressionClassifier formals_classifier(this);
1134 ParserFormalParameters formals(scope); 1134 ParserFormalParameters formals(scope);
1135 Checkpoint checkpoint(this); 1135 Checkpoint checkpoint(this);
1136 { 1136 {
1137 // Parsing patterns as variable reference expression creates 1137 // Parsing patterns as variable reference expression creates
1138 // NewUnresolved references in current scope. Entrer arrow function 1138 // NewUnresolved references in current scope. Entrer arrow function
1139 // scope for formal parameter parsing. 1139 // scope for formal parameter parsing.
1140 BlockState block_state(&scope_, scope); 1140 BlockState block_state(&scope_state_, scope);
1141 if (Check(Token::LPAREN)) { 1141 if (Check(Token::LPAREN)) {
1142 // '(' StrictFormalParameters ')' 1142 // '(' StrictFormalParameters ')'
1143 ParseFormalParameterList(&formals, &formals_classifier, &ok); 1143 ParseFormalParameterList(&formals, &formals_classifier, &ok);
1144 if (ok) ok = Check(Token::RPAREN); 1144 if (ok) ok = Check(Token::RPAREN);
1145 } else { 1145 } else {
1146 // BindingIdentifier 1146 // BindingIdentifier
1147 ParseFormalParameter(&formals, &formals_classifier, &ok); 1147 ParseFormalParameter(&formals, &formals_classifier, &ok);
1148 if (ok) { 1148 if (ok) {
1149 DeclareFormalParameter(formals.scope, formals.at(0), 1149 DeclareFormalParameter(formals.scope, formals.at(0),
1150 &formals_classifier); 1150 &formals_classifier);
(...skipping 29 matching lines...) Expand all
1180 raw_name, IsSubclassConstructor(shared_info->kind()), scope, 1180 raw_name, IsSubclassConstructor(shared_info->kind()), scope,
1181 shared_info->start_position(), shared_info->end_position(), 1181 shared_info->start_position(), shared_info->end_position(),
1182 shared_info->language_mode()); 1182 shared_info->language_mode());
1183 } else { 1183 } else {
1184 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), 1184 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(),
1185 kSkipFunctionNameCheck, shared_info->kind(), 1185 kSkipFunctionNameCheck, shared_info->kind(),
1186 kNoSourcePosition, function_type, 1186 kNoSourcePosition, function_type,
1187 shared_info->language_mode(), &ok); 1187 shared_info->language_mode(), &ok);
1188 } 1188 }
1189 // Make sure the results agree. 1189 // Make sure the results agree.
1190 DCHECK(ok == (result != NULL)); 1190 DCHECK(ok == (result != nullptr));
1191 } 1191 }
1192 1192
1193 // Make sure the target stack is empty. 1193 // Make sure the target stack is empty.
1194 DCHECK(target_stack_ == NULL); 1194 DCHECK_NULL(target_stack_);
1195 1195
1196 if (result != NULL) { 1196 if (result != nullptr) {
1197 Handle<String> inferred_name(shared_info->inferred_name()); 1197 Handle<String> inferred_name(shared_info->inferred_name());
1198 result->set_inferred_name(inferred_name); 1198 result->set_inferred_name(inferred_name);
1199 } 1199 }
1200 return result; 1200 return result;
1201 } 1201 }
1202 1202
1203 1203
1204 void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, 1204 void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
1205 bool* ok) { 1205 bool* ok) {
1206 // StatementList :: 1206 // StatementList ::
(...skipping 28 matching lines...) Expand all
1235 if ((e_stat = stat->AsExpressionStatement()) != NULL && 1235 if ((e_stat = stat->AsExpressionStatement()) != NULL &&
1236 (literal = e_stat->expression()->AsLiteral()) != NULL && 1236 (literal = e_stat->expression()->AsLiteral()) != NULL &&
1237 literal->raw_value()->IsString()) { 1237 literal->raw_value()->IsString()) {
1238 // Check "use strict" directive (ES5 14.1), "use asm" directive. 1238 // Check "use strict" directive (ES5 14.1), "use asm" directive.
1239 bool use_strict_found = 1239 bool use_strict_found =
1240 literal->raw_value()->AsString() == 1240 literal->raw_value()->AsString() ==
1241 ast_value_factory()->use_strict_string() && 1241 ast_value_factory()->use_strict_string() &&
1242 token_loc.end_pos - token_loc.beg_pos == 1242 token_loc.end_pos - token_loc.beg_pos ==
1243 ast_value_factory()->use_strict_string()->length() + 2; 1243 ast_value_factory()->use_strict_string()->length() + 2;
1244 if (use_strict_found) { 1244 if (use_strict_found) {
1245 if (is_sloppy(scope_->language_mode())) { 1245 if (is_sloppy(this->scope()->language_mode())) {
1246 RaiseLanguageMode(STRICT); 1246 RaiseLanguageMode(STRICT);
1247 } 1247 }
1248 1248
1249 if (!scope_->HasSimpleParameters()) { 1249 if (!this->scope()->HasSimpleParameters()) {
1250 // TC39 deemed "use strict" directives to be an error when occurring 1250 // TC39 deemed "use strict" directives to be an error when occurring
1251 // in the body of a function with non-simple parameter list, on 1251 // in the body of a function with non-simple parameter list, on
1252 // 29/7/2015. https://goo.gl/ueA7Ln 1252 // 29/7/2015. https://goo.gl/ueA7Ln
1253 const AstRawString* string = literal->raw_value()->AsString(); 1253 const AstRawString* string = literal->raw_value()->AsString();
1254 ParserTraits::ReportMessageAt( 1254 ParserTraits::ReportMessageAt(
1255 token_loc, MessageTemplate::kIllegalLanguageModeDirective, 1255 token_loc, MessageTemplate::kIllegalLanguageModeDirective,
1256 string); 1256 string);
1257 *ok = false; 1257 *ok = false;
1258 return nullptr; 1258 return nullptr;
1259 } 1259 }
1260 // Because declarations in strict eval code don't leak into the scope 1260 // Because declarations in strict eval code don't leak into the scope
1261 // of the eval call, it is likely that functions declared in strict 1261 // of the eval call, it is likely that functions declared in strict
1262 // eval code will be used within the eval code, so lazy parsing is 1262 // eval code will be used within the eval code, so lazy parsing is
1263 // probably not a win. 1263 // probably not a win.
1264 if (scope_->is_eval_scope()) mode_ = PARSE_EAGERLY; 1264 if (this->scope()->is_eval_scope()) mode_ = PARSE_EAGERLY;
1265 } else if (literal->raw_value()->AsString() == 1265 } else if (literal->raw_value()->AsString() ==
1266 ast_value_factory()->use_asm_string() && 1266 ast_value_factory()->use_asm_string() &&
1267 token_loc.end_pos - token_loc.beg_pos == 1267 token_loc.end_pos - token_loc.beg_pos ==
1268 ast_value_factory()->use_asm_string()->length() + 2) { 1268 ast_value_factory()->use_asm_string()->length() + 2) {
1269 // Store the usage count; The actual use counter on the isolate is 1269 // Store the usage count; The actual use counter on the isolate is
1270 // incremented after parsing is done. 1270 // incremented after parsing is done.
1271 ++use_counts_[v8::Isolate::kUseAsm]; 1271 ++use_counts_[v8::Isolate::kUseAsm];
1272 scope_->SetAsmModule(); 1272 this->scope()->SetAsmModule();
1273 } else { 1273 } else {
1274 // Should not change mode, but will increment UseCounter 1274 // Should not change mode, but will increment UseCounter
1275 // if appropriate. Ditto usages below. 1275 // if appropriate. Ditto usages below.
1276 RaiseLanguageMode(SLOPPY); 1276 RaiseLanguageMode(SLOPPY);
1277 } 1277 }
1278 } else { 1278 } else {
1279 // End of the directive prologue. 1279 // End of the directive prologue.
1280 directive_prologue = false; 1280 directive_prologue = false;
1281 RaiseLanguageMode(SLOPPY); 1281 RaiseLanguageMode(SLOPPY);
1282 } 1282 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 1347
1348 void* Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) { 1348 void* Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) {
1349 // ecma262/#prod-Module 1349 // ecma262/#prod-Module
1350 // Module : 1350 // Module :
1351 // ModuleBody? 1351 // ModuleBody?
1352 // 1352 //
1353 // ecma262/#prod-ModuleItemList 1353 // ecma262/#prod-ModuleItemList
1354 // ModuleBody : 1354 // ModuleBody :
1355 // ModuleItem* 1355 // ModuleItem*
1356 1356
1357 DCHECK(scope_->is_module_scope()); 1357 DCHECK(scope()->is_module_scope());
1358 while (peek() != Token::EOS) { 1358 while (peek() != Token::EOS) {
1359 Statement* stat = ParseModuleItem(CHECK_OK); 1359 Statement* stat = ParseModuleItem(CHECK_OK);
1360 if (stat && !stat->IsEmpty()) { 1360 if (stat && !stat->IsEmpty()) {
1361 body->Add(stat, zone()); 1361 body->Add(stat, zone());
1362 } 1362 }
1363 } 1363 }
1364 return nullptr; 1364 return nullptr;
1365 } 1365 }
1366 1366
1367 1367
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 1492
1493 int pos = peek_position(); 1493 int pos = peek_position();
1494 Expect(Token::IMPORT, CHECK_OK); 1494 Expect(Token::IMPORT, CHECK_OK);
1495 1495
1496 Token::Value tok = peek(); 1496 Token::Value tok = peek();
1497 1497
1498 // 'import' ModuleSpecifier ';' 1498 // 'import' ModuleSpecifier ';'
1499 if (tok == Token::STRING) { 1499 if (tok == Token::STRING) {
1500 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK); 1500 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK);
1501 ExpectSemicolon(CHECK_OK); 1501 ExpectSemicolon(CHECK_OK);
1502 scope_->module()->AddEmptyImport( 1502 module()->AddEmptyImport(module_specifier, scanner()->location(), zone());
1503 module_specifier, scanner()->location(), zone());
1504 return nullptr; 1503 return nullptr;
1505 } 1504 }
1506 1505
1507 // Parse ImportedDefaultBinding if present. 1506 // Parse ImportedDefaultBinding if present.
1508 const AstRawString* import_default_binding = nullptr; 1507 const AstRawString* import_default_binding = nullptr;
1509 Scanner::Location import_default_binding_loc; 1508 Scanner::Location import_default_binding_loc;
1510 if (tok != Token::MUL && tok != Token::LBRACE) { 1509 if (tok != Token::MUL && tok != Token::LBRACE) {
1511 import_default_binding = 1510 import_default_binding =
1512 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); 1511 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
1513 import_default_binding_loc = scanner()->location(); 1512 import_default_binding_loc = scanner()->location();
(...skipping 27 matching lines...) Expand all
1541 } 1540 }
1542 1541
1543 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); 1542 ExpectContextualKeyword(CStrVector("from"), CHECK_OK);
1544 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK); 1543 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK);
1545 ExpectSemicolon(CHECK_OK); 1544 ExpectSemicolon(CHECK_OK);
1546 1545
1547 // Now that we have all the information, we can make the appropriate 1546 // Now that we have all the information, we can make the appropriate
1548 // declarations. 1547 // declarations.
1549 1548
1550 if (module_namespace_binding != nullptr) { 1549 if (module_namespace_binding != nullptr) {
1551 scope_->module()->AddStarImport( 1550 module()->AddStarImport(module_namespace_binding, module_specifier,
1552 module_namespace_binding, module_specifier, 1551 module_namespace_binding_loc, zone());
1553 module_namespace_binding_loc, zone());
1554 // TODO(neis): Create special immutable binding for the namespace object. 1552 // TODO(neis): Create special immutable binding for the namespace object.
1555 } 1553 }
1556 1554
1557 // TODO(neis): Would prefer to call DeclareImport below rather than above and 1555 // TODO(neis): Would prefer to call DeclareImport below rather than above and
1558 // in ParseNamedImports, but then a possible error message would point to the 1556 // in ParseNamedImports, but then a possible error message would point to the
1559 // wrong location. Maybe have a DeclareAt version of Declare that takes a 1557 // wrong location. Maybe have a DeclareAt version of Declare that takes a
1560 // location? 1558 // location?
1561 1559
1562 if (import_default_binding != nullptr) { 1560 if (import_default_binding != nullptr) {
1563 scope_->module()->AddImport( 1561 module()->AddImport(ast_value_factory()->default_string(),
1564 ast_value_factory()->default_string(), import_default_binding, 1562 import_default_binding, module_specifier,
1565 module_specifier, import_default_binding_loc, zone()); 1563 import_default_binding_loc, zone());
1566 // DeclareImport(import_default_binding, pos, CHECK_OK); 1564 // DeclareImport(import_default_binding, pos, CHECK_OK);
1567 } 1565 }
1568 1566
1569 if (named_imports != nullptr) { 1567 if (named_imports != nullptr) {
1570 if (named_imports->length() == 0) { 1568 if (named_imports->length() == 0) {
1571 scope_->module()->AddEmptyImport( 1569 module()->AddEmptyImport(module_specifier, scanner()->location(), zone());
1572 module_specifier, scanner()->location(), zone());
1573 } else { 1570 } else {
1574 for (int i = 0; i < named_imports->length(); ++i) { 1571 for (int i = 0; i < named_imports->length(); ++i) {
1575 const NamedImport* import = named_imports->at(i); 1572 const NamedImport* import = named_imports->at(i);
1576 scope_->module()->AddImport( 1573 module()->AddImport(import->import_name, import->local_name,
1577 import->import_name, import->local_name, 1574 module_specifier, import->location, zone());
1578 module_specifier, import->location, zone());
1579 // DeclareImport(import->local_name, pos, CHECK_OK); 1575 // DeclareImport(import->local_name, pos, CHECK_OK);
1580 } 1576 }
1581 } 1577 }
1582 } 1578 }
1583 1579
1584 return nullptr; 1580 return nullptr;
1585 } 1581 }
1586 1582
1587 1583
1588 Statement* Parser::ParseExportDefault(bool* ok) { 1584 Statement* Parser::ParseExportDefault(bool* ok) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 SetFunctionName(value, ast_value_factory()->default_string()); 1620 SetFunctionName(value, ast_value_factory()->default_string());
1625 1621
1626 const AstRawString* local_name = 1622 const AstRawString* local_name =
1627 ast_value_factory()->star_default_star_string(); 1623 ast_value_factory()->star_default_star_string();
1628 local_names.Add(local_name, zone()); 1624 local_names.Add(local_name, zone());
1629 1625
1630 // It's fine to declare this as CONST because the user has no way of 1626 // It's fine to declare this as CONST because the user has no way of
1631 // writing to it. 1627 // writing to it.
1632 VariableProxy* proxy = NewUnresolved(local_name, CONST); 1628 VariableProxy* proxy = NewUnresolved(local_name, CONST);
1633 Declaration* declaration = 1629 Declaration* declaration =
1634 factory()->NewVariableDeclaration(proxy, CONST, scope_, pos); 1630 factory()->NewVariableDeclaration(proxy, CONST, scope(), pos);
1635 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 1631 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
1636 proxy->var()->set_initializer_position(position()); 1632 proxy->var()->set_initializer_position(position());
1637 1633
1638 Assignment* assignment = factory()->NewAssignment( 1634 Assignment* assignment = factory()->NewAssignment(
1639 Token::INIT, proxy, value, kNoSourcePosition); 1635 Token::INIT, proxy, value, kNoSourcePosition);
1640 result = factory()->NewExpressionStatement(assignment, kNoSourcePosition); 1636 result = factory()->NewExpressionStatement(assignment, kNoSourcePosition);
1641 1637
1642 ExpectSemicolon(CHECK_OK); 1638 ExpectSemicolon(CHECK_OK);
1643 break; 1639 break;
1644 } 1640 }
1645 } 1641 }
1646 1642
1647 DCHECK_EQ(local_names.length(), 1); 1643 DCHECK_EQ(local_names.length(), 1);
1648 scope_->module()->AddExport( 1644 module()->AddExport(local_names.first(),
1649 local_names.first(), ast_value_factory()->default_string(), default_loc, 1645 ast_value_factory()->default_string(), default_loc,
1650 zone()); 1646 zone());
1651 1647
1652 DCHECK_NOT_NULL(result); 1648 DCHECK_NOT_NULL(result);
1653 return result; 1649 return result;
1654 } 1650 }
1655 1651
1656 Statement* Parser::ParseExportDeclaration(bool* ok) { 1652 Statement* Parser::ParseExportDeclaration(bool* ok) {
1657 // ExportDeclaration: 1653 // ExportDeclaration:
1658 // 'export' '*' 'from' ModuleSpecifier ';' 1654 // 'export' '*' 'from' ModuleSpecifier ';'
1659 // 'export' ExportClause ('from' ModuleSpecifier)? ';' 1655 // 'export' ExportClause ('from' ModuleSpecifier)? ';'
1660 // 'export' VariableStatement 1656 // 'export' VariableStatement
1661 // 'export' Declaration 1657 // 'export' Declaration
1662 // 'export' 'default' ... (handled in ParseExportDefault) 1658 // 'export' 'default' ... (handled in ParseExportDefault)
1663 1659
1664 int pos = peek_position(); 1660 int pos = peek_position();
1665 Expect(Token::EXPORT, CHECK_OK); 1661 Expect(Token::EXPORT, CHECK_OK);
1666 1662
1667 Statement* result = nullptr; 1663 Statement* result = nullptr;
1668 ZoneList<const AstRawString*> names(1, zone()); 1664 ZoneList<const AstRawString*> names(1, zone());
1669 switch (peek()) { 1665 switch (peek()) {
1670 case Token::DEFAULT: 1666 case Token::DEFAULT:
1671 return ParseExportDefault(ok); 1667 return ParseExportDefault(ok);
1672 1668
1673 case Token::MUL: { 1669 case Token::MUL: {
1674 Consume(Token::MUL); 1670 Consume(Token::MUL);
1675 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); 1671 ExpectContextualKeyword(CStrVector("from"), CHECK_OK);
1676 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK); 1672 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK);
1677 ExpectSemicolon(CHECK_OK); 1673 ExpectSemicolon(CHECK_OK);
1678 scope_->module()->AddStarExport( 1674 module()->AddStarExport(module_specifier, scanner()->location(), zone());
1679 module_specifier, scanner()->location(), zone());
1680 return factory()->NewEmptyStatement(pos); 1675 return factory()->NewEmptyStatement(pos);
1681 } 1676 }
1682 1677
1683 case Token::LBRACE: { 1678 case Token::LBRACE: {
1684 // There are two cases here: 1679 // There are two cases here:
1685 // 1680 //
1686 // 'export' ExportClause ';' 1681 // 'export' ExportClause ';'
1687 // and 1682 // and
1688 // 'export' ExportClause FromClause ';' 1683 // 'export' ExportClause FromClause ';'
1689 // 1684 //
(...skipping 16 matching lines...) Expand all
1706 *ok = false; 1701 *ok = false;
1707 ReportMessageAt(reserved_loc, MessageTemplate::kUnexpectedReserved); 1702 ReportMessageAt(reserved_loc, MessageTemplate::kUnexpectedReserved);
1708 return nullptr; 1703 return nullptr;
1709 } 1704 }
1710 ExpectSemicolon(CHECK_OK); 1705 ExpectSemicolon(CHECK_OK);
1711 const int length = export_names.length(); 1706 const int length = export_names.length();
1712 DCHECK_EQ(length, original_names.length()); 1707 DCHECK_EQ(length, original_names.length());
1713 DCHECK_EQ(length, export_locations.length()); 1708 DCHECK_EQ(length, export_locations.length());
1714 if (module_specifier == nullptr) { 1709 if (module_specifier == nullptr) {
1715 for (int i = 0; i < length; ++i) { 1710 for (int i = 0; i < length; ++i) {
1716 scope_->module()->AddExport(original_names[i], export_names[i], 1711 module()->AddExport(original_names[i], export_names[i],
1717 export_locations[i], zone()); 1712 export_locations[i], zone());
1718 } 1713 }
1719 } else if (length == 0) { 1714 } else if (length == 0) {
1720 scope_->module()->AddEmptyImport( 1715 module()->AddEmptyImport(module_specifier, scanner()->location(),
1721 module_specifier, scanner()->location(), zone()); 1716 zone());
1722 } else { 1717 } else {
1723 for (int i = 0; i < length; ++i) { 1718 for (int i = 0; i < length; ++i) {
1724 scope_->module()->AddExport( 1719 module()->AddExport(original_names[i], export_names[i],
1725 original_names[i], export_names[i], module_specifier, 1720 module_specifier, export_locations[i], zone());
1726 export_locations[i], zone());
1727 } 1721 }
1728 } 1722 }
1729 return factory()->NewEmptyStatement(pos); 1723 return factory()->NewEmptyStatement(pos);
1730 } 1724 }
1731 1725
1732 case Token::FUNCTION: 1726 case Token::FUNCTION:
1733 result = ParseHoistableDeclaration(&names, false, CHECK_OK); 1727 result = ParseHoistableDeclaration(&names, false, CHECK_OK);
1734 break; 1728 break;
1735 1729
1736 case Token::CLASS: 1730 case Token::CLASS:
(...skipping 16 matching lines...) Expand all
1753 break; 1747 break;
1754 } 1748 }
1755 /* falls through */ 1749 /* falls through */
1756 1750
1757 default: 1751 default:
1758 *ok = false; 1752 *ok = false;
1759 ReportUnexpectedToken(scanner()->current_token()); 1753 ReportUnexpectedToken(scanner()->current_token());
1760 return nullptr; 1754 return nullptr;
1761 } 1755 }
1762 1756
1763 ModuleDescriptor* descriptor = scope_->module(); 1757 ModuleDescriptor* descriptor = module();
1764 for (int i = 0; i < names.length(); ++i) { 1758 for (int i = 0; i < names.length(); ++i) {
1765 // TODO(neis): Provide better location. 1759 // TODO(neis): Provide better location.
1766 descriptor->AddExport(names[i], names[i], scanner()->location(), zone()); 1760 descriptor->AddExport(names[i], names[i], scanner()->location(), zone());
1767 } 1761 }
1768 1762
1769 DCHECK_NOT_NULL(result); 1763 DCHECK_NOT_NULL(result);
1770 return result; 1764 return result;
1771 } 1765 }
1772 1766
1773 Statement* Parser::ParseStatement(ZoneList<const AstRawString*>* labels, 1767 Statement* Parser::ParseStatement(ZoneList<const AstRawString*>* labels,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 } 1897 }
1904 } 1898 }
1905 1899
1906 1900
1907 VariableProxy* Parser::NewUnresolved(const AstRawString* name, 1901 VariableProxy* Parser::NewUnresolved(const AstRawString* name,
1908 VariableMode mode) { 1902 VariableMode mode) {
1909 // If we are inside a function, a declaration of a 'var' variable is a 1903 // If we are inside a function, a declaration of a 'var' variable is a
1910 // truly local variable, and the scope of the variable is always the function 1904 // truly local variable, and the scope of the variable is always the function
1911 // scope. 1905 // scope.
1912 // Let/const variables are always added to the immediately enclosing scope. 1906 // Let/const variables are always added to the immediately enclosing scope.
1913 Scope* scope = 1907 Scope* scope = IsLexicalVariableMode(mode)
1914 IsLexicalVariableMode(mode) ? scope_ : scope_->DeclarationScope(); 1908 ? this->scope()
1909 : this->scope()->DeclarationScope();
1915 return scope->NewUnresolved(factory(), name, Variable::NORMAL, 1910 return scope->NewUnresolved(factory(), name, Variable::NORMAL,
1916 scanner()->location().beg_pos, 1911 scanner()->location().beg_pos,
1917 scanner()->location().end_pos); 1912 scanner()->location().end_pos);
1918 } 1913 }
1919 1914
1920 1915
1921 void* Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { 1916 void* Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) {
1922 DCHECK_NOT_NULL(local_name); 1917 DCHECK_NOT_NULL(local_name);
1923 VariableProxy* proxy = NewUnresolved(local_name, IMPORT); 1918 VariableProxy* proxy = NewUnresolved(local_name, IMPORT);
1924 Declaration* declaration = 1919 Declaration* declaration =
1925 factory()->NewVariableDeclaration(proxy, IMPORT, scope_, pos); 1920 factory()->NewVariableDeclaration(proxy, IMPORT, scope(), pos);
1926 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 1921 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
1927 return nullptr; 1922 return nullptr;
1928 } 1923 }
1929 1924
1930 1925
1931 Variable* Parser::Declare(Declaration* declaration, 1926 Variable* Parser::Declare(Declaration* declaration,
1932 DeclarationDescriptor::Kind declaration_kind, 1927 DeclarationDescriptor::Kind declaration_kind,
1933 bool resolve, bool* ok, Scope* scope) { 1928 bool resolve, bool* ok, Scope* scope) {
1934 VariableProxy* proxy = declaration->proxy(); 1929 VariableProxy* proxy = declaration->proxy();
1935 DCHECK(proxy->raw_name() != NULL); 1930 DCHECK(proxy->raw_name() != NULL);
1936 const AstRawString* name = proxy->raw_name(); 1931 const AstRawString* name = proxy->raw_name();
1937 VariableMode mode = declaration->mode(); 1932 VariableMode mode = declaration->mode();
1938 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); 1933 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY);
1939 bool is_function_declaration = declaration->IsFunctionDeclaration(); 1934 bool is_function_declaration = declaration->IsFunctionDeclaration();
1940 if (scope == nullptr) scope = scope_; 1935 if (scope == nullptr) scope = this->scope();
1941 Scope* declaration_scope = 1936 Scope* declaration_scope =
1942 IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope(); 1937 IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope();
1943 Variable* var = NULL; 1938 Variable* var = NULL;
1944 1939
1945 // If a suitable scope exists, then we can statically declare this 1940 // If a suitable scope exists, then we can statically declare this
1946 // variable and also set its mode. In any case, a Declaration node 1941 // variable and also set its mode. In any case, a Declaration node
1947 // will be added to the scope so that the declaration can be added 1942 // will be added to the scope so that the declaration can be added
1948 // to the corresponding activation frame at runtime if necessary. 1943 // to the corresponding activation frame at runtime if necessary.
1949 // For instance, var declarations inside a sloppy eval scope need 1944 // For instance, var declarations inside a sloppy eval scope need
1950 // to be added to the calling function context. Similarly, strict 1945 // to be added to the calling function context. Similarly, strict
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 } 2097 }
2103 } 2098 }
2104 Expect(Token::RPAREN, CHECK_OK); 2099 Expect(Token::RPAREN, CHECK_OK);
2105 Expect(Token::SEMICOLON, CHECK_OK); 2100 Expect(Token::SEMICOLON, CHECK_OK);
2106 2101
2107 // Make sure that the function containing the native declaration 2102 // Make sure that the function containing the native declaration
2108 // isn't lazily compiled. The extension structures are only 2103 // isn't lazily compiled. The extension structures are only
2109 // accessible while parsing the first time not when reparsing 2104 // accessible while parsing the first time not when reparsing
2110 // because of lazy compilation. 2105 // because of lazy compilation.
2111 // TODO(adamk): Should this be ClosureScope()? 2106 // TODO(adamk): Should this be ClosureScope()?
2112 scope_->DeclarationScope()->ForceEagerCompilation(); 2107 scope()->DeclarationScope()->ForceEagerCompilation();
2113 2108
2114 // TODO(1240846): It's weird that native function declarations are 2109 // TODO(1240846): It's weird that native function declarations are
2115 // introduced dynamically when we meet their declarations, whereas 2110 // introduced dynamically when we meet their declarations, whereas
2116 // other functions are set up when entering the surrounding scope. 2111 // other functions are set up when entering the surrounding scope.
2117 VariableProxy* proxy = NewUnresolved(name, VAR); 2112 VariableProxy* proxy = NewUnresolved(name, VAR);
2118 Declaration* declaration = 2113 Declaration* declaration =
2119 factory()->NewVariableDeclaration(proxy, VAR, scope_, pos); 2114 factory()->NewVariableDeclaration(proxy, VAR, scope(), pos);
2120 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2115 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2121 NativeFunctionLiteral* lit = 2116 NativeFunctionLiteral* lit =
2122 factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition); 2117 factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition);
2123 return factory()->NewExpressionStatement( 2118 return factory()->NewExpressionStatement(
2124 factory()->NewAssignment(Token::INIT, proxy, lit, kNoSourcePosition), 2119 factory()->NewAssignment(Token::INIT, proxy, lit, kNoSourcePosition),
2125 pos); 2120 pos);
2126 } 2121 }
2127 2122
2128 Statement* Parser::ParseHoistableDeclaration( 2123 Statement* Parser::ParseHoistableDeclaration(
2129 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { 2124 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 FunctionLiteral* fun = ParseFunctionLiteral( 2190 FunctionLiteral* fun = ParseFunctionLiteral(
2196 name, scanner()->location(), name_validity, 2191 name, scanner()->location(), name_validity,
2197 is_generator ? FunctionKind::kGeneratorFunction 2192 is_generator ? FunctionKind::kGeneratorFunction
2198 : is_async ? FunctionKind::kAsyncFunction 2193 : is_async ? FunctionKind::kAsyncFunction
2199 : FunctionKind::kNormalFunction, 2194 : FunctionKind::kNormalFunction,
2200 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); 2195 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK);
2201 2196
2202 // In ES6, a function behaves as a lexical binding, except in 2197 // In ES6, a function behaves as a lexical binding, except in
2203 // a script scope, or the initial scope of eval or another function. 2198 // a script scope, or the initial scope of eval or another function.
2204 VariableMode mode = 2199 VariableMode mode =
2205 (!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET 2200 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET
2206 : VAR; 2201 : VAR;
2207 VariableProxy* proxy = NewUnresolved(variable_name, mode); 2202 VariableProxy* proxy = NewUnresolved(variable_name, mode);
2208 Declaration* declaration = 2203 Declaration* declaration =
2209 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); 2204 factory()->NewFunctionDeclaration(proxy, mode, fun, scope(), pos);
2210 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2205 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2211 if (names) names->Add(variable_name, zone()); 2206 if (names) names->Add(variable_name, zone());
2212 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); 2207 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition);
2213 // Async functions don't undergo sloppy mode block scoped hoisting, and don't 2208 // Async functions don't undergo sloppy mode block scoped hoisting, and don't
2214 // allow duplicates in a block. Both are represented by the 2209 // allow duplicates in a block. Both are represented by the
2215 // sloppy_block_function_map. Don't add them to the map for async functions. 2210 // sloppy_block_function_map. Don't add them to the map for async functions.
2216 // Generators are also supposed to be prohibited; currently doing this behind 2211 // Generators are also supposed to be prohibited; currently doing this behind
2217 // a flag and UseCounting violations to assess web compatibility. 2212 // a flag and UseCounting violations to assess web compatibility.
2218 if (is_sloppy(language_mode()) && !scope_->is_declaration_scope() && 2213 if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() &&
2219 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) { 2214 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) {
2220 SloppyBlockFunctionStatement* delegate = 2215 SloppyBlockFunctionStatement* delegate =
2221 factory()->NewSloppyBlockFunctionStatement(empty, scope_); 2216 factory()->NewSloppyBlockFunctionStatement(empty, scope());
2222 scope_->DeclarationScope()->sloppy_block_function_map()->Declare( 2217 scope()->DeclarationScope()->sloppy_block_function_map()->Declare(
2223 variable_name, delegate); 2218 variable_name, delegate);
2224 return delegate; 2219 return delegate;
2225 } 2220 }
2226 return empty; 2221 return empty;
2227 } 2222 }
2228 2223
2229 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, 2224 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
2230 bool default_export, bool* ok) { 2225 bool default_export, bool* ok) {
2231 // ClassDeclaration :: 2226 // ClassDeclaration ::
2232 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}' 2227 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
(...skipping 25 matching lines...) Expand all
2258 } else { 2253 } else {
2259 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 2254 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
2260 variable_name = name; 2255 variable_name = name;
2261 } 2256 }
2262 2257
2263 ClassLiteral* value = ParseClassLiteral(nullptr, name, scanner()->location(), 2258 ClassLiteral* value = ParseClassLiteral(nullptr, name, scanner()->location(),
2264 is_strict_reserved, pos, CHECK_OK); 2259 is_strict_reserved, pos, CHECK_OK);
2265 2260
2266 VariableProxy* proxy = NewUnresolved(variable_name, LET); 2261 VariableProxy* proxy = NewUnresolved(variable_name, LET);
2267 Declaration* declaration = 2262 Declaration* declaration =
2268 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); 2263 factory()->NewVariableDeclaration(proxy, LET, scope(), pos);
2269 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2264 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2270 proxy->var()->set_initializer_position(position()); 2265 proxy->var()->set_initializer_position(position());
2271 Assignment* assignment = 2266 Assignment* assignment =
2272 factory()->NewAssignment(Token::INIT, proxy, value, pos); 2267 factory()->NewAssignment(Token::INIT, proxy, value, pos);
2273 Statement* assignment_statement = 2268 Statement* assignment_statement =
2274 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 2269 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
2275 if (names) names->Add(variable_name, zone()); 2270 if (names) names->Add(variable_name, zone());
2276 return assignment_statement; 2271 return assignment_statement;
2277 } 2272 }
2278 2273
2279 2274
2280 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, 2275 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels,
2281 bool finalize_block_scope, bool* ok) { 2276 bool finalize_block_scope, bool* ok) {
2282 // The harmony mode uses block elements instead of statements. 2277 // The harmony mode uses block elements instead of statements.
2283 // 2278 //
2284 // Block :: 2279 // Block ::
2285 // '{' StatementList '}' 2280 // '{' StatementList '}'
2286 2281
2287 // Construct block expecting 16 statements. 2282 // Construct block expecting 16 statements.
2288 Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); 2283 Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition);
2289 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 2284 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
2290 2285
2291 // Parse the statements and collect escaping labels. 2286 // Parse the statements and collect escaping labels.
2292 Expect(Token::LBRACE, CHECK_OK); 2287 Expect(Token::LBRACE, CHECK_OK);
2293 block_scope->set_start_position(scanner()->location().beg_pos); 2288 block_scope->set_start_position(scanner()->location().beg_pos);
2294 { BlockState block_state(&scope_, block_scope); 2289 {
2290 BlockState block_state(&scope_state_, block_scope);
2295 Target target(&this->target_stack_, body); 2291 Target target(&this->target_stack_, body);
2296 2292
2297 while (peek() != Token::RBRACE) { 2293 while (peek() != Token::RBRACE) {
2298 Statement* stat = ParseStatementListItem(CHECK_OK); 2294 Statement* stat = ParseStatementListItem(CHECK_OK);
2299 if (stat && !stat->IsEmpty()) { 2295 if (stat && !stat->IsEmpty()) {
2300 body->statements()->Add(stat, zone()); 2296 body->statements()->Add(stat, zone());
2301 } 2297 }
2302 } 2298 }
2303 } 2299 }
2304 Expect(Token::RBRACE, CHECK_OK); 2300 Expect(Token::RBRACE, CHECK_OK);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 DCHECK(var_context != kStatement); 2386 DCHECK(var_context != kStatement);
2391 parsing_result->descriptor.mode = CONST; 2387 parsing_result->descriptor.mode = CONST;
2392 } else if (peek() == Token::LET) { 2388 } else if (peek() == Token::LET) {
2393 Consume(Token::LET); 2389 Consume(Token::LET);
2394 DCHECK(var_context != kStatement); 2390 DCHECK(var_context != kStatement);
2395 parsing_result->descriptor.mode = LET; 2391 parsing_result->descriptor.mode = LET;
2396 } else { 2392 } else {
2397 UNREACHABLE(); // by current callers 2393 UNREACHABLE(); // by current callers
2398 } 2394 }
2399 2395
2400 parsing_result->descriptor.scope = scope_; 2396 parsing_result->descriptor.scope = scope();
2401 parsing_result->descriptor.hoist_scope = nullptr; 2397 parsing_result->descriptor.hoist_scope = nullptr;
2402 2398
2403 2399
2404 bool first_declaration = true; 2400 bool first_declaration = true;
2405 int bindings_start = peek_position(); 2401 int bindings_start = peek_position();
2406 do { 2402 do {
2407 FuncNameInferrer::State fni_state(fni_); 2403 FuncNameInferrer::State fni_state(fni_);
2408 2404
2409 // Parse name. 2405 // Parse name.
2410 if (!first_declaration) Consume(Token::COMMA); 2406 if (!first_declaration) Consume(Token::COMMA);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2578 *ok = false; 2574 *ok = false;
2579 return NULL; 2575 return NULL;
2580 } 2576 }
2581 if (labels == NULL) { 2577 if (labels == NULL) {
2582 labels = new(zone()) ZoneList<const AstRawString*>(4, zone()); 2578 labels = new(zone()) ZoneList<const AstRawString*>(4, zone());
2583 } 2579 }
2584 labels->Add(label, zone()); 2580 labels->Add(label, zone());
2585 // Remove the "ghost" variable that turned out to be a label 2581 // Remove the "ghost" variable that turned out to be a label
2586 // from the top scope. This way, we don't try to resolve it 2582 // from the top scope. This way, we don't try to resolve it
2587 // during the scope processing. 2583 // during the scope processing.
2588 scope_->RemoveUnresolved(var); 2584 scope()->RemoveUnresolved(var);
2589 Expect(Token::COLON, CHECK_OK); 2585 Expect(Token::COLON, CHECK_OK);
2590 // ES#sec-labelled-function-declarations Labelled Function Declarations 2586 // ES#sec-labelled-function-declarations Labelled Function Declarations
2591 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { 2587 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) {
2592 if (allow_function == kAllowLabelledFunctionStatement) { 2588 if (allow_function == kAllowLabelledFunctionStatement) {
2593 return ParseFunctionDeclaration(ok); 2589 return ParseFunctionDeclaration(ok);
2594 } else { 2590 } else {
2595 return ParseScopedStatement(labels, true, ok); 2591 return ParseScopedStatement(labels, true, ok);
2596 } 2592 }
2597 } 2593 }
2598 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); 2594 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2717 function_state_->set_return_location(loc); 2713 function_state_->set_return_location(loc);
2718 2714
2719 Token::Value tok = peek(); 2715 Token::Value tok = peek();
2720 Statement* result; 2716 Statement* result;
2721 Expression* return_value; 2717 Expression* return_value;
2722 if (scanner()->HasAnyLineTerminatorBeforeNext() || 2718 if (scanner()->HasAnyLineTerminatorBeforeNext() ||
2723 tok == Token::SEMICOLON || 2719 tok == Token::SEMICOLON ||
2724 tok == Token::RBRACE || 2720 tok == Token::RBRACE ||
2725 tok == Token::EOS) { 2721 tok == Token::EOS) {
2726 if (IsSubclassConstructor(function_state_->kind())) { 2722 if (IsSubclassConstructor(function_state_->kind())) {
2727 return_value = ThisExpression(scope_, factory(), loc.beg_pos); 2723 return_value = ThisExpression(scope(), factory(), loc.beg_pos);
2728 } else { 2724 } else {
2729 return_value = GetLiteralUndefined(position()); 2725 return_value = GetLiteralUndefined(position());
2730 } 2726 }
2731 } else { 2727 } else {
2732 int pos = peek_position(); 2728 int pos = peek_position();
2733 2729
2734 if (IsSubclassConstructor(function_state_->kind())) { 2730 if (IsSubclassConstructor(function_state_->kind())) {
2735 // Because of the return code rewriting that happens in case of a subclass 2731 // Because of the return code rewriting that happens in case of a subclass
2736 // constructor we don't want to accept tail calls, therefore we don't set 2732 // constructor we don't want to accept tail calls, therefore we don't set
2737 // ReturnExprScope to kInsideValidReturnStatement here. 2733 // ReturnExprScope to kInsideValidReturnStatement here.
2738 return_value = ParseExpression(true, CHECK_OK); 2734 return_value = ParseExpression(true, CHECK_OK);
2739 2735
2740 // For subclass constructors we need to return this in case of undefined 2736 // For subclass constructors we need to return this in case of undefined
2741 // return a Smi (transformed into an exception in the ConstructStub) 2737 // return a Smi (transformed into an exception in the ConstructStub)
2742 // for a non object. 2738 // for a non object.
2743 // 2739 //
2744 // return expr; 2740 // return expr;
2745 // 2741 //
2746 // Is rewritten as: 2742 // Is rewritten as:
2747 // 2743 //
2748 // return (temp = expr) === undefined ? this : 2744 // return (temp = expr) === undefined ? this :
2749 // %_IsJSReceiver(temp) ? temp : 1; 2745 // %_IsJSReceiver(temp) ? temp : 1;
2750 2746
2751 // temp = expr 2747 // temp = expr
2752 Variable* temp = scope_->NewTemporary( 2748 Variable* temp =
2753 ast_value_factory()->empty_string()); 2749 scope()->NewTemporary(ast_value_factory()->empty_string());
2754 Assignment* assign = factory()->NewAssignment( 2750 Assignment* assign = factory()->NewAssignment(
2755 Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos); 2751 Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos);
2756 2752
2757 // %_IsJSReceiver(temp) 2753 // %_IsJSReceiver(temp)
2758 ZoneList<Expression*>* is_spec_object_args = 2754 ZoneList<Expression*>* is_spec_object_args =
2759 new (zone()) ZoneList<Expression*>(1, zone()); 2755 new (zone()) ZoneList<Expression*>(1, zone());
2760 is_spec_object_args->Add(factory()->NewVariableProxy(temp), zone()); 2756 is_spec_object_args->Add(factory()->NewVariableProxy(temp), zone());
2761 Expression* is_spec_object_call = factory()->NewCallRuntime( 2757 Expression* is_spec_object_call = factory()->NewCallRuntime(
2762 Runtime::kInlineIsJSReceiver, is_spec_object_args, pos); 2758 Runtime::kInlineIsJSReceiver, is_spec_object_args, pos);
2763 2759
2764 // %_IsJSReceiver(temp) ? temp : 1; 2760 // %_IsJSReceiver(temp) ? temp : 1;
2765 Expression* is_object_conditional = factory()->NewConditional( 2761 Expression* is_object_conditional = factory()->NewConditional(
2766 is_spec_object_call, factory()->NewVariableProxy(temp), 2762 is_spec_object_call, factory()->NewVariableProxy(temp),
2767 factory()->NewSmiLiteral(1, pos), pos); 2763 factory()->NewSmiLiteral(1, pos), pos);
2768 2764
2769 // temp === undefined 2765 // temp === undefined
2770 Expression* is_undefined = factory()->NewCompareOperation( 2766 Expression* is_undefined = factory()->NewCompareOperation(
2771 Token::EQ_STRICT, assign, 2767 Token::EQ_STRICT, assign,
2772 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); 2768 factory()->NewUndefinedLiteral(kNoSourcePosition), pos);
2773 2769
2774 // is_undefined ? this : is_object_conditional 2770 // is_undefined ? this : is_object_conditional
2775 return_value = factory()->NewConditional( 2771 return_value = factory()->NewConditional(
2776 is_undefined, ThisExpression(scope_, factory(), pos), 2772 is_undefined, ThisExpression(scope(), factory(), pos),
2777 is_object_conditional, pos); 2773 is_object_conditional, pos);
2778 } else { 2774 } else {
2779 ReturnExprScope maybe_allow_tail_calls( 2775 ReturnExprScope maybe_allow_tail_calls(
2780 function_state_, ReturnExprContext::kInsideValidReturnStatement); 2776 function_state_, ReturnExprContext::kInsideValidReturnStatement);
2781 return_value = ParseExpression(true, CHECK_OK); 2777 return_value = ParseExpression(true, CHECK_OK);
2782 2778
2783 if (allow_tailcalls() && !is_sloppy(language_mode())) { 2779 if (allow_tailcalls() && !is_sloppy(language_mode())) {
2784 // ES6 14.6.1 Static Semantics: IsInTailPosition 2780 // ES6 14.6.1 Static Semantics: IsInTailPosition
2785 function_state_->AddImplicitTailCallExpression(return_value); 2781 function_state_->AddImplicitTailCallExpression(return_value);
2786 } 2782 }
2787 } 2783 }
2788 } 2784 }
2789 ExpectSemicolon(CHECK_OK); 2785 ExpectSemicolon(CHECK_OK);
2790 2786
2791 if (is_generator()) { 2787 if (is_generator()) {
2792 return_value = BuildIteratorResult(return_value, true); 2788 return_value = BuildIteratorResult(return_value, true);
2793 } else if (is_async_function()) { 2789 } else if (is_async_function()) {
2794 return_value = BuildPromiseResolve(return_value, return_value->position()); 2790 return_value = BuildPromiseResolve(return_value, return_value->position());
2795 } 2791 }
2796 2792
2797 result = factory()->NewReturnStatement(return_value, loc.beg_pos); 2793 result = factory()->NewReturnStatement(return_value, loc.beg_pos);
2798 2794
2799 Scope* decl_scope = scope_->DeclarationScope(); 2795 Scope* decl_scope = scope()->DeclarationScope();
2800 if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) { 2796 if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) {
2801 ReportMessageAt(loc, MessageTemplate::kIllegalReturn); 2797 ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
2802 *ok = false; 2798 *ok = false;
2803 return NULL; 2799 return NULL;
2804 } 2800 }
2805 return result; 2801 return result;
2806 } 2802 }
2807 2803
2808 2804
2809 Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels, 2805 Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels,
2810 bool* ok) { 2806 bool* ok) {
2811 // WithStatement :: 2807 // WithStatement ::
2812 // 'with' '(' Expression ')' Statement 2808 // 'with' '(' Expression ')' Statement
2813 2809
2814 Expect(Token::WITH, CHECK_OK); 2810 Expect(Token::WITH, CHECK_OK);
2815 int pos = position(); 2811 int pos = position();
2816 2812
2817 if (is_strict(language_mode())) { 2813 if (is_strict(language_mode())) {
2818 ReportMessage(MessageTemplate::kStrictWith); 2814 ReportMessage(MessageTemplate::kStrictWith);
2819 *ok = false; 2815 *ok = false;
2820 return NULL; 2816 return NULL;
2821 } 2817 }
2822 2818
2823 Expect(Token::LPAREN, CHECK_OK); 2819 Expect(Token::LPAREN, CHECK_OK);
2824 Expression* expr = ParseExpression(true, CHECK_OK); 2820 Expression* expr = ParseExpression(true, CHECK_OK);
2825 Expect(Token::RPAREN, CHECK_OK); 2821 Expect(Token::RPAREN, CHECK_OK);
2826 2822
2827 Scope* with_scope = NewScope(scope_, WITH_SCOPE); 2823 Scope* with_scope = NewScope(scope(), WITH_SCOPE);
2828 Statement* body; 2824 Statement* body;
2829 { BlockState block_state(&scope_, with_scope); 2825 {
2826 BlockState block_state(&scope_state_, with_scope);
2830 with_scope->set_start_position(scanner()->peek_location().beg_pos); 2827 with_scope->set_start_position(scanner()->peek_location().beg_pos);
2831 body = ParseScopedStatement(labels, true, CHECK_OK); 2828 body = ParseScopedStatement(labels, true, CHECK_OK);
2832 with_scope->set_end_position(scanner()->location().end_pos); 2829 with_scope->set_end_position(scanner()->location().end_pos);
2833 } 2830 }
2834 return factory()->NewWithStatement(with_scope, expr, body, pos); 2831 return factory()->NewWithStatement(with_scope, expr, body, pos);
2835 } 2832 }
2836 2833
2837 2834
2838 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { 2835 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
2839 // CaseClause :: 2836 // CaseClause ::
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 2881
2885 Block* switch_block = factory()->NewBlock(NULL, 2, false, kNoSourcePosition); 2882 Block* switch_block = factory()->NewBlock(NULL, 2, false, kNoSourcePosition);
2886 int switch_pos = peek_position(); 2883 int switch_pos = peek_position();
2887 2884
2888 Expect(Token::SWITCH, CHECK_OK); 2885 Expect(Token::SWITCH, CHECK_OK);
2889 Expect(Token::LPAREN, CHECK_OK); 2886 Expect(Token::LPAREN, CHECK_OK);
2890 Expression* tag = ParseExpression(true, CHECK_OK); 2887 Expression* tag = ParseExpression(true, CHECK_OK);
2891 Expect(Token::RPAREN, CHECK_OK); 2888 Expect(Token::RPAREN, CHECK_OK);
2892 2889
2893 Variable* tag_variable = 2890 Variable* tag_variable =
2894 scope_->NewTemporary(ast_value_factory()->dot_switch_tag_string()); 2891 scope()->NewTemporary(ast_value_factory()->dot_switch_tag_string());
2895 Assignment* tag_assign = factory()->NewAssignment( 2892 Assignment* tag_assign = factory()->NewAssignment(
2896 Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag, 2893 Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag,
2897 tag->position()); 2894 tag->position());
2898 Statement* tag_statement = 2895 Statement* tag_statement =
2899 factory()->NewExpressionStatement(tag_assign, kNoSourcePosition); 2896 factory()->NewExpressionStatement(tag_assign, kNoSourcePosition);
2900 switch_block->statements()->Add(tag_statement, zone()); 2897 switch_block->statements()->Add(tag_statement, zone());
2901 2898
2902 // make statement: undefined; 2899 // make statement: undefined;
2903 // This is needed so the tag isn't returned as the value, in case the switch 2900 // This is needed so the tag isn't returned as the value, in case the switch
2904 // statements don't have a value. 2901 // statements don't have a value.
2905 switch_block->statements()->Add( 2902 switch_block->statements()->Add(
2906 factory()->NewExpressionStatement( 2903 factory()->NewExpressionStatement(
2907 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), 2904 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition),
2908 zone()); 2905 zone());
2909 2906
2910 Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); 2907 Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
2911 Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); 2908 Scope* cases_scope = NewScope(scope(), BLOCK_SCOPE);
2912 cases_scope->SetNonlinear(); 2909 cases_scope->SetNonlinear();
2913 2910
2914 SwitchStatement* switch_statement = 2911 SwitchStatement* switch_statement =
2915 factory()->NewSwitchStatement(labels, switch_pos); 2912 factory()->NewSwitchStatement(labels, switch_pos);
2916 2913
2917 cases_scope->set_start_position(scanner()->location().beg_pos); 2914 cases_scope->set_start_position(scanner()->location().beg_pos);
2918 { 2915 {
2919 BlockState cases_block_state(&scope_, cases_scope); 2916 BlockState cases_block_state(&scope_state_, cases_scope);
2920 Target target(&this->target_stack_, switch_statement); 2917 Target target(&this->target_stack_, switch_statement);
2921 2918
2922 Expression* tag_read = factory()->NewVariableProxy(tag_variable); 2919 Expression* tag_read = factory()->NewVariableProxy(tag_variable);
2923 2920
2924 bool default_seen = false; 2921 bool default_seen = false;
2925 ZoneList<CaseClause*>* cases = 2922 ZoneList<CaseClause*>* cases =
2926 new (zone()) ZoneList<CaseClause*>(4, zone()); 2923 new (zone()) ZoneList<CaseClause*>(4, zone());
2927 Expect(Token::LBRACE, CHECK_OK); 2924 Expect(Token::LBRACE, CHECK_OK);
2928 while (peek() != Token::RBRACE) { 2925 while (peek() != Token::RBRACE) {
2929 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK); 2926 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2993 } 2990 }
2994 2991
2995 Scope* catch_scope = NULL; 2992 Scope* catch_scope = NULL;
2996 Variable* catch_variable = NULL; 2993 Variable* catch_variable = NULL;
2997 Block* catch_block = NULL; 2994 Block* catch_block = NULL;
2998 TailCallExpressionList tail_call_expressions_in_catch_block(zone()); 2995 TailCallExpressionList tail_call_expressions_in_catch_block(zone());
2999 if (tok == Token::CATCH) { 2996 if (tok == Token::CATCH) {
3000 Consume(Token::CATCH); 2997 Consume(Token::CATCH);
3001 2998
3002 Expect(Token::LPAREN, CHECK_OK); 2999 Expect(Token::LPAREN, CHECK_OK);
3003 catch_scope = NewScope(scope_, CATCH_SCOPE); 3000 catch_scope = NewScope(scope(), CATCH_SCOPE);
3004 catch_scope->set_start_position(scanner()->location().beg_pos); 3001 catch_scope->set_start_position(scanner()->location().beg_pos);
3005 3002
3006 { 3003 {
3007 CollectExpressionsInTailPositionToListScope 3004 CollectExpressionsInTailPositionToListScope
3008 collect_tail_call_expressions_scope( 3005 collect_tail_call_expressions_scope(
3009 function_state_, &tail_call_expressions_in_catch_block); 3006 function_state_, &tail_call_expressions_in_catch_block);
3010 BlockState block_state(&scope_, catch_scope); 3007 BlockState block_state(&scope_state_, catch_scope);
3011 3008
3012 catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); 3009 catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
3013 3010
3014 // Create a block scope to hold any lexical declarations created 3011 // Create a block scope to hold any lexical declarations created
3015 // as part of destructuring the catch parameter. 3012 // as part of destructuring the catch parameter.
3016 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 3013 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
3017 block_scope->set_start_position(scanner()->location().beg_pos); 3014 block_scope->set_start_position(scanner()->location().beg_pos);
3018 { 3015 {
3019 BlockState block_state(&scope_, block_scope); 3016 BlockState block_state(&scope_state_, block_scope);
3020 Target target(&this->target_stack_, catch_block); 3017 Target target(&this->target_stack_, catch_block);
3021 3018
3022 const AstRawString* name = ast_value_factory()->dot_catch_string(); 3019 const AstRawString* name = ast_value_factory()->dot_catch_string();
3023 Expression* pattern = nullptr; 3020 Expression* pattern = nullptr;
3024 if (peek_any_identifier()) { 3021 if (peek_any_identifier()) {
3025 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); 3022 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
3026 } else { 3023 } else {
3027 ExpressionClassifier pattern_classifier(this); 3024 ExpressionClassifier pattern_classifier(this);
3028 pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); 3025 pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
3029 ValidateBindingPattern(&pattern_classifier, CHECK_OK); 3026 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
3030 } 3027 }
3031 catch_variable = catch_scope->DeclareLocal( 3028 catch_variable = catch_scope->DeclareLocal(
3032 name, VAR, kCreatedInitialized, Variable::NORMAL); 3029 name, VAR, kCreatedInitialized, Variable::NORMAL);
3033 3030
3034 Expect(Token::RPAREN, CHECK_OK); 3031 Expect(Token::RPAREN, CHECK_OK);
3035 3032
3036 ZoneList<const AstRawString*> bound_names(1, zone()); 3033 ZoneList<const AstRawString*> bound_names(1, zone());
3037 if (pattern != nullptr) { 3034 if (pattern != nullptr) {
3038 DeclarationDescriptor descriptor; 3035 DeclarationDescriptor descriptor;
3039 descriptor.declaration_kind = DeclarationDescriptor::NORMAL; 3036 descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
3040 descriptor.parser = this; 3037 descriptor.parser = this;
3041 descriptor.scope = scope_; 3038 descriptor.scope = scope();
3042 descriptor.hoist_scope = nullptr; 3039 descriptor.hoist_scope = nullptr;
3043 descriptor.mode = LET; 3040 descriptor.mode = LET;
3044 descriptor.declaration_pos = pattern->position(); 3041 descriptor.declaration_pos = pattern->position();
3045 descriptor.initialization_pos = pattern->position(); 3042 descriptor.initialization_pos = pattern->position();
3046 3043
3047 // Initializer position for variables declared by the pattern. 3044 // Initializer position for variables declared by the pattern.
3048 const int initializer_position = position(); 3045 const int initializer_position = position();
3049 3046
3050 DeclarationParsingResult::Declaration decl( 3047 DeclarationParsingResult::Declaration decl(
3051 pattern, initializer_position, 3048 pattern, initializer_position,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
3233 Statement* body, 3230 Statement* body,
3234 int each_keyword_pos) { 3231 int each_keyword_pos) {
3235 ForOfStatement* for_of = stmt->AsForOfStatement(); 3232 ForOfStatement* for_of = stmt->AsForOfStatement();
3236 if (for_of != NULL) { 3233 if (for_of != NULL) {
3237 const bool finalize = true; 3234 const bool finalize = true;
3238 return InitializeForOfStatement(for_of, each, subject, body, finalize, 3235 return InitializeForOfStatement(for_of, each, subject, body, finalize,
3239 each_keyword_pos); 3236 each_keyword_pos);
3240 } else { 3237 } else {
3241 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { 3238 if (each->IsArrayLiteral() || each->IsObjectLiteral()) {
3242 Variable* temp = 3239 Variable* temp =
3243 scope_->NewTemporary(ast_value_factory()->empty_string()); 3240 scope()->NewTemporary(ast_value_factory()->empty_string());
3244 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 3241 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
3245 Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment( 3242 Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment(
3246 this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy, 3243 this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy,
3247 kNoSourcePosition), 3244 kNoSourcePosition),
3248 scope_); 3245 scope());
3249 auto block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition); 3246 auto block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition);
3250 block->statements()->Add( 3247 block->statements()->Add(
3251 factory()->NewExpressionStatement(assign_each, kNoSourcePosition), 3248 factory()->NewExpressionStatement(assign_each, kNoSourcePosition),
3252 zone()); 3249 zone());
3253 block->statements()->Add(body, zone()); 3250 block->statements()->Add(body, zone());
3254 body = block; 3251 body = block;
3255 each = factory()->NewVariableProxy(temp); 3252 each = factory()->NewVariableProxy(temp);
3256 } 3253 }
3257 stmt->AsForInStatement()->Initialize(each, subject, body); 3254 stmt->AsForInStatement()->Initialize(each, subject, body);
3258 } 3255 }
3259 return stmt; 3256 return stmt;
3260 } 3257 }
3261 3258
3262 Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of, 3259 Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
3263 Expression* each, 3260 Expression* each,
3264 Expression* iterable, 3261 Expression* iterable,
3265 Statement* body, bool finalize, 3262 Statement* body, bool finalize,
3266 int next_result_pos) { 3263 int next_result_pos) {
3267 // Create the auxiliary expressions needed for iterating over the iterable, 3264 // Create the auxiliary expressions needed for iterating over the iterable,
3268 // and initialize the given ForOfStatement with them. 3265 // and initialize the given ForOfStatement with them.
3269 // If finalize is true, also instrument the loop with code that performs the 3266 // If finalize is true, also instrument the loop with code that performs the
3270 // proper ES6 iterator finalization. In that case, the result is not 3267 // proper ES6 iterator finalization. In that case, the result is not
3271 // immediately a ForOfStatement. 3268 // immediately a ForOfStatement.
3272 3269
3273 const int nopos = kNoSourcePosition; 3270 const int nopos = kNoSourcePosition;
3274 auto avfactory = ast_value_factory(); 3271 auto avfactory = ast_value_factory();
3275 3272
3276 Variable* iterator = 3273 Variable* iterator =
3277 scope_->NewTemporary(ast_value_factory()->dot_iterator_string()); 3274 scope()->NewTemporary(ast_value_factory()->dot_iterator_string());
3278 Variable* result = 3275 Variable* result =
3279 scope_->NewTemporary(ast_value_factory()->dot_result_string()); 3276 scope()->NewTemporary(ast_value_factory()->dot_result_string());
3280 Variable* completion = scope_->NewTemporary(avfactory->empty_string()); 3277 Variable* completion = scope()->NewTemporary(avfactory->empty_string());
3281 3278
3282 // iterator = iterable[Symbol.iterator]() 3279 // iterator = iterable[Symbol.iterator]()
3283 Expression* assign_iterator; 3280 Expression* assign_iterator;
3284 { 3281 {
3285 assign_iterator = factory()->NewAssignment( 3282 assign_iterator = factory()->NewAssignment(
3286 Token::ASSIGN, factory()->NewVariableProxy(iterator), 3283 Token::ASSIGN, factory()->NewVariableProxy(iterator),
3287 GetIterator(iterable, factory(), iterable->position()), 3284 GetIterator(iterable, factory(), iterable->position()),
3288 iterable->position()); 3285 iterable->position());
3289 } 3286 }
3290 3287
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3326 3323
3327 Block* block = factory()->NewBlock(nullptr, 1, true, nopos); 3324 Block* block = factory()->NewBlock(nullptr, 1, true, nopos);
3328 block->statements()->Add( 3325 block->statements()->Add(
3329 factory()->NewExpressionStatement(assignment, nopos), zone()); 3326 factory()->NewExpressionStatement(assignment, nopos), zone());
3330 set_completion_abrupt = block; 3327 set_completion_abrupt = block;
3331 } 3328 }
3332 3329
3333 // do { let tmp = #result_value; #set_completion_abrupt; tmp } 3330 // do { let tmp = #result_value; #set_completion_abrupt; tmp }
3334 // Expression* result_value (gets overwritten) 3331 // Expression* result_value (gets overwritten)
3335 if (finalize) { 3332 if (finalize) {
3336 Variable* var_tmp = scope_->NewTemporary(avfactory->empty_string()); 3333 Variable* var_tmp = scope()->NewTemporary(avfactory->empty_string());
3337 Expression* tmp = factory()->NewVariableProxy(var_tmp); 3334 Expression* tmp = factory()->NewVariableProxy(var_tmp);
3338 Expression* assignment = 3335 Expression* assignment =
3339 factory()->NewAssignment(Token::ASSIGN, tmp, result_value, nopos); 3336 factory()->NewAssignment(Token::ASSIGN, tmp, result_value, nopos);
3340 3337
3341 Block* block = factory()->NewBlock(nullptr, 2, false, nopos); 3338 Block* block = factory()->NewBlock(nullptr, 2, false, nopos);
3342 block->statements()->Add( 3339 block->statements()->Add(
3343 factory()->NewExpressionStatement(assignment, nopos), zone()); 3340 factory()->NewExpressionStatement(assignment, nopos), zone());
3344 block->statements()->Add(set_completion_abrupt, zone()); 3341 block->statements()->Add(set_completion_abrupt, zone());
3345 3342
3346 result_value = factory()->NewDoExpression(block, var_tmp, nopos); 3343 result_value = factory()->NewDoExpression(block, var_tmp, nopos);
3347 } 3344 }
3348 3345
3349 // each = #result_value; 3346 // each = #result_value;
3350 Expression* assign_each; 3347 Expression* assign_each;
3351 { 3348 {
3352 assign_each = 3349 assign_each =
3353 factory()->NewAssignment(Token::ASSIGN, each, result_value, nopos); 3350 factory()->NewAssignment(Token::ASSIGN, each, result_value, nopos);
3354 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { 3351 if (each->IsArrayLiteral() || each->IsObjectLiteral()) {
3355 assign_each = PatternRewriter::RewriteDestructuringAssignment( 3352 assign_each = PatternRewriter::RewriteDestructuringAssignment(
3356 this, assign_each->AsAssignment(), scope_); 3353 this, assign_each->AsAssignment(), scope());
3357 } 3354 }
3358 } 3355 }
3359 3356
3360 // {{completion = kNormalCompletion;}} 3357 // {{completion = kNormalCompletion;}}
3361 Statement* set_completion_normal; 3358 Statement* set_completion_normal;
3362 if (finalize) { 3359 if (finalize) {
3363 Expression* proxy = factory()->NewVariableProxy(completion); 3360 Expression* proxy = factory()->NewVariableProxy(completion);
3364 Expression* assignment = factory()->NewAssignment( 3361 Expression* assignment = factory()->NewAssignment(
3365 Token::ASSIGN, proxy, 3362 Token::ASSIGN, proxy,
3366 factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos); 3363 factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
3436 3433
3437 // Add statement: let/const x = i. 3434 // Add statement: let/const x = i.
3438 outer_block->statements()->Add(init, zone()); 3435 outer_block->statements()->Add(init, zone());
3439 3436
3440 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); 3437 const AstRawString* temp_name = ast_value_factory()->dot_for_string();
3441 3438
3442 // For each lexical variable x: 3439 // For each lexical variable x:
3443 // make statement: temp_x = x. 3440 // make statement: temp_x = x.
3444 for (int i = 0; i < names->length(); i++) { 3441 for (int i = 0; i < names->length(); i++) {
3445 VariableProxy* proxy = NewUnresolved(names->at(i), LET); 3442 VariableProxy* proxy = NewUnresolved(names->at(i), LET);
3446 Variable* temp = scope_->NewTemporary(temp_name); 3443 Variable* temp = scope()->NewTemporary(temp_name);
3447 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 3444 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
3448 Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy, 3445 Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy,
3449 proxy, kNoSourcePosition); 3446 proxy, kNoSourcePosition);
3450 Statement* assignment_statement = 3447 Statement* assignment_statement =
3451 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 3448 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
3452 outer_block->statements()->Add(assignment_statement, zone()); 3449 outer_block->statements()->Add(assignment_statement, zone());
3453 temps.Add(temp, zone()); 3450 temps.Add(temp, zone());
3454 } 3451 }
3455 3452
3456 Variable* first = NULL; 3453 Variable* first = NULL;
3457 // Make statement: first = 1. 3454 // Make statement: first = 1.
3458 if (next) { 3455 if (next) {
3459 first = scope_->NewTemporary(temp_name); 3456 first = scope()->NewTemporary(temp_name);
3460 VariableProxy* first_proxy = factory()->NewVariableProxy(first); 3457 VariableProxy* first_proxy = factory()->NewVariableProxy(first);
3461 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); 3458 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition);
3462 Assignment* assignment = factory()->NewAssignment( 3459 Assignment* assignment = factory()->NewAssignment(
3463 Token::ASSIGN, first_proxy, const1, kNoSourcePosition); 3460 Token::ASSIGN, first_proxy, const1, kNoSourcePosition);
3464 Statement* assignment_statement = 3461 Statement* assignment_statement =
3465 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 3462 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
3466 outer_block->statements()->Add(assignment_statement, zone()); 3463 outer_block->statements()->Add(assignment_statement, zone());
3467 } 3464 }
3468 3465
3469 // make statement: undefined; 3466 // make statement: undefined;
3470 outer_block->statements()->Add( 3467 outer_block->statements()->Add(
3471 factory()->NewExpressionStatement( 3468 factory()->NewExpressionStatement(
3472 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition), 3469 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition),
3473 zone()); 3470 zone());
3474 3471
3475 // Make statement: outer: for (;;) 3472 // Make statement: outer: for (;;)
3476 // Note that we don't actually create the label, or set this loop up as an 3473 // Note that we don't actually create the label, or set this loop up as an
3477 // explicit break target, instead handing it directly to those nodes that 3474 // explicit break target, instead handing it directly to those nodes that
3478 // need to know about it. This should be safe because we don't run any code 3475 // need to know about it. This should be safe because we don't run any code
3479 // in this function that looks up break targets. 3476 // in this function that looks up break targets.
3480 ForStatement* outer_loop = 3477 ForStatement* outer_loop =
3481 factory()->NewForStatement(NULL, kNoSourcePosition); 3478 factory()->NewForStatement(NULL, kNoSourcePosition);
3482 outer_block->statements()->Add(outer_loop, zone()); 3479 outer_block->statements()->Add(outer_loop, zone());
3483 outer_block->set_scope(scope_); 3480 outer_block->set_scope(scope());
3484 3481
3485 Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition); 3482 Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition);
3486 { 3483 {
3487 BlockState block_state(&scope_, inner_scope); 3484 BlockState block_state(&scope_state_, inner_scope);
3488 3485
3489 Block* ignore_completion_block = 3486 Block* ignore_completion_block =
3490 factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition); 3487 factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition);
3491 ZoneList<Variable*> inner_vars(names->length(), zone()); 3488 ZoneList<Variable*> inner_vars(names->length(), zone());
3492 // For each let variable x: 3489 // For each let variable x:
3493 // make statement: let/const x = temp_x. 3490 // make statement: let/const x = temp_x.
3494 for (int i = 0; i < names->length(); i++) { 3491 for (int i = 0; i < names->length(); i++) {
3495 VariableProxy* proxy = NewUnresolved(names->at(i), mode); 3492 VariableProxy* proxy = NewUnresolved(names->at(i), mode);
3496 Declaration* declaration = factory()->NewVariableDeclaration( 3493 Declaration* declaration = factory()->NewVariableDeclaration(
3497 proxy, mode, scope_, kNoSourcePosition); 3494 proxy, mode, scope(), kNoSourcePosition);
3498 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 3495 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
3499 inner_vars.Add(declaration->proxy()->var(), zone()); 3496 inner_vars.Add(declaration->proxy()->var(), zone());
3500 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); 3497 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i));
3501 Assignment* assignment = factory()->NewAssignment( 3498 Assignment* assignment = factory()->NewAssignment(
3502 Token::INIT, proxy, temp_proxy, kNoSourcePosition); 3499 Token::INIT, proxy, temp_proxy, kNoSourcePosition);
3503 Statement* assignment_statement = 3500 Statement* assignment_statement =
3504 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 3501 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
3505 DCHECK(init->position() != kNoSourcePosition); 3502 DCHECK(init->position() != kNoSourcePosition);
3506 proxy->var()->set_initializer_position(init->position()); 3503 proxy->var()->set_initializer_position(init->position());
3507 ignore_completion_block->statements()->Add(assignment_statement, zone()); 3504 ignore_completion_block->statements()->Add(assignment_statement, zone());
(...skipping 18 matching lines...) Expand all
3526 Assignment* assignment = factory()->NewAssignment( 3523 Assignment* assignment = factory()->NewAssignment(
3527 Token::ASSIGN, first_proxy, const0, kNoSourcePosition); 3524 Token::ASSIGN, first_proxy, const0, kNoSourcePosition);
3528 clear_first = 3525 clear_first =
3529 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 3526 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
3530 } 3527 }
3531 Statement* clear_first_or_next = factory()->NewIfStatement( 3528 Statement* clear_first_or_next = factory()->NewIfStatement(
3532 compare, clear_first, next, kNoSourcePosition); 3529 compare, clear_first, next, kNoSourcePosition);
3533 ignore_completion_block->statements()->Add(clear_first_or_next, zone()); 3530 ignore_completion_block->statements()->Add(clear_first_or_next, zone());
3534 } 3531 }
3535 3532
3536 Variable* flag = scope_->NewTemporary(temp_name); 3533 Variable* flag = scope()->NewTemporary(temp_name);
3537 // Make statement: flag = 1. 3534 // Make statement: flag = 1.
3538 { 3535 {
3539 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 3536 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
3540 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); 3537 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition);
3541 Assignment* assignment = factory()->NewAssignment( 3538 Assignment* assignment = factory()->NewAssignment(
3542 Token::ASSIGN, flag_proxy, const1, kNoSourcePosition); 3539 Token::ASSIGN, flag_proxy, const1, kNoSourcePosition);
3543 Statement* assignment_statement = 3540 Statement* assignment_statement =
3544 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 3541 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
3545 ignore_completion_block->statements()->Add(assignment_statement, zone()); 3542 ignore_completion_block->statements()->Add(assignment_statement, zone());
3546 } 3543 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
3633 bool legacy, bool* ok) { 3630 bool legacy, bool* ok) {
3634 if (is_strict(language_mode()) || peek() != Token::FUNCTION || 3631 if (is_strict(language_mode()) || peek() != Token::FUNCTION ||
3635 (legacy && allow_harmony_restrictive_declarations())) { 3632 (legacy && allow_harmony_restrictive_declarations())) {
3636 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok); 3633 return ParseSubStatement(labels, kDisallowLabelledFunctionStatement, ok);
3637 } else { 3634 } else {
3638 if (legacy) { 3635 if (legacy) {
3639 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration]; 3636 ++use_counts_[v8::Isolate::kLegacyFunctionDeclaration];
3640 } 3637 }
3641 // Make a block around the statement for a lexical binding 3638 // Make a block around the statement for a lexical binding
3642 // is introduced by a FunctionDeclaration. 3639 // is introduced by a FunctionDeclaration.
3643 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); 3640 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
3644 body_scope->set_start_position(scanner()->location().beg_pos); 3641 body_scope->set_start_position(scanner()->location().beg_pos);
3645 BlockState block_state(&scope_, body_scope); 3642 BlockState block_state(&scope_state_, body_scope);
3646 Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); 3643 Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
3647 Statement* body = ParseFunctionDeclaration(CHECK_OK); 3644 Statement* body = ParseFunctionDeclaration(CHECK_OK);
3648 block->statements()->Add(body, zone()); 3645 block->statements()->Add(body, zone());
3649 body_scope->set_end_position(scanner()->location().end_pos); 3646 body_scope->set_end_position(scanner()->location().end_pos);
3650 body_scope = body_scope->FinalizeBlockScope(); 3647 body_scope = body_scope->FinalizeBlockScope();
3651 block->set_scope(body_scope); 3648 block->set_scope(body_scope);
3652 return block; 3649 return block;
3653 } 3650 }
3654 } 3651 }
3655 3652
3656 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, 3653 Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
3657 bool* ok) { 3654 bool* ok) {
3658 int stmt_pos = peek_position(); 3655 int stmt_pos = peek_position();
3659 Statement* init = NULL; 3656 Statement* init = NULL;
3660 ZoneList<const AstRawString*> bound_names(1, zone()); 3657 ZoneList<const AstRawString*> bound_names(1, zone());
3661 bool bound_names_are_lexical = false; 3658 bool bound_names_are_lexical = false;
3662 3659
3663 // Create an in-between scope for let-bound iteration variables. 3660 // Create an in-between scope for let-bound iteration variables.
3664 Scope* for_scope = NewScope(scope_, BLOCK_SCOPE); 3661 Scope* for_scope = NewScope(scope(), BLOCK_SCOPE);
3665 3662
3666 BlockState block_state(&scope_, for_scope); 3663 BlockState block_state(&scope_state_, for_scope);
3667 Expect(Token::FOR, CHECK_OK); 3664 Expect(Token::FOR, CHECK_OK);
3668 Expect(Token::LPAREN, CHECK_OK); 3665 Expect(Token::LPAREN, CHECK_OK);
3669 for_scope->set_start_position(scanner()->location().beg_pos); 3666 for_scope->set_start_position(scanner()->location().beg_pos);
3670 for_scope->set_is_hidden(); 3667 for_scope->set_is_hidden();
3671 DeclarationParsingResult parsing_result; 3668 DeclarationParsingResult parsing_result;
3672 if (peek() != Token::SEMICOLON) { 3669 if (peek() != Token::SEMICOLON) {
3673 if (peek() == Token::VAR || peek() == Token::CONST || 3670 if (peek() == Token::VAR || peek() == Token::CONST ||
3674 (peek() == Token::LET && IsNextLetKeyword())) { 3671 (peek() == Token::LET && IsNextLetKeyword())) {
3675 ParseVariableDeclarations(kForStatement, &parsing_result, nullptr, 3672 ParseVariableDeclarations(kForStatement, &parsing_result, nullptr,
3676 CHECK_OK); 3673 CHECK_OK);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3712 bound_names_are_lexical = 3709 bound_names_are_lexical =
3713 IsLexicalVariableMode(parsing_result.descriptor.mode); 3710 IsLexicalVariableMode(parsing_result.descriptor.mode);
3714 3711
3715 // special case for legacy for (var ... = ... in ...) 3712 // special case for legacy for (var ... = ... in ...)
3716 if (!bound_names_are_lexical && decl.pattern->IsVariableProxy() && 3713 if (!bound_names_are_lexical && decl.pattern->IsVariableProxy() &&
3717 decl.initializer != nullptr) { 3714 decl.initializer != nullptr) {
3718 DCHECK(!allow_harmony_for_in()); 3715 DCHECK(!allow_harmony_for_in());
3719 ++use_counts_[v8::Isolate::kForInInitializer]; 3716 ++use_counts_[v8::Isolate::kForInInitializer];
3720 const AstRawString* name = 3717 const AstRawString* name =
3721 decl.pattern->AsVariableProxy()->raw_name(); 3718 decl.pattern->AsVariableProxy()->raw_name();
3722 VariableProxy* single_var = scope_->NewUnresolved( 3719 VariableProxy* single_var = scope()->NewUnresolved(
3723 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos); 3720 factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos);
3724 init_block = factory()->NewBlock( 3721 init_block = factory()->NewBlock(
3725 nullptr, 2, true, parsing_result.descriptor.declaration_pos); 3722 nullptr, 2, true, parsing_result.descriptor.declaration_pos);
3726 init_block->statements()->Add( 3723 init_block->statements()->Add(
3727 factory()->NewExpressionStatement( 3724 factory()->NewExpressionStatement(
3728 factory()->NewAssignment(Token::ASSIGN, single_var, 3725 factory()->NewAssignment(Token::ASSIGN, single_var,
3729 decl.initializer, kNoSourcePosition), 3726 decl.initializer, kNoSourcePosition),
3730 kNoSourcePosition), 3727 kNoSourcePosition),
3731 zone()); 3728 zone());
3732 } 3729 }
3733 3730
3734 // Rewrite a for-in/of statement of the form 3731 // Rewrite a for-in/of statement of the form
3735 // 3732 //
3736 // for (let/const/var x in/of e) b 3733 // for (let/const/var x in/of e) b
3737 // 3734 //
3738 // into 3735 // into
3739 // 3736 //
3740 // { 3737 // {
3741 // <let x' be a temporary variable> 3738 // <let x' be a temporary variable>
3742 // for (x' in/of e) { 3739 // for (x' in/of e) {
3743 // let/const/var x; 3740 // let/const/var x;
3744 // x = x'; 3741 // x = x';
3745 // b; 3742 // b;
3746 // } 3743 // }
3747 // let x; // for TDZ 3744 // let x; // for TDZ
3748 // } 3745 // }
3749 3746
3750 Variable* temp = 3747 Variable* temp =
3751 scope_->NewTemporary(ast_value_factory()->dot_for_string()); 3748 scope()->NewTemporary(ast_value_factory()->dot_for_string());
3752 ForEachStatement* loop = 3749 ForEachStatement* loop =
3753 factory()->NewForEachStatement(mode, labels, stmt_pos); 3750 factory()->NewForEachStatement(mode, labels, stmt_pos);
3754 Target target(&this->target_stack_, loop); 3751 Target target(&this->target_stack_, loop);
3755 3752
3756 int each_keyword_position = scanner()->location().beg_pos; 3753 int each_keyword_position = scanner()->location().beg_pos;
3757 3754
3758 Expression* enumerable; 3755 Expression* enumerable;
3759 if (mode == ForEachStatement::ITERATE) { 3756 if (mode == ForEachStatement::ITERATE) {
3760 ExpressionClassifier classifier(this); 3757 ExpressionClassifier classifier(this);
3761 enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK); 3758 enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK);
3762 RewriteNonPattern(&classifier, CHECK_OK); 3759 RewriteNonPattern(&classifier, CHECK_OK);
3763 } else { 3760 } else {
3764 enumerable = ParseExpression(true, CHECK_OK); 3761 enumerable = ParseExpression(true, CHECK_OK);
3765 } 3762 }
3766 3763
3767 Expect(Token::RPAREN, CHECK_OK); 3764 Expect(Token::RPAREN, CHECK_OK);
3768 3765
3769 Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); 3766 Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
3770 body_scope->set_start_position(scanner()->location().beg_pos); 3767 body_scope->set_start_position(scanner()->location().beg_pos);
3771 3768
3772 Block* body_block = 3769 Block* body_block =
3773 factory()->NewBlock(NULL, 3, false, kNoSourcePosition); 3770 factory()->NewBlock(NULL, 3, false, kNoSourcePosition);
3774 3771
3775 Statement* final_loop; 3772 Statement* final_loop;
3776 { 3773 {
3777 ReturnExprScope no_tail_calls(function_state_, 3774 ReturnExprScope no_tail_calls(function_state_,
3778 ReturnExprContext::kInsideForInOfBody); 3775 ReturnExprContext::kInsideForInOfBody);
3779 BlockState block_state(&scope_, body_scope); 3776 BlockState block_state(&scope_state_, body_scope);
3780 3777
3781 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK); 3778 Statement* body = ParseScopedStatement(NULL, true, CHECK_OK);
3782 3779
3783 auto each_initialization_block = 3780 auto each_initialization_block =
3784 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); 3781 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
3785 { 3782 {
3786 auto descriptor = parsing_result.descriptor; 3783 auto descriptor = parsing_result.descriptor;
3787 descriptor.declaration_pos = kNoSourcePosition; 3784 descriptor.declaration_pos = kNoSourcePosition;
3788 descriptor.initialization_pos = kNoSourcePosition; 3785 descriptor.initialization_pos = kNoSourcePosition;
3789 decl.initializer = factory()->NewVariableProxy(temp); 3786 decl.initializer = factory()->NewVariableProxy(temp);
3790 3787
3791 bool is_for_var_of = 3788 bool is_for_var_of =
3792 mode == ForEachStatement::ITERATE && 3789 mode == ForEachStatement::ITERATE &&
3793 parsing_result.descriptor.mode == VariableMode::VAR; 3790 parsing_result.descriptor.mode == VariableMode::VAR;
3794 3791
3795 PatternRewriter::DeclareAndInitializeVariables( 3792 PatternRewriter::DeclareAndInitializeVariables(
3796 each_initialization_block, &descriptor, &decl, 3793 each_initialization_block, &descriptor, &decl,
3797 bound_names_are_lexical || is_for_var_of ? &bound_names 3794 bound_names_are_lexical || is_for_var_of ? &bound_names
3798 : nullptr, 3795 : nullptr,
3799 CHECK_OK); 3796 CHECK_OK);
3800 3797
3801 // Annex B.3.5 prohibits the form 3798 // Annex B.3.5 prohibits the form
3802 // `try {} catch(e) { for (var e of {}); }` 3799 // `try {} catch(e) { for (var e of {}); }`
3803 // So if we are parsing a statement like `for (var ... of ...)` 3800 // So if we are parsing a statement like `for (var ... of ...)`
3804 // we need to walk up the scope chain and look for catch scopes 3801 // we need to walk up the scope chain and look for catch scopes
3805 // which have a simple binding, then compare their binding against 3802 // which have a simple binding, then compare their binding against
3806 // all of the names declared in the init of the for-of we're 3803 // all of the names declared in the init of the for-of we're
3807 // parsing. 3804 // parsing.
3808 if (is_for_var_of) { 3805 if (is_for_var_of) {
3809 Scope* catch_scope = scope_; 3806 Scope* catch_scope = scope();
3810 while (catch_scope != nullptr && 3807 while (catch_scope != nullptr &&
3811 !catch_scope->is_declaration_scope()) { 3808 !catch_scope->is_declaration_scope()) {
3812 if (catch_scope->is_catch_scope()) { 3809 if (catch_scope->is_catch_scope()) {
3813 auto name = catch_scope->catch_variable_name(); 3810 auto name = catch_scope->catch_variable_name();
3814 if (name != 3811 if (name !=
3815 ast_value_factory() 3812 ast_value_factory()
3816 ->dot_catch_string()) { // i.e. is a simple binding 3813 ->dot_catch_string()) { // i.e. is a simple binding
3817 if (bound_names.Contains(name)) { 3814 if (bound_names.Contains(name)) {
3818 ParserTraits::ReportMessageAt( 3815 ParserTraits::ReportMessageAt(
3819 parsing_result.bindings_loc, 3816 parsing_result.bindings_loc,
(...skipping 25 matching lines...) Expand all
3845 3842
3846 init_block = 3843 init_block =
3847 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); 3844 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition);
3848 3845
3849 for (int i = 0; i < bound_names.length(); ++i) { 3846 for (int i = 0; i < bound_names.length(); ++i) {
3850 // TODO(adamk): This needs to be some sort of special 3847 // TODO(adamk): This needs to be some sort of special
3851 // INTERNAL variable that's invisible to the debugger 3848 // INTERNAL variable that's invisible to the debugger
3852 // but visible to everything else. 3849 // but visible to everything else.
3853 VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET); 3850 VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET);
3854 Declaration* tdz_decl = factory()->NewVariableDeclaration( 3851 Declaration* tdz_decl = factory()->NewVariableDeclaration(
3855 tdz_proxy, LET, scope_, kNoSourcePosition); 3852 tdz_proxy, LET, scope(), kNoSourcePosition);
3856 Variable* tdz_var = Declare( 3853 Variable* tdz_var = Declare(
3857 tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK); 3854 tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK);
3858 tdz_var->set_initializer_position(position()); 3855 tdz_var->set_initializer_position(position());
3859 } 3856 }
3860 } 3857 }
3861 3858
3862 for_scope->set_end_position(scanner()->location().end_pos); 3859 for_scope->set_end_position(scanner()->location().end_pos);
3863 for_scope = for_scope->FinalizeBlockScope(); 3860 for_scope = for_scope->FinalizeBlockScope();
3864 // Parsed for-in loop w/ variable declarations. 3861 // Parsed for-in loop w/ variable declarations.
3865 if (init_block != nullptr) { 3862 if (init_block != nullptr) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3940 3937
3941 // Parsed initializer at this point. 3938 // Parsed initializer at this point.
3942 Expect(Token::SEMICOLON, CHECK_OK); 3939 Expect(Token::SEMICOLON, CHECK_OK);
3943 3940
3944 Expression* cond = NULL; 3941 Expression* cond = NULL;
3945 Statement* next = NULL; 3942 Statement* next = NULL;
3946 Statement* body = NULL; 3943 Statement* body = NULL;
3947 3944
3948 // If there are let bindings, then condition and the next statement of the 3945 // If there are let bindings, then condition and the next statement of the
3949 // for loop must be parsed in a new scope. 3946 // for loop must be parsed in a new scope.
3950 Scope* inner_scope = scope_; 3947 Scope* inner_scope = scope();
3951 if (bound_names_are_lexical && bound_names.length() > 0) { 3948 if (bound_names_are_lexical && bound_names.length() > 0) {
3952 inner_scope = NewScope(for_scope, BLOCK_SCOPE); 3949 inner_scope = NewScope(for_scope, BLOCK_SCOPE);
3953 inner_scope->set_start_position(scanner()->location().beg_pos); 3950 inner_scope->set_start_position(scanner()->location().beg_pos);
3954 } 3951 }
3955 { 3952 {
3956 BlockState block_state(&scope_, inner_scope); 3953 BlockState block_state(&scope_state_, inner_scope);
3957 3954
3958 if (peek() != Token::SEMICOLON) { 3955 if (peek() != Token::SEMICOLON) {
3959 cond = ParseExpression(true, CHECK_OK); 3956 cond = ParseExpression(true, CHECK_OK);
3960 } 3957 }
3961 Expect(Token::SEMICOLON, CHECK_OK); 3958 Expect(Token::SEMICOLON, CHECK_OK);
3962 3959
3963 if (peek() != Token::RPAREN) { 3960 if (peek() != Token::RPAREN) {
3964 Expression* exp = ParseExpression(true, CHECK_OK); 3961 Expression* exp = ParseExpression(true, CHECK_OK);
3965 next = factory()->NewExpressionStatement(exp, exp->position()); 3962 next = factory()->NewExpressionStatement(exp, exp->position());
3966 } 3963 }
3967 Expect(Token::RPAREN, CHECK_OK); 3964 Expect(Token::RPAREN, CHECK_OK);
3968 3965
3969 body = ParseScopedStatement(NULL, true, CHECK_OK); 3966 body = ParseScopedStatement(NULL, true, CHECK_OK);
3970 } 3967 }
3971 3968
3972 Statement* result = NULL; 3969 Statement* result = NULL;
3973 if (bound_names_are_lexical && bound_names.length() > 0) { 3970 if (bound_names_are_lexical && bound_names.length() > 0) {
3974 BlockState block_state(&scope_, for_scope); 3971 BlockState block_state(&scope_state_, for_scope);
3975 result = DesugarLexicalBindingsInForStatement( 3972 result = DesugarLexicalBindingsInForStatement(
3976 inner_scope, parsing_result.descriptor.mode, &bound_names, loop, init, 3973 inner_scope, parsing_result.descriptor.mode, &bound_names, loop, init,
3977 cond, next, body, CHECK_OK); 3974 cond, next, body, CHECK_OK);
3978 for_scope->set_end_position(scanner()->location().end_pos); 3975 for_scope->set_end_position(scanner()->location().end_pos);
3979 } else { 3976 } else {
3980 for_scope->set_end_position(scanner()->location().end_pos); 3977 for_scope->set_end_position(scanner()->location().end_pos);
3981 for_scope = for_scope->FinalizeBlockScope(); 3978 for_scope = for_scope->FinalizeBlockScope();
3982 if (for_scope) { 3979 if (for_scope) {
3983 // Rewrite a for statement of the form 3980 // Rewrite a for statement of the form
3984 // for (const x = i; c; n) b 3981 // for (const x = i; c; n) b
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
4113 parameters->is_simple = !is_rest && expr->IsVariableProxy(); 4110 parameters->is_simple = !is_rest && expr->IsVariableProxy();
4114 } 4111 }
4115 4112
4116 Expression* initializer = nullptr; 4113 Expression* initializer = nullptr;
4117 if (expr->IsVariableProxy()) { 4114 if (expr->IsVariableProxy()) {
4118 // When the formal parameter was originally seen, it was parsed as a 4115 // When the formal parameter was originally seen, it was parsed as a
4119 // VariableProxy and recorded as unresolved in the scope. Here we undo that 4116 // VariableProxy and recorded as unresolved in the scope. Here we undo that
4120 // parse-time side-effect for parameters that are single-names (not 4117 // parse-time side-effect for parameters that are single-names (not
4121 // patterns; for patterns that happens uniformly in 4118 // patterns; for patterns that happens uniformly in
4122 // PatternRewriter::VisitVariableProxy). 4119 // PatternRewriter::VisitVariableProxy).
4123 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); 4120 parser_->scope()->RemoveUnresolved(expr->AsVariableProxy());
4124 } else if (expr->IsAssignment()) { 4121 } else if (expr->IsAssignment()) {
4125 Assignment* assignment = expr->AsAssignment(); 4122 Assignment* assignment = expr->AsAssignment();
4126 DCHECK(!assignment->is_compound()); 4123 DCHECK(!assignment->is_compound());
4127 initializer = assignment->value(); 4124 initializer = assignment->value();
4128 expr = assignment->target(); 4125 expr = assignment->target();
4129 4126
4130 // TODO(adamk): Only call this if necessary. 4127 // TODO(adamk): Only call this if necessary.
4131 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, 4128 RewriteParameterInitializerScope(parser_->stack_limit(), initializer,
4132 parser_->scope_, parameters->scope); 4129 parser_->scope(), parameters->scope);
4133 } 4130 }
4134 4131
4135 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); 4132 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest);
4136 } 4133 }
4137 4134
4138 void ParserTraits::ParseAsyncArrowSingleExpressionBody( 4135 void ParserTraits::ParseAsyncArrowSingleExpressionBody(
4139 ZoneList<Statement*>* body, bool accept_IN, 4136 ZoneList<Statement*>* body, bool accept_IN,
4140 Type::ExpressionClassifier* classifier, int pos, bool* ok) { 4137 Type::ExpressionClassifier* classifier, int pos, bool* ok) {
4141 parser_->DesugarAsyncFunctionBody( 4138 parser_->DesugarAsyncFunctionBody(
4142 parser_->ast_value_factory()->empty_string(), parser_->scope_, body, 4139 parser_->ast_value_factory()->empty_string(), parser_->scope(), body,
4143 classifier, kAsyncArrowFunction, FunctionBody::SingleExpression, 4140 classifier, kAsyncArrowFunction, FunctionBody::SingleExpression,
4144 accept_IN, pos, ok); 4141 accept_IN, pos, ok);
4145 } 4142 }
4146 4143
4147 void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, 4144 void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
4148 Scope* scope, ZoneList<Statement*>* body, 4145 Scope* scope, ZoneList<Statement*>* body,
4149 ExpressionClassifier* classifier, 4146 ExpressionClassifier* classifier,
4150 FunctionKind kind, FunctionBody body_type, 4147 FunctionKind kind, FunctionBody body_type,
4151 bool accept_IN, int pos, bool* ok) { 4148 bool accept_IN, int pos, bool* ok) {
4152 // function async_function() { 4149 // function async_function() {
4153 // try { 4150 // try {
4154 // .generator_object = %CreateGeneratorObject(); 4151 // .generator_object = %CreateGeneratorObject();
4155 // ... function body ... 4152 // ... function body ...
4156 // } catch (e) { 4153 // } catch (e) {
4157 // return Promise.reject(e); 4154 // return Promise.reject(e);
4158 // } 4155 // }
4159 // } 4156 // }
4160 scope->ForceContextAllocation(); 4157 scope->ForceContextAllocation();
4161 Variable* temp = 4158 Variable* temp = this->scope()->NewTemporary(
4162 scope_->NewTemporary(ast_value_factory()->dot_generator_object_string()); 4159 ast_value_factory()->dot_generator_object_string());
4163 function_state_->set_generator_object_variable(temp); 4160 function_state_->set_generator_object_variable(temp);
4164 4161
4165 Expression* init_generator_variable = factory()->NewAssignment( 4162 Expression* init_generator_variable = factory()->NewAssignment(
4166 Token::INIT, factory()->NewVariableProxy(temp), 4163 Token::INIT, factory()->NewVariableProxy(temp),
4167 BuildCreateJSGeneratorObject(pos, kind), kNoSourcePosition); 4164 BuildCreateJSGeneratorObject(pos, kind), kNoSourcePosition);
4168 body->Add(factory()->NewExpressionStatement(init_generator_variable, 4165 body->Add(factory()->NewExpressionStatement(init_generator_variable,
4169 kNoSourcePosition), 4166 kNoSourcePosition),
4170 zone()); 4167 zone());
4171 4168
4172 Block* try_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); 4169 Block* try_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
(...skipping 18 matching lines...) Expand all
4191 scope->set_end_position(scanner()->location().end_pos); 4188 scope->set_end_position(scanner()->location().end_pos);
4192 } 4189 }
4193 4190
4194 DoExpression* Parser::ParseDoExpression(bool* ok) { 4191 DoExpression* Parser::ParseDoExpression(bool* ok) {
4195 // AssignmentExpression :: 4192 // AssignmentExpression ::
4196 // do '{' StatementList '}' 4193 // do '{' StatementList '}'
4197 int pos = peek_position(); 4194 int pos = peek_position();
4198 4195
4199 Expect(Token::DO, CHECK_OK); 4196 Expect(Token::DO, CHECK_OK);
4200 Variable* result = 4197 Variable* result =
4201 scope_->NewTemporary(ast_value_factory()->dot_result_string()); 4198 scope()->NewTemporary(ast_value_factory()->dot_result_string());
4202 Block* block = ParseBlock(nullptr, false, CHECK_OK); 4199 Block* block = ParseBlock(nullptr, false, CHECK_OK);
4203 DoExpression* expr = factory()->NewDoExpression(block, result, pos); 4200 DoExpression* expr = factory()->NewDoExpression(block, result, pos);
4204 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) { 4201 if (!Rewriter::Rewrite(this, expr, ast_value_factory())) {
4205 *ok = false; 4202 *ok = false;
4206 return nullptr; 4203 return nullptr;
4207 } 4204 }
4208 block->set_scope(block->scope()->FinalizeBlockScope()); 4205 block->set_scope(block->scope()->FinalizeBlockScope());
4209 return expr; 4206 return expr;
4210 } 4207 }
4211 4208
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4277 // Anonymous functions were passed either the empty symbol or a null 4274 // Anonymous functions were passed either the empty symbol or a null
4278 // handle as the function name. Remember if we were passed a non-empty 4275 // handle as the function name. Remember if we were passed a non-empty
4279 // handle to decide whether to invoke function name inference. 4276 // handle to decide whether to invoke function name inference.
4280 bool should_infer_name = function_name == NULL; 4277 bool should_infer_name = function_name == NULL;
4281 4278
4282 // We want a non-null handle as the function name. 4279 // We want a non-null handle as the function name.
4283 if (should_infer_name) { 4280 if (should_infer_name) {
4284 function_name = ast_value_factory()->empty_string(); 4281 function_name = ast_value_factory()->empty_string();
4285 } 4282 }
4286 4283
4287 Scope* scope = NewScope(scope_, FUNCTION_SCOPE, kind); 4284 Scope* scope = NewScope(this->scope(), FUNCTION_SCOPE, kind);
4288 SetLanguageMode(scope, language_mode); 4285 SetLanguageMode(scope, language_mode);
4289 ZoneList<Statement*>* body = NULL; 4286 ZoneList<Statement*>* body = NULL;
4290 int arity = -1; 4287 int arity = -1;
4291 int materialized_literal_count = -1; 4288 int materialized_literal_count = -1;
4292 int expected_property_count = -1; 4289 int expected_property_count = -1;
4293 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 4290 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
4294 bool should_be_used_once_hint = false; 4291 bool should_be_used_once_hint = false;
4295 bool has_duplicate_parameters; 4292 bool has_duplicate_parameters;
4296 FunctionLiteral::EagerCompileHint eager_compile_hint; 4293 FunctionLiteral::EagerCompileHint eager_compile_hint;
4297 4294
4298 // Parse function. 4295 // Parse function.
4299 { 4296 {
4300 AstNodeFactory function_factory(ast_value_factory()); 4297 AstNodeFactory function_factory(ast_value_factory());
4301 FunctionState function_state(&function_state_, &scope_, scope, kind, 4298 FunctionState function_state(&function_state_, &scope_state_, scope, kind,
4302 &function_factory); 4299 &function_factory);
4303 scope_->SetScopeName(function_name); 4300 this->scope()->SetScopeName(function_name);
4304 ExpressionClassifier formals_classifier(this, &duplicate_finder); 4301 ExpressionClassifier formals_classifier(this, &duplicate_finder);
4305 4302
4306 eager_compile_hint = function_state_->this_function_is_parenthesized() 4303 eager_compile_hint = function_state_->this_function_is_parenthesized()
4307 ? FunctionLiteral::kShouldEagerCompile 4304 ? FunctionLiteral::kShouldEagerCompile
4308 : FunctionLiteral::kShouldLazyCompile; 4305 : FunctionLiteral::kShouldLazyCompile;
4309 4306
4310 if (is_generator) { 4307 if (is_generator) {
4311 // For generators, allocating variables in contexts is currently a win 4308 // For generators, allocating variables in contexts is currently a win
4312 // because it minimizes the work needed to suspend and resume an 4309 // because it minimizes the work needed to suspend and resume an
4313 // activation. The machine code produced for generators (by full-codegen) 4310 // activation. The machine code produced for generators (by full-codegen)
4314 // relies on this forced context allocation, but not in an essential way. 4311 // relies on this forced context allocation, but not in an essential way.
4315 scope_->ForceContextAllocation(); 4312 this->scope()->ForceContextAllocation();
4316 4313
4317 // Calling a generator returns a generator object. That object is stored 4314 // Calling a generator returns a generator object. That object is stored
4318 // in a temporary variable, a definition that is used by "yield" 4315 // in a temporary variable, a definition that is used by "yield"
4319 // expressions. This also marks the FunctionState as a generator. 4316 // expressions. This also marks the FunctionState as a generator.
4320 Variable* temp = scope_->NewTemporary( 4317 Variable* temp = this->scope()->NewTemporary(
4321 ast_value_factory()->dot_generator_object_string()); 4318 ast_value_factory()->dot_generator_object_string());
4322 function_state.set_generator_object_variable(temp); 4319 function_state.set_generator_object_variable(temp);
4323 } 4320 }
4324 4321
4325 Expect(Token::LPAREN, CHECK_OK); 4322 Expect(Token::LPAREN, CHECK_OK);
4326 int start_position = scanner()->location().beg_pos; 4323 int start_position = scanner()->location().beg_pos;
4327 scope_->set_start_position(start_position); 4324 this->scope()->set_start_position(start_position);
4328 ParserFormalParameters formals(scope); 4325 ParserFormalParameters formals(scope);
4329 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); 4326 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
4330 arity = formals.Arity(); 4327 arity = formals.Arity();
4331 Expect(Token::RPAREN, CHECK_OK); 4328 Expect(Token::RPAREN, CHECK_OK);
4332 int formals_end_position = scanner()->location().end_pos; 4329 int formals_end_position = scanner()->location().end_pos;
4333 4330
4334 CheckArityRestrictions(arity, kind, formals.has_rest, start_position, 4331 CheckArityRestrictions(arity, kind, formals.has_rest, start_position,
4335 formals_end_position, CHECK_OK); 4332 formals_end_position, CHECK_OK);
4336 Expect(Token::LBRACE, CHECK_OK); 4333 Expect(Token::LBRACE, CHECK_OK);
4337 // Don't include the rest parameter into the function's formal parameter 4334 // Don't include the rest parameter into the function's formal parameter
(...skipping 28 matching lines...) Expand all
4366 4363
4367 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume 4364 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume
4368 // parenthesis before the function means that it will be called 4365 // parenthesis before the function means that it will be called
4369 // immediately). The inner function *must* be parsed eagerly to resolve the 4366 // immediately). The inner function *must* be parsed eagerly to resolve the
4370 // possible reference to the variable in foo's scope. However, it's possible 4367 // possible reference to the variable in foo's scope. However, it's possible
4371 // that it will be compiled lazily. 4368 // that it will be compiled lazily.
4372 4369
4373 // To make this additional case work, both Parser and PreParser implement a 4370 // To make this additional case work, both Parser and PreParser implement a
4374 // logic where only top-level functions will be parsed lazily. 4371 // logic where only top-level functions will be parsed lazily.
4375 bool is_lazily_parsed = mode() == PARSE_LAZILY && 4372 bool is_lazily_parsed = mode() == PARSE_LAZILY &&
4376 scope_->AllowsLazyParsing() && 4373 this->scope()->AllowsLazyParsing() &&
4377 !function_state_->this_function_is_parenthesized(); 4374 !function_state_->this_function_is_parenthesized();
4378 4375
4379 // Eager or lazy parse? 4376 // Eager or lazy parse?
4380 // If is_lazily_parsed, we'll parse lazy. If we can set a bookmark, we'll 4377 // If is_lazily_parsed, we'll parse lazy. If we can set a bookmark, we'll
4381 // pass it to SkipLazyFunctionBody, which may use it to abort lazy 4378 // pass it to SkipLazyFunctionBody, which may use it to abort lazy
4382 // parsing if it suspect that wasn't a good idea. If so, or if we didn't 4379 // parsing if it suspect that wasn't a good idea. If so, or if we didn't
4383 // try to lazy parse in the first place, we'll have to parse eagerly. 4380 // try to lazy parse in the first place, we'll have to parse eagerly.
4384 Scanner::BookmarkScope bookmark(scanner()); 4381 Scanner::BookmarkScope bookmark(scanner());
4385 if (is_lazily_parsed) { 4382 if (is_lazily_parsed) {
4386 Scanner::BookmarkScope* maybe_bookmark = 4383 Scanner::BookmarkScope* maybe_bookmark =
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
4533 // If we have cached data, we use it to skip parsing the function body. The 4530 // If we have cached data, we use it to skip parsing the function body. The
4534 // data contains the information we need to construct the lazy function. 4531 // data contains the information we need to construct the lazy function.
4535 FunctionEntry entry = 4532 FunctionEntry entry =
4536 cached_parse_data_->GetFunctionEntry(function_block_pos); 4533 cached_parse_data_->GetFunctionEntry(function_block_pos);
4537 // Check that cached data is valid. If not, mark it as invalid (the embedder 4534 // Check that cached data is valid. If not, mark it as invalid (the embedder
4538 // handles it). Note that end position greater than end of stream is safe, 4535 // handles it). Note that end position greater than end of stream is safe,
4539 // and hard to check. 4536 // and hard to check.
4540 if (entry.is_valid() && entry.end_pos() > function_block_pos) { 4537 if (entry.is_valid() && entry.end_pos() > function_block_pos) {
4541 scanner()->SeekForward(entry.end_pos() - 1); 4538 scanner()->SeekForward(entry.end_pos() - 1);
4542 4539
4543 scope_->set_end_position(entry.end_pos()); 4540 scope()->set_end_position(entry.end_pos());
4544 Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void)); 4541 Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void));
4545 total_preparse_skipped_ += scope_->end_position() - function_block_pos; 4542 total_preparse_skipped_ += scope()->end_position() - function_block_pos;
4546 *materialized_literal_count = entry.literal_count(); 4543 *materialized_literal_count = entry.literal_count();
4547 *expected_property_count = entry.property_count(); 4544 *expected_property_count = entry.property_count();
4548 SetLanguageMode(scope_, entry.language_mode()); 4545 SetLanguageMode(scope(), entry.language_mode());
4549 if (entry.uses_super_property()) scope_->RecordSuperPropertyUsage(); 4546 if (entry.uses_super_property()) scope()->RecordSuperPropertyUsage();
4550 if (entry.calls_eval()) scope_->RecordEvalCall(); 4547 if (entry.calls_eval()) scope()->RecordEvalCall();
4551 return; 4548 return;
4552 } 4549 }
4553 cached_parse_data_->Reject(); 4550 cached_parse_data_->Reject();
4554 } 4551 }
4555 // With no cached data, we partially parse the function, without building an 4552 // With no cached data, we partially parse the function, without building an
4556 // AST. This gathers the data needed to build a lazy function. 4553 // AST. This gathers the data needed to build a lazy function.
4557 SingletonLogger logger; 4554 SingletonLogger logger;
4558 PreParser::PreParseResult result = 4555 PreParser::PreParseResult result =
4559 ParseLazyFunctionBodyWithPreParser(&logger, bookmark); 4556 ParseLazyFunctionBodyWithPreParser(&logger, bookmark);
4560 if (bookmark && bookmark->HasBeenReset()) { 4557 if (bookmark && bookmark->HasBeenReset()) {
4561 return; // Return immediately if pre-parser devided to abort parsing. 4558 return; // Return immediately if pre-parser devided to abort parsing.
4562 } 4559 }
4563 if (result == PreParser::kPreParseStackOverflow) { 4560 if (result == PreParser::kPreParseStackOverflow) {
4564 // Propagate stack overflow. 4561 // Propagate stack overflow.
4565 set_stack_overflow(); 4562 set_stack_overflow();
4566 *ok = false; 4563 *ok = false;
4567 return; 4564 return;
4568 } 4565 }
4569 if (logger.has_error()) { 4566 if (logger.has_error()) {
4570 ParserTraits::ReportMessageAt( 4567 ParserTraits::ReportMessageAt(
4571 Scanner::Location(logger.start(), logger.end()), logger.message(), 4568 Scanner::Location(logger.start(), logger.end()), logger.message(),
4572 logger.argument_opt(), logger.error_type()); 4569 logger.argument_opt(), logger.error_type());
4573 *ok = false; 4570 *ok = false;
4574 return; 4571 return;
4575 } 4572 }
4576 scope_->set_end_position(logger.end()); 4573 scope()->set_end_position(logger.end());
4577 Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void)); 4574 Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void));
4578 total_preparse_skipped_ += scope_->end_position() - function_block_pos; 4575 total_preparse_skipped_ += scope()->end_position() - function_block_pos;
4579 *materialized_literal_count = logger.literals(); 4576 *materialized_literal_count = logger.literals();
4580 *expected_property_count = logger.properties(); 4577 *expected_property_count = logger.properties();
4581 SetLanguageMode(scope_, logger.language_mode()); 4578 SetLanguageMode(scope(), logger.language_mode());
4582 if (logger.uses_super_property()) { 4579 if (logger.uses_super_property()) {
4583 scope_->RecordSuperPropertyUsage(); 4580 scope()->RecordSuperPropertyUsage();
4584 } 4581 }
4585 if (logger.calls_eval()) { 4582 if (logger.calls_eval()) {
4586 scope_->RecordEvalCall(); 4583 scope()->RecordEvalCall();
4587 } 4584 }
4588 if (produce_cached_parse_data()) { 4585 if (produce_cached_parse_data()) {
4589 DCHECK(log_); 4586 DCHECK(log_);
4590 // Position right after terminal '}'. 4587 // Position right after terminal '}'.
4591 int body_end = scanner()->location().end_pos; 4588 int body_end = scanner()->location().end_pos;
4592 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, 4589 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count,
4593 *expected_property_count, scope_->language_mode(), 4590 *expected_property_count, scope()->language_mode(),
4594 scope_->uses_super_property(), scope_->calls_eval()); 4591 scope()->uses_super_property(), scope()->calls_eval());
4595 } 4592 }
4596 } 4593 }
4597 4594
4598 4595
4599 Statement* Parser::BuildAssertIsCoercible(Variable* var) { 4596 Statement* Parser::BuildAssertIsCoercible(Variable* var) {
4600 // if (var === null || var === undefined) 4597 // if (var === null || var === undefined)
4601 // throw /* type error kNonCoercible) */; 4598 // throw /* type error kNonCoercible) */;
4602 4599
4603 Expression* condition = factory()->NewBinaryOperation( 4600 Expression* condition = factory()->NewBinaryOperation(
4604 Token::OR, 4601 Token::OR,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4649 4646
4650 void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) { 4647 void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) {
4651 InitializerRewriter rewriter(stack_limit_, expr, this, scope); 4648 InitializerRewriter rewriter(stack_limit_, expr, this, scope);
4652 rewriter.Run(); 4649 rewriter.Run();
4653 } 4650 }
4654 4651
4655 4652
4656 Block* Parser::BuildParameterInitializationBlock( 4653 Block* Parser::BuildParameterInitializationBlock(
4657 const ParserFormalParameters& parameters, bool* ok) { 4654 const ParserFormalParameters& parameters, bool* ok) {
4658 DCHECK(!parameters.is_simple); 4655 DCHECK(!parameters.is_simple);
4659 DCHECK(scope_->is_function_scope()); 4656 DCHECK(scope()->is_function_scope());
4660 Block* init_block = factory()->NewBlock(NULL, 1, true, kNoSourcePosition); 4657 Block* init_block = factory()->NewBlock(NULL, 1, true, kNoSourcePosition);
4661 for (int i = 0; i < parameters.params.length(); ++i) { 4658 for (int i = 0; i < parameters.params.length(); ++i) {
4662 auto parameter = parameters.params[i]; 4659 auto parameter = parameters.params[i];
4663 if (parameter.is_rest && parameter.pattern->IsVariableProxy()) break; 4660 if (parameter.is_rest && parameter.pattern->IsVariableProxy()) break;
4664 DeclarationDescriptor descriptor; 4661 DeclarationDescriptor descriptor;
4665 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; 4662 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER;
4666 descriptor.parser = this; 4663 descriptor.parser = this;
4667 descriptor.scope = scope_; 4664 descriptor.scope = scope();
4668 descriptor.hoist_scope = nullptr; 4665 descriptor.hoist_scope = nullptr;
4669 descriptor.mode = LET; 4666 descriptor.mode = LET;
4670 descriptor.declaration_pos = parameter.pattern->position(); 4667 descriptor.declaration_pos = parameter.pattern->position();
4671 // The position that will be used by the AssignmentExpression 4668 // The position that will be used by the AssignmentExpression
4672 // which copies from the temp parameter to the pattern. 4669 // which copies from the temp parameter to the pattern.
4673 // 4670 //
4674 // TODO(adamk): Should this be kNoSourcePosition, since 4671 // TODO(adamk): Should this be kNoSourcePosition, since
4675 // it's just copying from a temp var to the real param var? 4672 // it's just copying from a temp var to the real param var?
4676 descriptor.initialization_pos = parameter.pattern->position(); 4673 descriptor.initialization_pos = parameter.pattern->position();
4677 // The initializer position which will end up in, 4674 // The initializer position which will end up in,
4678 // Variable::initializer_position(), used for hole check elimination. 4675 // Variable::initializer_position(), used for hole check elimination.
4679 int initializer_position = parameter.pattern->position(); 4676 int initializer_position = parameter.pattern->position();
4680 Expression* initial_value = 4677 Expression* initial_value =
4681 factory()->NewVariableProxy(parameters.scope->parameter(i)); 4678 factory()->NewVariableProxy(parameters.scope->parameter(i));
4682 if (parameter.initializer != nullptr) { 4679 if (parameter.initializer != nullptr) {
4683 // IS_UNDEFINED($param) ? initializer : $param 4680 // IS_UNDEFINED($param) ? initializer : $param
4684 4681
4685 // Ensure initializer is rewritten 4682 // Ensure initializer is rewritten
4686 RewriteParameterInitializer(parameter.initializer, scope_); 4683 RewriteParameterInitializer(parameter.initializer, scope());
4687 4684
4688 auto condition = factory()->NewCompareOperation( 4685 auto condition = factory()->NewCompareOperation(
4689 Token::EQ_STRICT, 4686 Token::EQ_STRICT,
4690 factory()->NewVariableProxy(parameters.scope->parameter(i)), 4687 factory()->NewVariableProxy(parameters.scope->parameter(i)),
4691 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition); 4688 factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition);
4692 initial_value = factory()->NewConditional( 4689 initial_value = factory()->NewConditional(
4693 condition, parameter.initializer, initial_value, kNoSourcePosition); 4690 condition, parameter.initializer, initial_value, kNoSourcePosition);
4694 descriptor.initialization_pos = parameter.initializer->position(); 4691 descriptor.initialization_pos = parameter.initializer->position();
4695 initializer_position = parameter.initializer_end_position; 4692 initializer_position = parameter.initializer_end_position;
4696 } 4693 }
4697 4694
4698 Scope* param_scope = scope_; 4695 Scope* param_scope = scope();
4699 Block* param_block = init_block; 4696 Block* param_block = init_block;
4700 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { 4697 if (!parameter.is_simple() && scope()->calls_sloppy_eval()) {
4701 param_scope = NewScope(scope_, BLOCK_SCOPE); 4698 param_scope = NewScope(scope(), BLOCK_SCOPE);
4702 param_scope->set_is_declaration_scope(); 4699 param_scope->set_is_declaration_scope();
4703 param_scope->set_start_position(descriptor.initialization_pos); 4700 param_scope->set_start_position(descriptor.initialization_pos);
4704 param_scope->set_end_position(parameter.initializer_end_position); 4701 param_scope->set_end_position(parameter.initializer_end_position);
4705 param_scope->RecordEvalCall(); 4702 param_scope->RecordEvalCall();
4706 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); 4703 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
4707 param_block->set_scope(param_scope); 4704 param_block->set_scope(param_scope);
4708 descriptor.hoist_scope = scope_; 4705 descriptor.hoist_scope = scope();
4709 // Pass the appropriate scope in so that PatternRewriter can appropriately 4706 // Pass the appropriate scope in so that PatternRewriter can appropriately
4710 // rewrite inner initializers of the pattern to param_scope 4707 // rewrite inner initializers of the pattern to param_scope
4711 descriptor.scope = param_scope; 4708 descriptor.scope = param_scope;
4712 // Rewrite the outer initializer to point to param_scope 4709 // Rewrite the outer initializer to point to param_scope
4713 RewriteParameterInitializerScope(stack_limit(), initial_value, scope_, 4710 RewriteParameterInitializerScope(stack_limit(), initial_value, scope(),
4714 param_scope); 4711 param_scope);
4715 } 4712 }
4716 4713
4717 { 4714 {
4718 BlockState block_state(&scope_, param_scope); 4715 BlockState block_state(&scope_state_, param_scope);
4719 DeclarationParsingResult::Declaration decl( 4716 DeclarationParsingResult::Declaration decl(
4720 parameter.pattern, initializer_position, initial_value); 4717 parameter.pattern, initializer_position, initial_value);
4721 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, 4718 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor,
4722 &decl, nullptr, CHECK_OK); 4719 &decl, nullptr, CHECK_OK);
4723 } 4720 }
4724 4721
4725 if (!parameter.is_simple() && scope_->calls_sloppy_eval()) { 4722 if (!parameter.is_simple() && scope()->calls_sloppy_eval()) {
4726 param_scope = param_scope->FinalizeBlockScope(); 4723 param_scope = param_scope->FinalizeBlockScope();
4727 if (param_scope != nullptr) { 4724 if (param_scope != nullptr) {
4728 CheckConflictingVarDeclarations(param_scope, CHECK_OK); 4725 CheckConflictingVarDeclarations(param_scope, CHECK_OK);
4729 } 4726 }
4730 init_block->statements()->Add(param_block, zone()); 4727 init_block->statements()->Add(param_block, zone());
4731 } 4728 }
4732 } 4729 }
4733 return init_block; 4730 return init_block;
4734 } 4731 }
4735 4732
4736 Block* Parser::BuildRejectPromiseOnException(Block* block) { 4733 Block* Parser::BuildRejectPromiseOnException(Block* block) {
4737 // try { <block> } catch (error) { return Promise.reject(error); } 4734 // try { <block> } catch (error) { return Promise.reject(error); }
4738 Block* try_block = block; 4735 Block* try_block = block;
4739 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); 4736 Scope* catch_scope = NewScope(scope(), CATCH_SCOPE);
4740 catch_scope->set_is_hidden(); 4737 catch_scope->set_is_hidden();
4741 Variable* catch_variable = 4738 Variable* catch_variable =
4742 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, 4739 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR,
4743 kCreatedInitialized, Variable::NORMAL); 4740 kCreatedInitialized, Variable::NORMAL);
4744 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); 4741 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
4745 4742
4746 Expression* promise_reject = BuildPromiseReject( 4743 Expression* promise_reject = BuildPromiseReject(
4747 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); 4744 factory()->NewVariableProxy(catch_variable), kNoSourcePosition);
4748 4745
4749 ReturnStatement* return_promise_reject = 4746 ReturnStatement* return_promise_reject =
4750 factory()->NewReturnStatement(promise_reject, kNoSourcePosition); 4747 factory()->NewReturnStatement(promise_reject, kNoSourcePosition);
4751 catch_block->statements()->Add(return_promise_reject, zone()); 4748 catch_block->statements()->Add(return_promise_reject, zone());
4752 TryStatement* try_catch_statement = factory()->NewTryCatchStatement( 4749 TryStatement* try_catch_statement = factory()->NewTryCatchStatement(
4753 try_block, catch_scope, catch_variable, catch_block, kNoSourcePosition); 4750 try_block, catch_scope, catch_variable, catch_block, kNoSourcePosition);
4754 4751
4755 block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); 4752 block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
4756 block->statements()->Add(try_catch_statement, zone()); 4753 block->statements()->Add(try_catch_statement, zone());
4757 return block; 4754 return block;
4758 } 4755 }
4759 4756
4760 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { 4757 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) {
4761 DCHECK_NOT_NULL(function_state_->generator_object_variable()); 4758 DCHECK_NOT_NULL(function_state_->generator_object_variable());
4762 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); 4759 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone());
4763 args->Add(factory()->NewThisFunction(pos), zone()); 4760 args->Add(factory()->NewThisFunction(pos), zone());
4764 args->Add(IsArrowFunction(kind) 4761 args->Add(IsArrowFunction(kind)
4765 ? GetLiteralUndefined(pos) 4762 ? GetLiteralUndefined(pos)
4766 : ThisExpression(scope_, factory(), kNoSourcePosition), 4763 : ThisExpression(scope(), factory(), kNoSourcePosition),
4767 zone()); 4764 zone());
4768 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, 4765 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args,
4769 pos); 4766 pos);
4770 } 4767 }
4771 4768
4772 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) { 4769 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) {
4773 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); 4770 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone());
4774 args->Add(value, zone()); 4771 args->Add(value, zone());
4775 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args, 4772 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args,
4776 pos); 4773 pos);
(...skipping 21 matching lines...) Expand all
4798 // If we have a named function expression, we add a local variable 4795 // If we have a named function expression, we add a local variable
4799 // declaration to the body of the function with the name of the 4796 // declaration to the body of the function with the name of the
4800 // function and let it refer to the function itself (closure). 4797 // function and let it refer to the function itself (closure).
4801 // Not having parsed the function body, the language mode may still change, 4798 // Not having parsed the function body, the language mode may still change,
4802 // so we reserve a spot and create the actual const assignment later. 4799 // so we reserve a spot and create the actual const assignment later.
4803 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length()); 4800 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length());
4804 result->Add(NULL, zone()); 4801 result->Add(NULL, zone());
4805 } 4802 }
4806 4803
4807 ZoneList<Statement*>* body = result; 4804 ZoneList<Statement*>* body = result;
4808 Scope* inner_scope = scope_; 4805 Scope* inner_scope = scope();
4809 Block* inner_block = nullptr; 4806 Block* inner_block = nullptr;
4810 if (!parameters.is_simple) { 4807 if (!parameters.is_simple) {
4811 inner_scope = NewScope(scope_, BLOCK_SCOPE); 4808 inner_scope = NewScope(scope(), BLOCK_SCOPE);
4812 inner_scope->set_is_declaration_scope(); 4809 inner_scope->set_is_declaration_scope();
4813 inner_scope->set_start_position(scanner()->location().beg_pos); 4810 inner_scope->set_start_position(scanner()->location().beg_pos);
4814 inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); 4811 inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
4815 inner_block->set_scope(inner_scope); 4812 inner_block->set_scope(inner_scope);
4816 body = inner_block->statements(); 4813 body = inner_block->statements();
4817 } 4814 }
4818 4815
4819 { 4816 {
4820 BlockState block_state(&scope_, inner_scope); 4817 BlockState block_state(&scope_state_, inner_scope);
4821 4818
4822 if (IsGeneratorFunction(kind)) { 4819 if (IsGeneratorFunction(kind)) {
4823 // We produce: 4820 // We produce:
4824 // 4821 //
4825 // try { InitialYield; ...body...; return {value: undefined, done: true} } 4822 // try { InitialYield; ...body...; return {value: undefined, done: true} }
4826 // finally { %_GeneratorClose(generator) } 4823 // finally { %_GeneratorClose(generator) }
4827 // 4824 //
4828 // - InitialYield yields the actual generator object. 4825 // - InitialYield yields the actual generator object.
4829 // - Any return statement inside the body will have its argument wrapped 4826 // - Any return statement inside the body will have its argument wrapped
4830 // in a "done" iterator result object. 4827 // in a "done" iterator result object.
4831 // - If the generator terminates for whatever reason, we must close it. 4828 // - If the generator terminates for whatever reason, we must close it.
4832 // Hence the finally clause. 4829 // Hence the finally clause.
4833 4830
4834 Block* try_block = 4831 Block* try_block =
4835 factory()->NewBlock(nullptr, 3, false, kNoSourcePosition); 4832 factory()->NewBlock(nullptr, 3, false, kNoSourcePosition);
4836 4833
4837 { 4834 {
4838 Expression* allocation = BuildCreateJSGeneratorObject(pos, kind); 4835 Expression* allocation = BuildCreateJSGeneratorObject(pos, kind);
4839 VariableProxy* init_proxy = factory()->NewVariableProxy( 4836 VariableProxy* init_proxy = factory()->NewVariableProxy(
4840 function_state_->generator_object_variable()); 4837 function_state_->generator_object_variable());
4841 Assignment* assignment = factory()->NewAssignment( 4838 Assignment* assignment = factory()->NewAssignment(
4842 Token::INIT, init_proxy, allocation, kNoSourcePosition); 4839 Token::INIT, init_proxy, allocation, kNoSourcePosition);
4843 VariableProxy* get_proxy = factory()->NewVariableProxy( 4840 VariableProxy* get_proxy = factory()->NewVariableProxy(
4844 function_state_->generator_object_variable()); 4841 function_state_->generator_object_variable());
4845 // The position of the yield is important for reporting the exception 4842 // The position of the yield is important for reporting the exception
4846 // caused by calling the .throw method on a generator suspended at the 4843 // caused by calling the .throw method on a generator suspended at the
4847 // initial yield (i.e. right after generator instantiation). 4844 // initial yield (i.e. right after generator instantiation).
4848 Yield* yield = 4845 Yield* yield = factory()->NewYield(get_proxy, assignment,
4849 factory()->NewYield(get_proxy, assignment, scope_->start_position(), 4846 scope()->start_position(),
4850 Yield::kOnExceptionThrow); 4847 Yield::kOnExceptionThrow);
4851 try_block->statements()->Add( 4848 try_block->statements()->Add(
4852 factory()->NewExpressionStatement(yield, kNoSourcePosition), 4849 factory()->NewExpressionStatement(yield, kNoSourcePosition),
4853 zone()); 4850 zone());
4854 } 4851 }
4855 4852
4856 ParseStatementList(try_block->statements(), Token::RBRACE, CHECK_OK); 4853 ParseStatementList(try_block->statements(), Token::RBRACE, CHECK_OK);
4857 4854
4858 Statement* final_return = factory()->NewReturnStatement( 4855 Statement* final_return = factory()->NewReturnStatement(
4859 BuildIteratorResult(nullptr, true), kNoSourcePosition); 4856 BuildIteratorResult(nullptr, true), kNoSourcePosition);
4860 try_block->statements()->Add(final_return, zone()); 4857 try_block->statements()->Add(final_return, zone());
(...skipping 16 matching lines...) Expand all
4877 } else if (IsAsyncFunction(kind)) { 4874 } else if (IsAsyncFunction(kind)) {
4878 const bool accept_IN = true; 4875 const bool accept_IN = true;
4879 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, 4876 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind,
4880 FunctionBody::Normal, accept_IN, pos, CHECK_OK); 4877 FunctionBody::Normal, accept_IN, pos, CHECK_OK);
4881 } else { 4878 } else {
4882 ParseStatementList(body, Token::RBRACE, CHECK_OK); 4879 ParseStatementList(body, Token::RBRACE, CHECK_OK);
4883 } 4880 }
4884 4881
4885 if (IsSubclassConstructor(kind)) { 4882 if (IsSubclassConstructor(kind)) {
4886 body->Add(factory()->NewReturnStatement( 4883 body->Add(factory()->NewReturnStatement(
4887 this->ThisExpression(scope_, factory(), kNoSourcePosition), 4884 this->ThisExpression(scope(), factory(), kNoSourcePosition),
4888 kNoSourcePosition), 4885 kNoSourcePosition),
4889 zone()); 4886 zone());
4890 } 4887 }
4891 } 4888 }
4892 4889
4893 Expect(Token::RBRACE, CHECK_OK); 4890 Expect(Token::RBRACE, CHECK_OK);
4894 scope_->set_end_position(scanner()->location().end_pos); 4891 scope()->set_end_position(scanner()->location().end_pos);
4895 4892
4896 if (!parameters.is_simple) { 4893 if (!parameters.is_simple) {
4897 DCHECK_NOT_NULL(inner_scope); 4894 DCHECK_NOT_NULL(inner_scope);
4898 DCHECK_EQ(body, inner_block->statements()); 4895 DCHECK_EQ(body, inner_block->statements());
4899 SetLanguageMode(scope_, inner_scope->language_mode()); 4896 SetLanguageMode(scope(), inner_scope->language_mode());
4900 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); 4897 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK);
4901 4898
4902 if (is_sloppy(inner_scope->language_mode())) { 4899 if (is_sloppy(inner_scope->language_mode())) {
4903 InsertSloppyBlockFunctionVarBindings( 4900 InsertSloppyBlockFunctionVarBindings(
4904 inner_scope, inner_scope->outer_scope(), CHECK_OK); 4901 inner_scope, inner_scope->outer_scope(), CHECK_OK);
4905 } 4902 }
4906 4903
4907 if (IsAsyncFunction(kind)) { 4904 if (IsAsyncFunction(kind)) {
4908 init_block = BuildRejectPromiseOnException(init_block); 4905 init_block = BuildRejectPromiseOnException(init_block);
4909 } 4906 }
(...skipping 16 matching lines...) Expand all
4926 } 4923 }
4927 4924
4928 if (function_type == FunctionLiteral::kNamedExpression) { 4925 if (function_type == FunctionLiteral::kNamedExpression) {
4929 // Now that we know the language mode, we can create the const assignment 4926 // Now that we know the language mode, we can create the const assignment
4930 // in the previously reserved spot. 4927 // in the previously reserved spot.
4931 // NOTE: We create a proxy and resolve it here so that in the 4928 // NOTE: We create a proxy and resolve it here so that in the
4932 // future we can change the AST to only refer to VariableProxies 4929 // future we can change the AST to only refer to VariableProxies
4933 // instead of Variables and Proxies as is the case now. 4930 // instead of Variables and Proxies as is the case now.
4934 VariableMode fvar_mode = is_strict(language_mode()) ? CONST : CONST_LEGACY; 4931 VariableMode fvar_mode = is_strict(language_mode()) ? CONST : CONST_LEGACY;
4935 Variable* fvar = new (zone()) 4932 Variable* fvar = new (zone())
4936 Variable(scope_, function_name, fvar_mode, Variable::NORMAL, 4933 Variable(scope(), function_name, fvar_mode, Variable::NORMAL,
4937 kCreatedInitialized, kNotAssigned); 4934 kCreatedInitialized, kNotAssigned);
4938 VariableProxy* proxy = factory()->NewVariableProxy(fvar); 4935 VariableProxy* proxy = factory()->NewVariableProxy(fvar);
4939 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration( 4936 VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
4940 proxy, fvar_mode, scope_, kNoSourcePosition); 4937 proxy, fvar_mode, scope(), kNoSourcePosition);
4941 scope_->DeclareFunctionVar(fvar_declaration); 4938 scope()->DeclareFunctionVar(fvar_declaration);
4942 4939
4943 VariableProxy* fproxy = factory()->NewVariableProxy(fvar); 4940 VariableProxy* fproxy = factory()->NewVariableProxy(fvar);
4944 result->Set(kFunctionNameAssignmentIndex, 4941 result->Set(kFunctionNameAssignmentIndex,
4945 factory()->NewExpressionStatement( 4942 factory()->NewExpressionStatement(
4946 factory()->NewAssignment(Token::INIT, fproxy, 4943 factory()->NewAssignment(Token::INIT, fproxy,
4947 factory()->NewThisFunction(pos), 4944 factory()->NewThisFunction(pos),
4948 kNoSourcePosition), 4945 kNoSourcePosition),
4949 kNoSourcePosition)); 4946 kNoSourcePosition));
4950 } 4947 }
4951 4948
(...skipping 22 matching lines...) Expand all
4974 SET_ALLOW(harmony_do_expressions); 4971 SET_ALLOW(harmony_do_expressions);
4975 SET_ALLOW(harmony_for_in); 4972 SET_ALLOW(harmony_for_in);
4976 SET_ALLOW(harmony_function_sent); 4973 SET_ALLOW(harmony_function_sent);
4977 SET_ALLOW(harmony_exponentiation_operator); 4974 SET_ALLOW(harmony_exponentiation_operator);
4978 SET_ALLOW(harmony_restrictive_declarations); 4975 SET_ALLOW(harmony_restrictive_declarations);
4979 SET_ALLOW(harmony_async_await); 4976 SET_ALLOW(harmony_async_await);
4980 SET_ALLOW(harmony_trailing_commas); 4977 SET_ALLOW(harmony_trailing_commas);
4981 #undef SET_ALLOW 4978 #undef SET_ALLOW
4982 } 4979 }
4983 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4980 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4984 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), 4981 language_mode(), function_state_->kind(),
4985 parsing_module_, logger, bookmark, use_counts_); 4982 scope()->has_simple_parameters(), parsing_module_, logger, bookmark,
4983 use_counts_);
4986 if (pre_parse_timer_ != NULL) { 4984 if (pre_parse_timer_ != NULL) {
4987 pre_parse_timer_->Stop(); 4985 pre_parse_timer_->Stop();
4988 } 4986 }
4989 return result; 4987 return result;
4990 } 4988 }
4991 4989
4992 ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, 4990 ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
4993 const AstRawString* name, 4991 const AstRawString* name,
4994 Scanner::Location class_name_location, 4992 Scanner::Location class_name_location,
4995 bool name_is_strict_reserved, int pos, 4993 bool name_is_strict_reserved, int pos,
4996 bool* ok) { 4994 bool* ok) {
4997 // All parts of a ClassDeclaration and ClassExpression are strict code. 4995 // All parts of a ClassDeclaration and ClassExpression are strict code.
4998 if (name_is_strict_reserved) { 4996 if (name_is_strict_reserved) {
4999 ReportMessageAt(class_name_location, 4997 ReportMessageAt(class_name_location,
5000 MessageTemplate::kUnexpectedStrictReserved); 4998 MessageTemplate::kUnexpectedStrictReserved);
5001 *ok = false; 4999 *ok = false;
5002 return NULL; 5000 return NULL;
5003 } 5001 }
5004 if (IsEvalOrArguments(name)) { 5002 if (IsEvalOrArguments(name)) {
5005 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); 5003 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments);
5006 *ok = false; 5004 *ok = false;
5007 return NULL; 5005 return NULL;
5008 } 5006 }
5009 5007
5010 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 5008 Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
5011 BlockState block_state(&scope_, block_scope); 5009 BlockState block_state(&scope_state_, block_scope);
5012 RaiseLanguageMode(STRICT); 5010 RaiseLanguageMode(STRICT);
5013 scope_->SetScopeName(name); 5011 scope()->SetScopeName(name);
5014 5012
5015 VariableProxy* proxy = NULL; 5013 VariableProxy* proxy = NULL;
5016 if (name != NULL) { 5014 if (name != NULL) {
5017 proxy = NewUnresolved(name, CONST); 5015 proxy = NewUnresolved(name, CONST);
5018 Declaration* declaration = 5016 Declaration* declaration =
5019 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); 5017 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos);
5020 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 5018 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
5021 } 5019 }
5022 5020
5023 Expression* extends = NULL; 5021 Expression* extends = NULL;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
5111 Scanner::Location spread_pos; 5109 Scanner::Location spread_pos;
5112 ExpressionClassifier classifier(this); 5110 ExpressionClassifier classifier(this);
5113 ZoneList<Expression*>* args = 5111 ZoneList<Expression*>* args =
5114 ParseArguments(&spread_pos, &classifier, CHECK_OK); 5112 ParseArguments(&spread_pos, &classifier, CHECK_OK);
5115 5113
5116 DCHECK(!spread_pos.IsValid()); 5114 DCHECK(!spread_pos.IsValid());
5117 5115
5118 if (extension_ != NULL) { 5116 if (extension_ != NULL) {
5119 // The extension structures are only accessible while parsing the 5117 // The extension structures are only accessible while parsing the
5120 // very first time not when reparsing because of lazy compilation. 5118 // very first time not when reparsing because of lazy compilation.
5121 scope_->DeclarationScope()->ForceEagerCompilation(); 5119 scope()->DeclarationScope()->ForceEagerCompilation();
5122 } 5120 }
5123 5121
5124 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 5122 const Runtime::Function* function = Runtime::FunctionForName(name->string());
5125 5123
5126 if (function != NULL) { 5124 if (function != NULL) {
5127 // Check for possible name clash. 5125 // Check for possible name clash.
5128 DCHECK_EQ(Context::kNotFound, 5126 DCHECK_EQ(Context::kNotFound,
5129 Context::IntrinsicIndexForName(name->string())); 5127 Context::IntrinsicIndexForName(name->string()));
5130 // Check for built-in IS_VAR macro. 5128 // Check for built-in IS_VAR macro.
5131 if (function->function_id == Runtime::kIS_VAR) { 5129 if (function->function_id == Runtime::kIS_VAR) {
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
5659 Expression* super_constructor = factory()->NewCallRuntime( 5657 Expression* super_constructor = factory()->NewCallRuntime(
5660 Runtime::kInlineGetSuperConstructor, tmp, pos); 5658 Runtime::kInlineGetSuperConstructor, tmp, pos);
5661 args->InsertAt(0, super_constructor, zone()); 5659 args->InsertAt(0, super_constructor, zone());
5662 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); 5660 args->Add(function->AsSuperCallReference()->new_target_var(), zone());
5663 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, 5661 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args,
5664 pos); 5662 pos);
5665 } else { 5663 } else {
5666 if (function->IsProperty()) { 5664 if (function->IsProperty()) {
5667 // Method calls 5665 // Method calls
5668 if (function->AsProperty()->IsSuperAccess()) { 5666 if (function->AsProperty()->IsSuperAccess()) {
5669 Expression* home = ThisExpression(scope_, factory(), kNoSourcePosition); 5667 Expression* home =
5668 ThisExpression(scope(), factory(), kNoSourcePosition);
5670 args->InsertAt(0, function, zone()); 5669 args->InsertAt(0, function, zone());
5671 args->InsertAt(1, home, zone()); 5670 args->InsertAt(1, home, zone());
5672 } else { 5671 } else {
5673 Variable* temp = 5672 Variable* temp =
5674 scope_->NewTemporary(ast_value_factory()->empty_string()); 5673 scope()->NewTemporary(ast_value_factory()->empty_string());
5675 VariableProxy* obj = factory()->NewVariableProxy(temp); 5674 VariableProxy* obj = factory()->NewVariableProxy(temp);
5676 Assignment* assign_obj = factory()->NewAssignment( 5675 Assignment* assign_obj = factory()->NewAssignment(
5677 Token::ASSIGN, obj, function->AsProperty()->obj(), 5676 Token::ASSIGN, obj, function->AsProperty()->obj(),
5678 kNoSourcePosition); 5677 kNoSourcePosition);
5679 function = factory()->NewProperty( 5678 function = factory()->NewProperty(
5680 assign_obj, function->AsProperty()->key(), kNoSourcePosition); 5679 assign_obj, function->AsProperty()->key(), kNoSourcePosition);
5681 args->InsertAt(0, function, zone()); 5680 args->InsertAt(0, function, zone());
5682 obj = factory()->NewVariableProxy(temp); 5681 obj = factory()->NewVariableProxy(temp);
5683 args->InsertAt(1, obj, zone()); 5682 args->InsertAt(1, obj, zone());
5684 } 5683 }
(...skipping 24 matching lines...) Expand all
5709 else if (is_strict(mode)) 5708 else if (is_strict(mode))
5710 feature = v8::Isolate::kStrictMode; 5709 feature = v8::Isolate::kStrictMode;
5711 else 5710 else
5712 UNREACHABLE(); 5711 UNREACHABLE();
5713 ++use_counts_[feature]; 5712 ++use_counts_[feature];
5714 scope->SetLanguageMode(mode); 5713 scope->SetLanguageMode(mode);
5715 } 5714 }
5716 5715
5717 5716
5718 void Parser::RaiseLanguageMode(LanguageMode mode) { 5717 void Parser::RaiseLanguageMode(LanguageMode mode) {
5719 LanguageMode old = scope_->language_mode(); 5718 LanguageMode old = scope()->language_mode();
5720 SetLanguageMode(scope_, old > mode ? old : mode); 5719 SetLanguageMode(scope(), old > mode ? old : mode);
5721 } 5720 }
5722 5721
5723 void Parser::MarkCollectedTailCallExpressions() { 5722 void Parser::MarkCollectedTailCallExpressions() {
5724 const ZoneList<Expression*>& tail_call_expressions = 5723 const ZoneList<Expression*>& tail_call_expressions =
5725 function_state_->tail_call_expressions().expressions(); 5724 function_state_->tail_call_expressions().expressions();
5726 for (int i = 0; i < tail_call_expressions.length(); ++i) { 5725 for (int i = 0; i < tail_call_expressions.length(); ++i) {
5727 Expression* expression = tail_call_expressions[i]; 5726 Expression* expression = tail_call_expressions[i];
5728 // If only FLAG_harmony_explicit_tailcalls is enabled then expression 5727 // If only FLAG_harmony_explicit_tailcalls is enabled then expression
5729 // must be a Call expression. 5728 // must be a Call expression.
5730 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls || 5729 DCHECK(FLAG_harmony_tailcalls || !FLAG_harmony_explicit_tailcalls ||
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
5769 // yield %AsyncFunctionAwait(.generator_object, <operand>) 5768 // yield %AsyncFunctionAwait(.generator_object, <operand>)
5770 Variable* generator_object_variable = 5769 Variable* generator_object_variable =
5771 parser_->function_state_->generator_object_variable(); 5770 parser_->function_state_->generator_object_variable();
5772 5771
5773 // If generator_object_variable is null, 5772 // If generator_object_variable is null,
5774 if (!generator_object_variable) return value; 5773 if (!generator_object_variable) return value;
5775 5774
5776 auto factory = parser_->factory(); 5775 auto factory = parser_->factory();
5777 const int nopos = kNoSourcePosition; 5776 const int nopos = kNoSourcePosition;
5778 5777
5779 Variable* temp_var = parser_->scope_->NewTemporary( 5778 Variable* temp_var = parser_->scope()->NewTemporary(
5780 parser_->ast_value_factory()->empty_string()); 5779 parser_->ast_value_factory()->empty_string());
5781 VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var); 5780 VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var);
5782 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); 5781 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos);
5783 5782
5784 // Wrap value evaluation to provide a break location. 5783 // Wrap value evaluation to provide a break location.
5785 Expression* value_assignment = 5784 Expression* value_assignment =
5786 factory->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos); 5785 factory->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos);
5787 do_block->statements()->Add( 5786 do_block->statements()->Add(
5788 factory->NewExpressionStatement(value_assignment, value->position()), 5787 factory->NewExpressionStatement(value_assignment, value->position()),
5789 zone()); 5788 zone());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
5906 Expression* Parser::RewriteAssignExponentiation(Expression* left, 5905 Expression* Parser::RewriteAssignExponentiation(Expression* left,
5907 Expression* right, int pos) { 5906 Expression* right, int pos) {
5908 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); 5907 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone());
5909 if (left->IsVariableProxy()) { 5908 if (left->IsVariableProxy()) {
5910 VariableProxy* lhs = left->AsVariableProxy(); 5909 VariableProxy* lhs = left->AsVariableProxy();
5911 5910
5912 Expression* result; 5911 Expression* result;
5913 DCHECK_NOT_NULL(lhs->raw_name()); 5912 DCHECK_NOT_NULL(lhs->raw_name());
5914 result = 5913 result =
5915 this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(), 5914 this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(),
5916 lhs->end_position(), scope_, factory()); 5915 lhs->end_position(), scope(), factory());
5917 args->Add(left, zone()); 5916 args->Add(left, zone());
5918 args->Add(right, zone()); 5917 args->Add(right, zone());
5919 Expression* call = 5918 Expression* call =
5920 factory()->NewCallRuntime(Context::MATH_POW_INDEX, args, pos); 5919 factory()->NewCallRuntime(Context::MATH_POW_INDEX, args, pos);
5921 return factory()->NewAssignment(Token::ASSIGN, result, call, pos); 5920 return factory()->NewAssignment(Token::ASSIGN, result, call, pos);
5922 } else if (left->IsProperty()) { 5921 } else if (left->IsProperty()) {
5923 Property* prop = left->AsProperty(); 5922 Property* prop = left->AsProperty();
5924 auto temp_obj = scope_->NewTemporary(ast_value_factory()->empty_string()); 5923 auto temp_obj = scope()->NewTemporary(ast_value_factory()->empty_string());
5925 auto temp_key = scope_->NewTemporary(ast_value_factory()->empty_string()); 5924 auto temp_key = scope()->NewTemporary(ast_value_factory()->empty_string());
5926 Expression* assign_obj = factory()->NewAssignment( 5925 Expression* assign_obj = factory()->NewAssignment(
5927 Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(), 5926 Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(),
5928 kNoSourcePosition); 5927 kNoSourcePosition);
5929 Expression* assign_key = factory()->NewAssignment( 5928 Expression* assign_key = factory()->NewAssignment(
5930 Token::ASSIGN, factory()->NewVariableProxy(temp_key), prop->key(), 5929 Token::ASSIGN, factory()->NewVariableProxy(temp_key), prop->key(),
5931 kNoSourcePosition); 5930 kNoSourcePosition);
5932 args->Add(factory()->NewProperty(factory()->NewVariableProxy(temp_obj), 5931 args->Add(factory()->NewProperty(factory()->NewVariableProxy(temp_obj),
5933 factory()->NewVariableProxy(temp_key), 5932 factory()->NewVariableProxy(temp_key),
5934 left->position()), 5933 left->position()),
5935 zone()); 5934 zone());
(...skipping 23 matching lines...) Expand all
5959 // for ($i of x) %AppendElement($R, $i); 5958 // for ($i of x) %AppendElement($R, $i);
5960 // %AppendElement($R, 4); 5959 // %AppendElement($R, 4);
5961 // for ($j of y) %AppendElement($R, $j); 5960 // for ($j of y) %AppendElement($R, $j);
5962 // %AppendElement($R, 5); 5961 // %AppendElement($R, 5);
5963 // $R 5962 // $R
5964 // } 5963 // }
5965 // where $R, $i and $j are fresh temporary variables. 5964 // where $R, $i and $j are fresh temporary variables.
5966 ZoneList<Expression*>::iterator s = lit->FirstSpread(); 5965 ZoneList<Expression*>::iterator s = lit->FirstSpread();
5967 if (s == lit->EndValue()) return nullptr; // no spread, no rewriting... 5966 if (s == lit->EndValue()) return nullptr; // no spread, no rewriting...
5968 Variable* result = 5967 Variable* result =
5969 scope_->NewTemporary(ast_value_factory()->dot_result_string()); 5968 scope()->NewTemporary(ast_value_factory()->dot_result_string());
5970 // NOTE: The value assigned to R is the whole original array literal, 5969 // NOTE: The value assigned to R is the whole original array literal,
5971 // spreads included. This will be fixed before the rewritten AST is returned. 5970 // spreads included. This will be fixed before the rewritten AST is returned.
5972 // $R = lit 5971 // $R = lit
5973 Expression* init_result = factory()->NewAssignment( 5972 Expression* init_result = factory()->NewAssignment(
5974 Token::INIT, factory()->NewVariableProxy(result), lit, kNoSourcePosition); 5973 Token::INIT, factory()->NewVariableProxy(result), lit, kNoSourcePosition);
5975 Block* do_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition); 5974 Block* do_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
5976 do_block->statements()->Add( 5975 do_block->statements()->Add(
5977 factory()->NewExpressionStatement(init_result, kNoSourcePosition), 5976 factory()->NewExpressionStatement(init_result, kNoSourcePosition),
5978 zone()); 5977 zone());
5979 // Traverse the array literal starting from the first spread. 5978 // Traverse the array literal starting from the first spread.
5980 while (s != lit->EndValue()) { 5979 while (s != lit->EndValue()) {
5981 Expression* value = *s++; 5980 Expression* value = *s++;
5982 Spread* spread = value->AsSpread(); 5981 Spread* spread = value->AsSpread();
5983 if (spread == nullptr) { 5982 if (spread == nullptr) {
5984 // If the element is not a spread, we're adding a single: 5983 // If the element is not a spread, we're adding a single:
5985 // %AppendElement($R, value) 5984 // %AppendElement($R, value)
5986 ZoneList<Expression*>* append_element_args = NewExpressionList(2, zone()); 5985 ZoneList<Expression*>* append_element_args = NewExpressionList(2, zone());
5987 append_element_args->Add(factory()->NewVariableProxy(result), zone()); 5986 append_element_args->Add(factory()->NewVariableProxy(result), zone());
5988 append_element_args->Add(value, zone()); 5987 append_element_args->Add(value, zone());
5989 do_block->statements()->Add( 5988 do_block->statements()->Add(
5990 factory()->NewExpressionStatement( 5989 factory()->NewExpressionStatement(
5991 factory()->NewCallRuntime(Runtime::kAppendElement, 5990 factory()->NewCallRuntime(Runtime::kAppendElement,
5992 append_element_args, kNoSourcePosition), 5991 append_element_args, kNoSourcePosition),
5993 kNoSourcePosition), 5992 kNoSourcePosition),
5994 zone()); 5993 zone());
5995 } else { 5994 } else {
5996 // If it's a spread, we're adding a for/of loop iterating through it. 5995 // If it's a spread, we're adding a for/of loop iterating through it.
5997 Variable* each = 5996 Variable* each =
5998 scope_->NewTemporary(ast_value_factory()->dot_for_string()); 5997 scope()->NewTemporary(ast_value_factory()->dot_for_string());
5999 Expression* subject = spread->expression(); 5998 Expression* subject = spread->expression();
6000 // %AppendElement($R, each) 5999 // %AppendElement($R, each)
6001 Statement* append_body; 6000 Statement* append_body;
6002 { 6001 {
6003 ZoneList<Expression*>* append_element_args = 6002 ZoneList<Expression*>* append_element_args =
6004 NewExpressionList(2, zone()); 6003 NewExpressionList(2, zone());
6005 append_element_args->Add(factory()->NewVariableProxy(result), zone()); 6004 append_element_args->Add(factory()->NewVariableProxy(result), zone());
6006 append_element_args->Add(factory()->NewVariableProxy(each), zone()); 6005 append_element_args->Add(factory()->NewVariableProxy(each), zone());
6007 append_body = factory()->NewExpressionStatement( 6006 append_body = factory()->NewExpressionStatement(
6008 factory()->NewCallRuntime(Runtime::kAppendElement, 6007 factory()->NewCallRuntime(Runtime::kAppendElement,
(...skipping 13 matching lines...) Expand all
6022 // Now, rewind the original array literal to truncate everything from the 6021 // Now, rewind the original array literal to truncate everything from the
6023 // first spread (included) until the end. This fixes $R's initialization. 6022 // first spread (included) until the end. This fixes $R's initialization.
6024 lit->RewindSpreads(); 6023 lit->RewindSpreads();
6025 return factory()->NewDoExpression(do_block, result, lit->position()); 6024 return factory()->NewDoExpression(do_block, result, lit->position());
6026 } 6025 }
6027 6026
6028 6027
6029 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { 6028 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) {
6030 DCHECK(expr->IsRewritableExpression()); 6029 DCHECK(expr->IsRewritableExpression());
6031 parser_->function_state_->AddDestructuringAssignment( 6030 parser_->function_state_->AddDestructuringAssignment(
6032 Parser::DestructuringAssignment(expr, parser_->scope_)); 6031 Parser::DestructuringAssignment(expr, parser_->scope()));
6033 } 6032 }
6034 6033
6035 6034
6036 void ParserTraits::QueueNonPatternForRewriting(Expression* expr, bool* ok) { 6035 void ParserTraits::QueueNonPatternForRewriting(Expression* expr, bool* ok) {
6037 DCHECK(expr->IsRewritableExpression()); 6036 DCHECK(expr->IsRewritableExpression());
6038 parser_->function_state_->AddNonPatternForRewriting(expr, ok); 6037 parser_->function_state_->AddNonPatternForRewriting(expr, ok);
6039 } 6038 }
6040 6039
6041 6040
6042 void ParserTraits::SetFunctionNameFromPropertyName( 6041 void ParserTraits::SetFunctionNameFromPropertyName(
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
6173 // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return input; 6172 // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return input;
6174 // output = %_Call(iteratorReturn, iterator, input); 6173 // output = %_Call(iteratorReturn, iterator, input);
6175 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); 6174 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
6176 6175
6177 Expression* ParserTraits::RewriteYieldStar( 6176 Expression* ParserTraits::RewriteYieldStar(
6178 Expression* generator, Expression* iterable, int pos) { 6177 Expression* generator, Expression* iterable, int pos) {
6179 const int nopos = kNoSourcePosition; 6178 const int nopos = kNoSourcePosition;
6180 6179
6181 auto factory = parser_->factory(); 6180 auto factory = parser_->factory();
6182 auto avfactory = parser_->ast_value_factory(); 6181 auto avfactory = parser_->ast_value_factory();
6183 auto scope = parser_->scope_; 6182 auto scope = parser_->scope();
6184 auto zone = parser_->zone(); 6183 auto zone = parser_->zone();
6185 6184
6186 6185
6187 // Forward definition for break/continue statements. 6186 // Forward definition for break/continue statements.
6188 WhileStatement* loop = factory->NewWhileStatement(nullptr, nopos); 6187 WhileStatement* loop = factory->NewWhileStatement(nullptr, nopos);
6189 6188
6190 6189
6191 // let input = undefined; 6190 // let input = undefined;
6192 Variable* var_input = scope->NewTemporary(avfactory->empty_string()); 6191 Variable* var_input = scope->NewTemporary(avfactory->empty_string());
6193 Statement* initialize_input; 6192 Statement* initialize_input;
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
6738 // } finally { 6737 // } finally {
6739 // if (condition) { 6738 // if (condition) {
6740 // #BuildIteratorCloseForCompletion(iter, completion) 6739 // #BuildIteratorCloseForCompletion(iter, completion)
6741 // } 6740 // }
6742 // } 6741 // }
6743 // 6742 //
6744 6743
6745 const int nopos = kNoSourcePosition; 6744 const int nopos = kNoSourcePosition;
6746 auto factory = parser_->factory(); 6745 auto factory = parser_->factory();
6747 auto avfactory = parser_->ast_value_factory(); 6746 auto avfactory = parser_->ast_value_factory();
6748 auto scope = parser_->scope_; 6747 auto scope = parser_->scope();
6749 auto zone = parser_->zone(); 6748 auto zone = parser_->zone();
6750 6749
6751 // completion = kNormalCompletion; 6750 // completion = kNormalCompletion;
6752 Statement* initialize_completion; 6751 Statement* initialize_completion;
6753 { 6752 {
6754 Expression* proxy = factory->NewVariableProxy(completion); 6753 Expression* proxy = factory->NewVariableProxy(completion);
6755 Expression* assignment = factory->NewAssignment( 6754 Expression* assignment = factory->NewAssignment(
6756 Token::ASSIGN, proxy, 6755 Token::ASSIGN, proxy,
6757 factory->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos); 6756 factory->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos);
6758 initialize_completion = factory->NewExpressionStatement(assignment, nopos); 6757 initialize_completion = factory->NewExpressionStatement(assignment, nopos);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
6857 // if (!IS_RECEIVER(output)) { 6856 // if (!IS_RECEIVER(output)) {
6858 // %ThrowIterResultNotAnObject(output); 6857 // %ThrowIterResultNotAnObject(output);
6859 // } 6858 // }
6860 // } 6859 // }
6861 // } 6860 // }
6862 // 6861 //
6863 6862
6864 const int nopos = kNoSourcePosition; 6863 const int nopos = kNoSourcePosition;
6865 auto factory = parser_->factory(); 6864 auto factory = parser_->factory();
6866 auto avfactory = parser_->ast_value_factory(); 6865 auto avfactory = parser_->ast_value_factory();
6867 auto scope = parser_->scope_; 6866 auto scope = parser_->scope();
6868 auto zone = parser_->zone(); 6867 auto zone = parser_->zone();
6869 6868
6870 6869
6871 // let iteratorReturn = iterator.return; 6870 // let iteratorReturn = iterator.return;
6872 Variable* var_return = scope->NewTemporary(avfactory->empty_string()); 6871 Variable* var_return = scope->NewTemporary(avfactory->empty_string());
6873 Statement* get_return; 6872 Statement* get_return;
6874 { 6873 {
6875 Expression* iterator_proxy = factory->NewVariableProxy(iterator); 6874 Expression* iterator_proxy = factory->NewVariableProxy(iterator);
6876 Expression* literal = 6875 Expression* literal =
6877 factory->NewStringLiteral(avfactory->return_string(), nopos); 6876 factory->NewStringLiteral(avfactory->return_string(), nopos);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
7063 node->Print(Isolate::Current()); 7062 node->Print(Isolate::Current());
7064 } 7063 }
7065 #endif // DEBUG 7064 #endif // DEBUG
7066 7065
7067 #undef CHECK_OK 7066 #undef CHECK_OK
7068 #undef CHECK_OK_CUSTOM 7067 #undef CHECK_OK_CUSTOM
7069 #undef CHECK_FAILED 7068 #undef CHECK_FAILED
7070 7069
7071 } // namespace internal 7070 } // namespace internal
7072 } // namespace v8 7071 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698