Index: src/compiler/ast-graph-builder.cc |
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc |
index 6828b5b0a86c7bb3e85ae2745c12401a1f5cc812..bf12869a93cb38f5eef583d080c029cccfa98d7f 100644 |
--- a/src/compiler/ast-graph-builder.cc |
+++ b/src/compiler/ast-graph-builder.cc |
@@ -468,9 +468,11 @@ bool AstGraphBuilder::CreateGraph(bool constant_context, bool stack_check) { |
// Build receiver check for sloppy mode if necessary. |
// TODO(mstarzinger/verwaest): Should this be moved back into the CallIC? |
- Node* original_receiver = env.Lookup(scope->receiver()); |
- Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver); |
- env.Bind(scope->receiver(), patched_receiver); |
+ if (scope->has_this_declaration()) { |
+ Node* original_receiver = env.Lookup(scope->receiver()); |
+ Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver); |
+ env.Bind(scope->receiver(), patched_receiver); |
+ } |
// Build function context only if there are context allocated variables. |
int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
@@ -639,6 +641,13 @@ AstGraphBuilder::Environment::Environment(AstGraphBuilder::Environment* copy) |
void AstGraphBuilder::Environment::Bind(Variable* variable, Node* node) { |
+ // "this" may be context-allocated, but it's possible for us to look it up and |
+ // patch it on the stack before it has been hoisted to the context. |
+ if (variable->is_this()) { |
Michael Starzinger
2015/04/21 18:13:44
AFAICT, this is only needed for patching the recei
wingo
2015/04/22 08:04:00
I had tried to do that, but I couldn't get at envi
Michael Starzinger
2015/04/22 10:59:21
Yes, I think for patching purposes Parameter(0) is
|
+ values()->at(0) = node; |
+ return; |
+ } |
+ |
DCHECK(variable->IsStackAllocated()); |
if (variable->IsParameter()) { |
// The parameter indices are shifted by 1 (receiver is parameter |
@@ -655,6 +664,12 @@ void AstGraphBuilder::Environment::Bind(Variable* variable, Node* node) { |
Node* AstGraphBuilder::Environment::Lookup(Variable* variable) { |
+ // "this" may be context-allocated, but it's possible for us to look it up and |
+ // patch it on the stack before it has been hoisted to the context. |
+ if (variable->is_this()) { |
Michael Starzinger
2015/04/21 18:13:44
Likewise.
wingo
2015/04/22 08:04:00
Acknowledged.
|
+ return values()->at(0); |
+ } |
+ |
DCHECK(variable->IsStackAllocated()); |
if (variable->IsParameter()) { |
// The parameter indices are shifted by 1 (receiver is parameter |
@@ -2148,7 +2163,7 @@ void AstGraphBuilder::VisitCall(Call* expr) { |
// Create node to ask for help resolving potential eval call. This will |
// provide a fully resolved callee and the corresponding receiver. |
Node* function = GetFunctionClosure(); |
- Node* receiver = environment()->Lookup(info()->scope()->receiver()); |
+ Node* receiver = environment()->Lookup(info()->scope()->LookupThis()); |
Node* language = jsgraph()->Constant(language_mode()); |
Node* position = jsgraph()->Constant(info()->scope()->start_position()); |
const Operator* op = |
@@ -2651,8 +2666,10 @@ Node* AstGraphBuilder::BuildLocalFunctionContext(Node* context) { |
// Copy parameters into context if necessary. |
int num_parameters = info()->scope()->num_parameters(); |
- for (int i = 0; i < num_parameters; i++) { |
- Variable* variable = info()->scope()->parameter(i); |
+ int first_parameter = info()->scope()->has_this_declaration() ? -1 : 0; |
+ for (int i = first_parameter; i < num_parameters; i++) { |
+ Variable* variable = |
+ (i == -1) ? info()->scope()->receiver() : info()->scope()->parameter(i); |
Michael Starzinger
2015/04/21 18:13:44
This is getting out of hand, please hoist handling
|
if (!variable->IsContextSlot()) continue; |
// Temporary parameter node. The parameter indices are shifted by 1 |
// (receiver is parameter index -1 but environment index 0). |