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

Unified Diff: src/x64/full-codegen-x64.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/scopes.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/x64/full-codegen-x64.cc
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
index 24747ee9e85b11d7e3fed1b50e70db0d2073e9b2..ed24025888bede63f2083f3b6e516831e1779c21 100644
--- a/src/x64/full-codegen-x64.cc
+++ b/src/x64/full-codegen-x64.cc
@@ -113,8 +113,10 @@ void FullCodeGenerator::Generate() {
// Sloppy mode functions and builtins need to replace the receiver with the
// global proxy when called as functions (without an explicit receiver
- // object).
- if (info->strict_mode() == SLOPPY && !info->is_native()) {
+ // object). Arrow functions need to replace the receiver with the "this"
+ // binding from the context, so this does not need to be done for those.
+ if (info->strict_mode() == SLOPPY && !info->is_native() &&
+ !info->function()->is_arrow()) {
Label ok;
// +1 for return address.
StackArgumentsAccessor args(rsp, info->scope()->num_parameters());
@@ -140,6 +142,19 @@ void FullCodeGenerator::Generate() {
__ Prologue(info->IsCodePreAgingActive());
info->AddNoFrameRange(0, masm_->pc_offset());
+ // For arrow functions the value of the receiver is stored in the context,
+ // so in the case of a function that actually uses "this", the receiver is
+ // replaced by the one resulting from looking it up in the context.
+ if (info->function()->is_arrow() && info->scope()->uses_this()) {
+ DCHECK(info->scope()->scope_type() == ARROW_SCOPE);
+ Comment cmnt(masm_, "[ Patch receiver for arrow function");
+ StackArgumentsAccessor args(rbp, info->scope()->num_parameters());
+ __ Push(rsi); // Context
+ __ Push(isolate()->factory()->this_string());
+ __ CallRuntime(Runtime::kLoadLookupSlot, 2);
+ __ movp(args.GetReceiverOperand(), rax);
+ }
+
{ Comment cmnt(masm_, "[ Allocate locals");
int locals_count = info->scope()->num_stack_slots();
// Generators allocate locals, if any, in context slots.
@@ -207,9 +222,12 @@ void FullCodeGenerator::Generate() {
__ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rax);
// Copy any necessary parameters into the context.
+ DCHECK(info->scope()->receiver()->IsContextSlot() ==
+ info->scope()->inner_uses_this());
+
int num_parameters = info->scope()->num_parameters();
- for (int i = 0; i < num_parameters; i++) {
- Variable* var = scope()->parameter(i);
+ for (int i = -1; i < num_parameters; i++) {
+ Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
if (var->IsContextSlot()) {
int parameter_offset = StandardFrameConstants::kCallerSPOffset +
(num_parameters - 1 - i) * kPointerSize;
« no previous file with comments | « src/scopes.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698