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

Unified Diff: src/scopes.cc

Issue 791603003: WIP context-allocation for “this” in arrow functions Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Clean up a couple of comments, otherwise same as previous patch set Created 5 years, 11 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/heap/heap.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index 39b67a886444fe1db46a54e4006d37abd68d447a..cbb0d5dfe8f855e79eca7825c3f1f366ec1ffd80 100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -609,6 +609,12 @@ void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals,
}
}
+ // Arrow functions can cause the receiver to be copied in the context.
+ if (receiver_ && receiver_->has_forced_context_allocation()) {
+ DCHECK(receiver_->IsContextSlot());
+ context_locals->Add(receiver_, zone());
+ }
+
// Collect temporaries which are always allocated on the stack, unless the
// context as a whole has forced context allocation.
for (int i = 0; i < temps_.length(); i++) {
@@ -1178,25 +1184,40 @@ void Scope::PropagateScopeInfo(bool outer_scope_calls_sloppy_eval ) {
if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) {
inner_scope_calls_eval_ = true;
}
+
// If the inner scope is an arrow function, propagate the flags tracking
// usage of arguments/super/this, but do not propagate them out from normal
// functions.
- if (!inner->is_function_scope() || inner->is_arrow_scope()) {
- if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) {
+ if (inner->is_arrow_scope()) {
+ if (inner->scope_uses_this_ || inner->inner_scope_uses_this_)
+ inner_scope_uses_this_ = true;
+ if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_)
inner_scope_uses_arguments_ = true;
- }
if (inner->scope_uses_super_property_ ||
- inner->inner_scope_uses_super_property_) {
+ inner->inner_scope_uses_super_property_)
inner_scope_uses_super_property_ = true;
- }
if (inner->uses_super_constructor_call() ||
- inner->inner_scope_uses_super_constructor_call_) {
+ inner->inner_scope_uses_super_constructor_call_)
inner_scope_uses_super_constructor_call_ = true;
- }
- if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) {
+ } else if (!inner->is_function_scope()) {
+ if (inner->scope_uses_this_)
+ scope_uses_this_ = true;
+ if (inner->scope_uses_arguments_)
+ scope_uses_arguments_ = true;
+ if (inner->scope_uses_super_property_)
+ scope_uses_super_property_ = true;
+ if (inner->scope_uses_super_constructor_call_)
+ scope_uses_super_constructor_call_ = true;
+ if (inner->inner_scope_uses_this_)
inner_scope_uses_this_ = true;
- }
+ if (inner->inner_scope_uses_arguments_)
+ inner_scope_uses_arguments_ = true;
+ if (inner->inner_scope_uses_super_property_)
+ inner_scope_uses_super_property_ = true;
+ if (inner->inner_scope_uses_super_constructor_call_)
+ inner_scope_uses_super_constructor_call_ = true;
}
+
if (inner->force_eager_compilation_) {
force_eager_compilation_ = true;
}
@@ -1324,6 +1345,18 @@ void Scope::AllocateParameterLocals() {
}
}
}
+
+ // If the scope contains at least one inner arrow function which uses
+ // "this", the receiver must be copied to the context, from where it will
+ // be looked up by code emitted in the prologues of arrow functions.
+ if (inner_scope_uses_this_) {
+ DCHECK(receiver_);
+ if (receiver_->IsUnallocated() || !receiver_->IsContextSlot()) {
+ receiver_->ForceContextAllocation();
+ AllocateHeapSlot(receiver_);
+ }
+ DCHECK(MustAllocateInContext(receiver_));
+ }
}
« no previous file with comments | « src/heap/heap.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698