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

Unified Diff: src/compiler/ast-graph-builder.cc

Issue 1172013002: [turbofan] Fix context chain extension for top-level code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « src/compiler/ast-graph-builder.h ('k') | test/mjsunit/regress/regress-4169.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc
index 7fddc4aafd549a0c00956dd7a891a14703333ee0..9bafb730a867182a385b501e0d98b0161dc15266 100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -453,6 +453,21 @@ AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info,
}
+Node* AstGraphBuilder::GetFunctionClosureForContext() {
+ Scope* declaration_scope = current_scope()->DeclarationScope();
+ if (declaration_scope->is_script_scope() ||
+ declaration_scope->is_module_scope()) {
+ // Contexts nested in the native context have a canonical empty function as
+ // their closure, not the anonymous closure containing the global code.
+ // Pass a SMI sentinel and let the runtime look up the empty function.
+ return jsgraph()->SmiConstant(0);
+ } else {
+ DCHECK(declaration_scope->is_function_scope());
+ return GetFunctionClosure();
+ }
+}
+
+
Node* AstGraphBuilder::GetFunctionClosure() {
if (!function_closure_.is_set()) {
const Operator* op = common()->Parameter(
@@ -1181,7 +1196,7 @@ void AstGraphBuilder::VisitWithStatement(WithStatement* stmt) {
VisitForValue(stmt->expression());
Node* value = environment()->Pop();
const Operator* op = javascript()->CreateWithContext();
- Node* context = NewNode(op, value, GetFunctionClosure());
+ Node* context = NewNode(op, value, GetFunctionClosureForContext());
PrepareFrameState(context, stmt->EntryId());
ContextScope scope(this, stmt->scope(), context);
Visit(stmt->statement());
@@ -1399,7 +1414,7 @@ void AstGraphBuilder::VisitTryCatchStatement(TryCatchStatement* stmt) {
Node* exception = try_control.GetExceptionNode();
Unique<String> name = MakeUnique(stmt->variable()->name());
const Operator* op = javascript()->CreateCatchContext(name);
- Node* context = NewNode(op, exception, GetFunctionClosure());
+ Node* context = NewNode(op, exception, GetFunctionClosureForContext());
PrepareFrameState(context, BailoutId::None());
{
ContextScope scope(this, stmt->scope(), context);
@@ -3054,12 +3069,12 @@ Node* AstGraphBuilder::BuildLocalFunctionContext(Node* context,
Node* AstGraphBuilder::BuildLocalScriptContext(Scope* scope) {
- Node* closure = GetFunctionClosure();
+ DCHECK(scope->is_script_scope());
// Allocate a new local context.
const Operator* op = javascript()->CreateScriptContext();
Node* scope_info = jsgraph()->Constant(scope->GetScopeInfo(isolate()));
- Node* local_context = NewNode(op, closure, scope_info);
+ Node* local_context = NewNode(op, GetFunctionClosure(), scope_info);
PrepareFrameState(local_context, BailoutId::FunctionEntry());
return local_context;
@@ -3067,12 +3082,12 @@ Node* AstGraphBuilder::BuildLocalScriptContext(Scope* scope) {
Node* AstGraphBuilder::BuildLocalBlockContext(Scope* scope) {
- Node* closure = GetFunctionClosure();
+ DCHECK(scope->is_block_scope());
// Allocate a new local context.
const Operator* op = javascript()->CreateBlockContext();
Node* scope_info = jsgraph()->Constant(scope->GetScopeInfo(isolate()));
- Node* local_context = NewNode(op, scope_info, closure);
+ Node* local_context = NewNode(op, scope_info, GetFunctionClosureForContext());
return local_context;
}
« no previous file with comments | « src/compiler/ast-graph-builder.h ('k') | test/mjsunit/regress/regress-4169.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698