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