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

Unified 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: Rebase and partly restore for debugger 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 side-by-side diff with in-line comments
Download patch
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 0d16469f3190e582d399752cf5387926922d268a..6db71f8ebcdb669558f5944b452069a8ed166d4d 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -988,6 +988,12 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
FunctionLiteral* result = NULL;
{
Scope* outer = original_scope_;
+ // If there's a chance that there's a reference to global 'this', predeclare
+ // it as a dynamic global on the script scope.
+ if (outer->GetReceiverScope()->is_script_scope()) {
+ info->script_scope()->DeclareDynamicGlobal(
+ ast_value_factory()->this_string(), Variable::THIS);
+ }
DCHECK(outer);
if (info->is_eval()) {
if (!outer->is_script_scope() || is_strict(info->language_mode())) {
@@ -1152,6 +1158,12 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
// Parse the function literal.
Scope* scope = original_scope_;
DCHECK(scope);
+ // If there's a chance that there's a reference to global 'this', predeclare
+ // it as a dynamic global on the script scope.
+ if (info->is_arrow() && scope->GetReceiverScope()->is_script_scope()) {
+ info->script_scope()->DeclareDynamicGlobal(
+ ast_value_factory()->this_string(), Variable::THIS);
+ }
FunctionState function_state(&function_state_, &scope_state_, scope,
info->function_kind());
DCHECK(is_sloppy(scope->language_mode()) ||

Powered by Google App Engine
This is Rietveld 408576698