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

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

Issue 2237873002: Declare 'this' as DYNAMIC_GLOBAL on the script_scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix places where we declare this, remove shortcut Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 // via ParseInfo, and also not pass it forward. 991 // via ParseInfo, and also not pass it forward.
992 DCHECK_NULL(scope_state_); 992 DCHECK_NULL(scope_state_);
993 DCHECK_NULL(target_stack_); 993 DCHECK_NULL(target_stack_);
994 994
995 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; 995 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY;
996 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; 996 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY;
997 997
998 FunctionLiteral* result = NULL; 998 FunctionLiteral* result = NULL;
999 { 999 {
1000 Scope* outer = original_scope_; 1000 Scope* outer = original_scope_;
1001 // If there's a chance that there's a reference to global 'this', predeclare
adamk 2016/08/11 18:27:17 What does the "If there's a chance" add to this co
Toon Verwaest 2016/08/12 04:49:40 How would you reformulate? I'm just trying to indi
adamk 2016/08/15 17:39:43 Makes sense, I missed the fact that the GetReceive
1002 // it as a dynamic global on the script scope.
1003 if (outer->GetReceiverScope()->is_script_scope()) {
1004 info->script_scope()->DeclareDynamicGlobal(
1005 ast_value_factory()->this_string(), Variable::THIS);
1006 }
1001 DCHECK(outer); 1007 DCHECK(outer);
1002 if (info->is_eval()) { 1008 if (info->is_eval()) {
1003 if (!outer->is_script_scope() || is_strict(info->language_mode())) { 1009 if (!outer->is_script_scope() || is_strict(info->language_mode())) {
1004 parsing_mode = PARSE_EAGERLY; 1010 parsing_mode = PARSE_EAGERLY;
1005 } 1011 }
1006 outer = NewEvalScope(outer); 1012 outer = NewEvalScope(outer);
1007 } else if (info->is_module()) { 1013 } else if (info->is_module()) {
1008 outer = NewModuleScope(outer); 1014 outer = NewModuleScope(outer);
1009 } 1015 }
1010 1016
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 1161
1156 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1162 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1157 1163
1158 // Place holder for the result. 1164 // Place holder for the result.
1159 FunctionLiteral* result = nullptr; 1165 FunctionLiteral* result = nullptr;
1160 1166
1161 { 1167 {
1162 // Parse the function literal. 1168 // Parse the function literal.
1163 Scope* scope = original_scope_; 1169 Scope* scope = original_scope_;
1164 DCHECK(scope); 1170 DCHECK(scope);
1171 // If there's a chance that there's a reference to global 'this', predeclare
1172 // it as a dynamic global on the script scope.
1173 if (info->is_arrow() && scope->GetReceiverScope()->is_script_scope()) {
1174 info->script_scope()->DeclareDynamicGlobal(
1175 ast_value_factory()->this_string(), Variable::THIS);
1176 }
1165 FunctionState function_state(&function_state_, &scope_state_, scope, 1177 FunctionState function_state(&function_state_, &scope_state_, scope,
1166 info->function_kind()); 1178 info->function_kind());
1167 DCHECK(is_sloppy(scope->language_mode()) || 1179 DCHECK(is_sloppy(scope->language_mode()) ||
1168 is_strict(info->language_mode())); 1180 is_strict(info->language_mode()));
1169 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); 1181 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info);
1170 bool ok = true; 1182 bool ok = true;
1171 1183
1172 if (info->is_arrow()) { 1184 if (info->is_arrow()) {
1173 bool is_async = allow_harmony_async_await() && info->is_async(); 1185 bool is_async = allow_harmony_async_await() && info->is_async();
1174 if (is_async) { 1186 if (is_async) {
(...skipping 5919 matching lines...) Expand 10 before | Expand all | Expand 10 after
7094 node->Print(Isolate::Current()); 7106 node->Print(Isolate::Current());
7095 } 7107 }
7096 #endif // DEBUG 7108 #endif // DEBUG
7097 7109
7098 #undef CHECK_OK 7110 #undef CHECK_OK
7099 #undef CHECK_OK_VOID 7111 #undef CHECK_OK_VOID
7100 #undef CHECK_FAILED 7112 #undef CHECK_FAILED
7101 7113
7102 } // namespace internal 7114 } // namespace internal
7103 } // namespace v8 7115 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698