Index: src/ast/scopes.cc |
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc |
index bbc8155e9bd3f5f54070d480170f6ed4faef91cc..368d3eff6a2e17570e5ac3727e689609e71560ec 100644 |
--- a/src/ast/scopes.cc |
+++ b/src/ast/scopes.cc |
@@ -411,6 +411,13 @@ void DeclarationScope::Analyze(ParseInfo* info, AnalyzeMode mode) { |
scope->outer_scope()->scope_type() == SCRIPT_SCOPE || |
scope->outer_scope()->already_resolved_); |
+ // If there's a chance that there's a reference to global 'this', predeclare |
+ // it as a dynamic global on the script scope. |
+ if (scope->GetReceiverScope()->is_script_scope()) { |
+ info->script_scope()->DeclareDynamicGlobal( |
+ info->ast_value_factory()->this_string(), Variable::THIS); |
+ } |
+ |
scope->AllocateVariables(info, mode); |
#ifdef DEBUG |