Index: src/parsing/parser.cc |
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc |
index 59d31f5a73514fd5c8a7f98d8e4be9146f8f433f..b294e98a4799e70c3c6220a89f87bc90e53e9600 100644 |
--- a/src/parsing/parser.cc |
+++ b/src/parsing/parser.cc |
@@ -998,6 +998,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->GetDeclarationScope()->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())) { |