| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 // via ParseInfo, and also not pass it forward. | 981 // via ParseInfo, and also not pass it forward. |
| 982 DCHECK_NULL(scope_state_); | 982 DCHECK_NULL(scope_state_); |
| 983 DCHECK_NULL(target_stack_); | 983 DCHECK_NULL(target_stack_); |
| 984 | 984 |
| 985 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; | 985 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; |
| 986 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; | 986 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; |
| 987 | 987 |
| 988 FunctionLiteral* result = NULL; | 988 FunctionLiteral* result = NULL; |
| 989 { | 989 { |
| 990 Scope* outer = original_scope_; | 990 Scope* outer = original_scope_; |
| 991 // If there's a chance that there's a reference to global 'this', predeclare |
| 992 // it as a dynamic global on the script scope. |
| 993 if (outer->GetReceiverScope()->is_script_scope()) { |
| 994 info->script_scope()->DeclareDynamicGlobal( |
| 995 ast_value_factory()->this_string(), Variable::THIS); |
| 996 } |
| 991 DCHECK(outer); | 997 DCHECK(outer); |
| 992 if (info->is_eval()) { | 998 if (info->is_eval()) { |
| 993 if (!outer->is_script_scope() || is_strict(info->language_mode())) { | 999 if (!outer->is_script_scope() || is_strict(info->language_mode())) { |
| 994 parsing_mode = PARSE_EAGERLY; | 1000 parsing_mode = PARSE_EAGERLY; |
| 995 } | 1001 } |
| 996 outer = NewEvalScope(outer); | 1002 outer = NewEvalScope(outer); |
| 997 } else if (info->is_module()) { | 1003 } else if (info->is_module()) { |
| 998 outer = NewModuleScope(outer); | 1004 outer = NewModuleScope(outer); |
| 999 } | 1005 } |
| 1000 | 1006 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 | 1151 |
| 1146 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1152 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| 1147 | 1153 |
| 1148 // Place holder for the result. | 1154 // Place holder for the result. |
| 1149 FunctionLiteral* result = nullptr; | 1155 FunctionLiteral* result = nullptr; |
| 1150 | 1156 |
| 1151 { | 1157 { |
| 1152 // Parse the function literal. | 1158 // Parse the function literal. |
| 1153 Scope* scope = original_scope_; | 1159 Scope* scope = original_scope_; |
| 1154 DCHECK(scope); | 1160 DCHECK(scope); |
| 1161 // If there's a chance that there's a reference to global 'this', predeclare |
| 1162 // it as a dynamic global on the script scope. |
| 1163 if (info->is_arrow() && scope->GetReceiverScope()->is_script_scope()) { |
| 1164 info->script_scope()->DeclareDynamicGlobal( |
| 1165 ast_value_factory()->this_string(), Variable::THIS); |
| 1166 } |
| 1155 FunctionState function_state(&function_state_, &scope_state_, scope, | 1167 FunctionState function_state(&function_state_, &scope_state_, scope, |
| 1156 info->function_kind()); | 1168 info->function_kind()); |
| 1157 DCHECK(is_sloppy(scope->language_mode()) || | 1169 DCHECK(is_sloppy(scope->language_mode()) || |
| 1158 is_strict(info->language_mode())); | 1170 is_strict(info->language_mode())); |
| 1159 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); | 1171 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); |
| 1160 bool ok = true; | 1172 bool ok = true; |
| 1161 | 1173 |
| 1162 if (info->is_arrow()) { | 1174 if (info->is_arrow()) { |
| 1163 bool is_async = allow_harmony_async_await() && info->is_async(); | 1175 bool is_async = allow_harmony_async_await() && info->is_async(); |
| 1164 if (is_async) { | 1176 if (is_async) { |
| (...skipping 5905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7070 node->Print(Isolate::Current()); | 7082 node->Print(Isolate::Current()); |
| 7071 } | 7083 } |
| 7072 #endif // DEBUG | 7084 #endif // DEBUG |
| 7073 | 7085 |
| 7074 #undef CHECK_OK | 7086 #undef CHECK_OK |
| 7075 #undef CHECK_OK_VOID | 7087 #undef CHECK_OK_VOID |
| 7076 #undef CHECK_FAILED | 7088 #undef CHECK_FAILED |
| 7077 | 7089 |
| 7078 } // namespace internal | 7090 } // namespace internal |
| 7079 } // namespace v8 | 7091 } // namespace v8 |
| OLD | NEW |