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

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: Rebased against master, plus fixes. Only 4 tests failing (+2 in TurboFan) 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
« no previous file with comments | « src/compiler/ast-graph-builder.h ('k') | src/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/compiler.h" 7 #include "src/compiler.h"
8 #include "src/compiler/ast-loop-assignment-analyzer.h" 8 #include "src/compiler/ast-loop-assignment-analyzer.h"
9 #include "src/compiler/control-builders.h" 9 #include "src/compiler/control-builders.h"
10 #include "src/compiler/linkage.h" 10 #include "src/compiler/linkage.h"
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // It will be replaced with {Dead} after typing and optimizations. 451 // It will be replaced with {Dead} after typing and optimizations.
452 NewNode(common()->OsrNormalEntry()); 452 NewNode(common()->OsrNormalEntry());
453 } 453 }
454 454
455 // Initialize the incoming context. 455 // Initialize the incoming context.
456 CreateFunctionContext(constant_context); 456 CreateFunctionContext(constant_context);
457 ContextScope incoming(this, scope, function_context_.get()); 457 ContextScope incoming(this, scope, function_context_.get());
458 458
459 // Build receiver check for sloppy mode if necessary. 459 // Build receiver check for sloppy mode if necessary.
460 // TODO(mstarzinger/verwaest): Should this be moved back into the CallIC? 460 // TODO(mstarzinger/verwaest): Should this be moved back into the CallIC?
461 Node* original_receiver = env.Lookup(scope->receiver()); 461 if (scope->has_this_declaration()) {
462 Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver); 462 Node* original_receiver = env.Lookup(scope->receiver());
463 env.Bind(scope->receiver(), patched_receiver); 463 Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver);
464 env.Bind(scope->receiver(), patched_receiver);
465 }
464 466
465 // Build function context only if there are context allocated variables. 467 // Build function context only if there are context allocated variables.
466 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; 468 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
467 if (heap_slots > 0) { 469 if (heap_slots > 0) {
468 // Push a new inner context scope for the function. 470 // Push a new inner context scope for the function.
469 Node* closure = GetFunctionClosure(); 471 Node* closure = GetFunctionClosure();
470 Node* inner_context = 472 Node* inner_context =
471 BuildLocalFunctionContext(function_context_.get(), closure); 473 BuildLocalFunctionContext(function_context_.get(), closure);
472 ContextScope top_context(this, scope, inner_context); 474 ContextScope top_context(this, scope, inner_context);
473 CreateGraphBody(); 475 CreateGraphBody();
(...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 } 2452 }
2451 2453
2452 2454
2453 Node* AstGraphBuilder::BuildLocalFunctionContext(Node* context, Node* closure) { 2455 Node* AstGraphBuilder::BuildLocalFunctionContext(Node* context, Node* closure) {
2454 // Allocate a new local context. 2456 // Allocate a new local context.
2455 const Operator* op = javascript()->CreateFunctionContext(); 2457 const Operator* op = javascript()->CreateFunctionContext();
2456 Node* local_context = NewNode(op, closure); 2458 Node* local_context = NewNode(op, closure);
2457 2459
2458 // Copy parameters into context if necessary. 2460 // Copy parameters into context if necessary.
2459 int num_parameters = info()->scope()->num_parameters(); 2461 int num_parameters = info()->scope()->num_parameters();
2460 for (int i = 0; i < num_parameters; i++) { 2462 int first_parameter = info()->scope()->has_this_declaration() ? -1 : 0;
2461 Variable* variable = info()->scope()->parameter(i); 2463 for (int i = first_parameter; i < num_parameters; i++) {
2464 Variable* variable =
2465 (i == -1) ? info()->scope()->receiver() : info()->scope()->parameter(i);
2462 if (!variable->IsContextSlot()) continue; 2466 if (!variable->IsContextSlot()) continue;
2463 // Temporary parameter node. The parameter indices are shifted by 1 2467 // Temporary parameter node. The parameter indices are shifted by 1
2464 // (receiver is parameter index -1 but environment index 0). 2468 // (receiver is parameter index -1 but environment index 0).
2465 Node* parameter = NewNode(common()->Parameter(i + 1), graph()->start()); 2469 Node* parameter = NewNode(common()->Parameter(i + 1), graph()->start());
2466 // Context variable (at bottom of the context chain). 2470 // Context variable (at bottom of the context chain).
2467 DCHECK_EQ(0, info()->scope()->ContextChainLength(variable->scope())); 2471 DCHECK_EQ(0, info()->scope()->ContextChainLength(variable->scope()));
2468 const Operator* op = javascript()->StoreContext(0, variable->index()); 2472 const Operator* op = javascript()->StoreContext(0, variable->index());
2469 NewNode(op, local_context, parameter); 2473 NewNode(op, local_context, parameter);
2470 } 2474 }
2471 2475
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
3233 // Phi does not exist yet, introduce one. 3237 // Phi does not exist yet, introduce one.
3234 value = NewPhi(inputs, value, control); 3238 value = NewPhi(inputs, value, control);
3235 value->ReplaceInput(inputs - 1, other); 3239 value->ReplaceInput(inputs - 1, other);
3236 } 3240 }
3237 return value; 3241 return value;
3238 } 3242 }
3239 3243
3240 } // namespace compiler 3244 } // namespace compiler
3241 } // namespace internal 3245 } // namespace internal
3242 } // namespace v8 3246 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/ast-graph-builder.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698