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

Side by Side Diff: src/compiler/ast-graph-builder.cc

Issue 883823002: Implement proper scoping for "this" in arrow functions Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: mjsunit/debug-scopes: Skip "this" the same as "arguments" Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/ast-graph-builder.h" 5 #include "src/compiler/ast-graph-builder.h"
6 6
7 #include "src/ast-this-access-visitor.h"
7 #include "src/compiler.h" 8 #include "src/compiler.h"
8 #include "src/compiler/ast-loop-assignment-analyzer.h" 9 #include "src/compiler/ast-loop-assignment-analyzer.h"
9 #include "src/compiler/control-builders.h" 10 #include "src/compiler/control-builders.h"
10 #include "src/compiler/linkage.h" 11 #include "src/compiler/linkage.h"
11 #include "src/compiler/machine-operator.h" 12 #include "src/compiler/machine-operator.h"
12 #include "src/compiler/node-matchers.h" 13 #include "src/compiler/node-matchers.h"
13 #include "src/compiler/node-properties.h" 14 #include "src/compiler/node-properties.h"
14 #include "src/compiler/operator-properties.h" 15 #include "src/compiler/operator-properties.h"
15 #include "src/full-codegen.h" 16 #include "src/full-codegen.h"
16 #include "src/parser.h" 17 #include "src/parser.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // It will be replaced with {Dead} after typing and optimizations. 75 // It will be replaced with {Dead} after typing and optimizations.
75 NewNode(common()->OsrNormalEntry()); 76 NewNode(common()->OsrNormalEntry());
76 } 77 }
77 78
78 // Initialize the incoming context. 79 // Initialize the incoming context.
79 Node* outer_context = GetFunctionContext(); 80 Node* outer_context = GetFunctionContext();
80 set_current_context(outer_context); 81 set_current_context(outer_context);
81 82
82 // Build receiver check for sloppy mode if necessary. 83 // Build receiver check for sloppy mode if necessary.
83 // TODO(mstarzinger/verwaest): Should this be moved back into the CallIC? 84 // TODO(mstarzinger/verwaest): Should this be moved back into the CallIC?
84 Node* original_receiver = env.Lookup(scope->receiver()); 85 if (scope->has_this_declaration()) {
85 Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver); 86 Node* original_receiver = env.Lookup(scope->receiver());
86 env.Bind(scope->receiver(), patched_receiver); 87 Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver);
88 env.Bind(scope->receiver(), patched_receiver);
89 }
87 90
88 // Build node to initialize local function context. 91 // Build node to initialize local function context.
89 Node* closure = GetFunctionClosure(); 92 Node* closure = GetFunctionClosure();
90 Node* inner_context = BuildLocalFunctionContext(outer_context, closure); 93 Node* inner_context = BuildLocalFunctionContext(outer_context, closure);
91 94
92 // Push top-level function scope for the function body. 95 // Push top-level function scope for the function body.
93 ContextScope top_context(this, scope, inner_context); 96 ContextScope top_context(this, scope, inner_context);
94 97
95 // Build the arguments object if it is used. 98 // Build the arguments object if it is used.
96 BuildArgumentsObject(scope->arguments()); 99 BuildArgumentsObject(scope->arguments());
(...skipping 1846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 1946
1944 Node* AstGraphBuilder::BuildPatchReceiverToGlobalProxy(Node* receiver) { 1947 Node* AstGraphBuilder::BuildPatchReceiverToGlobalProxy(Node* receiver) {
1945 // Sloppy mode functions and builtins need to replace the receiver with the 1948 // Sloppy mode functions and builtins need to replace the receiver with the
1946 // global proxy when called as functions (without an explicit receiver 1949 // global proxy when called as functions (without an explicit receiver
1947 // object). Otherwise there is nothing left to do here. 1950 // object). Otherwise there is nothing left to do here.
1948 if (info()->strict_mode() != SLOPPY || info()->is_native()) return receiver; 1951 if (info()->strict_mode() != SLOPPY || info()->is_native()) return receiver;
1949 1952
1950 // There is no need to perform patching if the receiver is never used. Note 1953 // There is no need to perform patching if the receiver is never used. Note
1951 // that scope predicates are purely syntactical, a call to eval might still 1954 // that scope predicates are purely syntactical, a call to eval might still
1952 // inspect the receiver value. 1955 // inspect the receiver value.
1953 if (!info()->scope()->uses_this() && !info()->scope()->inner_uses_this() && 1956
1957 AstThisAccessVisitor this_access_visitor(isolate(), zone());
1958 this_access_visitor.VisitStatements(info()->function()->body());
1959
1960 if (!this_access_visitor.UsesThis() &&
1954 !info()->scope()->calls_sloppy_eval()) { 1961 !info()->scope()->calls_sloppy_eval()) {
1955 return receiver; 1962 return receiver;
1956 } 1963 }
1957 1964
1958 IfBuilder receiver_check(this); 1965 IfBuilder receiver_check(this);
1959 Node* undefined = jsgraph()->UndefinedConstant(); 1966 Node* undefined = jsgraph()->UndefinedConstant();
1960 Node* check = NewNode(javascript()->StrictEqual(), receiver, undefined); 1967 Node* check = NewNode(javascript()->StrictEqual(), receiver, undefined);
1961 receiver_check.If(check); 1968 receiver_check.If(check);
1962 receiver_check.Then(); 1969 receiver_check.Then();
1963 environment()->Push(BuildLoadGlobalProxy()); 1970 environment()->Push(BuildLoadGlobalProxy());
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2435 2442
2436 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop( 2443 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop(
2437 IterationStatement* stmt) { 2444 IterationStatement* stmt) {
2438 if (loop_assignment_analysis_ == NULL) return NULL; 2445 if (loop_assignment_analysis_ == NULL) return NULL;
2439 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt); 2446 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt);
2440 } 2447 }
2441 2448
2442 } // namespace compiler 2449 } // namespace compiler
2443 } // namespace internal 2450 } // namespace internal
2444 } // namespace v8 2451 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698