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

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: WIP v3 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
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index 39b67a886444fe1db46a54e4006d37abd68d447a..01cc24eeeae5ac9cd6e647586d62d824a865c376 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 collected in the context.
wingo 2015/01/15 10:09:06 "allocated". And really it's "copied to" the cont
aperez 2015/01/15 16:58:03 Done.
+ 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++) {
@@ -1181,7 +1187,7 @@ void Scope::PropagateScopeInfo(bool outer_scope_calls_sloppy_eval ) {
// 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->is_arrow_scope()) {
if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) {
inner_scope_uses_arguments_ = true;
}
@@ -1196,12 +1202,38 @@ void Scope::PropagateScopeInfo(bool outer_scope_calls_sloppy_eval ) {
if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) {
inner_scope_uses_this_ = true;
}
- }
- if (inner->force_eager_compilation_) {
- force_eager_compilation_ = true;
- }
- if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) {
- inner->asm_function_ = true;
+ } else if (inner->is_block_scope()) {
+ if (inner->scope_uses_this_) {
wingo 2015/01/15 10:09:06 Why do we need the whole list of these? At some p
aperez 2015/01/15 16:58:03 I have been trying to factor out the flag propagat
+ 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_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->inner_scope_uses_this_) {
+ inner_scope_uses_this_ = true;
+ }
+ } else if (!inner->is_function_scope() || inner->is_arrow_scope()) {
+ if (inner->force_eager_compilation_) {
+ force_eager_compilation_ = true;
+ }
wingo 2015/01/15 10:09:05 These propagations should run for all scopes
aperez 2015/01/15 16:58:03 Done.
+ if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) {
+ inner->asm_function_ = true;
+ }
}
}
}
@@ -1324,6 +1356,18 @@ void Scope::AllocateParameterLocals() {
}
}
}
+
+ // If the scope contains at least one inner arrow function which uses
+ // "this", it must be copied in the context, from where it will be looked
wingo 2015/01/15 10:09:06 s/it must be copied in/the receiver must be copied
aperez 2015/01/15 16:58:03 Done.
+ // 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_));
+ }
}

Powered by Google App Engine
This is Rietveld 408576698