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

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

Issue 1097283003: Resolve references to "this" the same way as normal variables (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: All TF tests passing Created 5 years, 8 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 | « no previous file | src/contexts.cc » ('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 6828b5b0a86c7bb3e85ae2745c12401a1f5cc812..797ca35034429c0b477618ff636307c707c31f2d 100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -468,9 +468,13 @@ 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() && scope->receiver()->IsStackAllocated()) {
+ // If the receiver is context-allocated, we patch it in
+ // BuildLocalFunctionContext.
+ Node* original_receiver = env.Lookup(scope->receiver());
+ Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver);
Michael Starzinger 2015/04/22 10:59:21 Instead of having two call-sites of BuildPatchRece
Michael Starzinger 2015/04/22 11:17:53 Or alternatively pass the patched_receiver as an a
wingo 2015/04/22 13:05:23 A bit squirrely, but done.
+ 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;
@@ -2148,7 +2152,23 @@ 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());
+ // TODO(wingo): ResolvePossibleDirectEval doesn't really need a receiver,
+ // now that eval scopes don't have "this" declarations. Remove this hack
+ // once ResolvePossibleDirectEval changes.
Michael Starzinger 2015/04/22 10:59:21 Does this mean that the "receiver" input to Resolv
wingo 2015/04/22 13:05:23 Yes I think so, and the second return value from R
Michael Starzinger 2015/04/22 13:26:19 Woot! That would be the awesomez! :)
+ Node* receiver;
+ {
+ Variable* variable = info()->scope()->LookupThis();
+ if (variable->IsStackAllocated()) {
+ receiver = environment()->Lookup(variable);
+ } else {
+ DCHECK(variable->IsContextSlot());
+ int depth = current_scope()->ContextChainLength(variable->scope());
+ bool immutable = variable->maybe_assigned() == kNotAssigned;
+ const Operator* op =
+ javascript()->LoadContext(depth, variable->index(), immutable);
+ receiver = NewNode(op, current_context());
+ }
+ }
Node* language = jsgraph()->Constant(language_mode());
Node* position = jsgraph()->Constant(info()->scope()->start_position());
const Operator* op =
@@ -2649,6 +2669,17 @@ Node* AstGraphBuilder::BuildLocalFunctionContext(Node* context) {
? BuildLocalScriptContext(info()->scope())
: NewNode(javascript()->CreateFunctionContext(), closure);
+ if (info()->scope()->has_this_declaration() &&
+ info()->scope()->receiver()->IsContextSlot()) {
+ Node* original_receiver = NewNode(common()->Parameter(0), graph()->start());
+ Node* patched_receiver = BuildPatchReceiverToGlobalProxy(original_receiver);
+ // Context variable (at bottom of the context chain).
+ Variable* variable = info()->scope()->receiver();
+ DCHECK_EQ(0, info()->scope()->ContextChainLength(variable->scope()));
+ const Operator* op = javascript()->StoreContext(0, variable->index());
+ NewNode(op, local_context, patched_receiver);
+ }
+
// Copy parameters into context if necessary.
int num_parameters = info()->scope()->num_parameters();
for (int i = 0; i < num_parameters; i++) {
« no previous file with comments | « no previous file | src/contexts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698