| 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;
|
|
|