Commit 92679b02 authored by jochen's avatar jochen Committed by Commit bot

Move pre-declaring the this variable to Scope::Analyze

The goal is to not have to look at the outer scope chain during parsing.

BUG=v8:5215
R=verwaest@chromium.org,marja@chromium.org

Review-Url: https://codereview.chromium.org/2298673002
Cr-Commit-Position: refs/heads/master@{#39042}
parent 998c9285
...@@ -420,6 +420,13 @@ void DeclarationScope::Analyze(ParseInfo* info, AnalyzeMode mode) { ...@@ -420,6 +420,13 @@ void DeclarationScope::Analyze(ParseInfo* info, AnalyzeMode mode) {
scope->outer_scope()->scope_type() == SCRIPT_SCOPE || scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
scope->outer_scope()->already_resolved_); 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); scope->AllocateVariables(info, mode);
#ifdef DEBUG #ifdef DEBUG
......
...@@ -671,12 +671,6 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -671,12 +671,6 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
{ {
Scope* outer = original_scope_; Scope* outer = original_scope_;
DCHECK_NOT_NULL(outer); DCHECK_NOT_NULL(outer);
// 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);
}
if (info->is_eval()) { if (info->is_eval()) {
if (!outer->is_script_scope() || is_strict(info->language_mode())) { if (!outer->is_script_scope() || is_strict(info->language_mode())) {
parsing_mode = PARSE_EAGERLY; parsing_mode = PARSE_EAGERLY;
...@@ -841,12 +835,6 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info, ...@@ -841,12 +835,6 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
// Parse the function literal. // Parse the function literal.
Scope* outer = original_scope_; Scope* outer = original_scope_;
DCHECK(outer); DCHECK(outer);
// 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() && outer->GetReceiverScope()->is_script_scope()) {
info->script_scope()->DeclareDynamicGlobal(
ast_value_factory()->this_string(), Variable::THIS);
}
FunctionState function_state(&function_state_, &scope_state_, outer, FunctionState function_state(&function_state_, &scope_state_, outer,
info->function_kind()); info->function_kind());
DCHECK(is_sloppy(outer->language_mode()) || DCHECK(is_sloppy(outer->language_mode()) ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment