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

Unified Diff: src/x64/full-codegen-x64.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: Add tests for "this" scoping in arrow functions 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
Index: src/x64/full-codegen-x64.cc
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
index 90d309504218bffd333366d1a2c03752c71bfb58..5741f7d178bba216f51023175a56294b402fa2fa 100644
--- a/src/x64/full-codegen-x64.cc
+++ b/src/x64/full-codegen-x64.cc
@@ -115,7 +115,8 @@ 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 (is_sloppy(info->language_mode()) && !info->is_native()) {
+ if (is_sloppy(info->language_mode()) && !info->is_native() &&
+ info->scope()->has_this_declaration()) {
Label ok;
// +1 for return address.
StackArgumentsAccessor args(rsp, info->scope()->num_parameters());
@@ -209,8 +210,10 @@ void FullCodeGenerator::Generate() {
// Copy any necessary parameters into the context.
int num_parameters = info->scope()->num_parameters();
- for (int i = 0; i < num_parameters; i++) {
- Variable* var = scope()->parameter(i);
+ int first_parameter = info->scope()->has_this_declaration() ? -1 : 0;
+ for (int i = first_parameter; i < num_parameters; i++) {
+ Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
+ CHECK_NOT_NULL(var);
adamk 2015/04/22 15:50:54 Seems unnecessary since receiver() already has thi
wingo 2015/04/23 14:16:02 Good catch; was vestigial. Removed.
if (var->IsContextSlot()) {
int parameter_offset = StandardFrameConstants::kCallerSPOffset +
(num_parameters - 1 - i) * kPointerSize;
@@ -2989,8 +2992,9 @@ void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) {
__ Push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
// Push the receiver of the enclosing function and do runtime call.
- StackArgumentsAccessor args(rbp, info_->scope()->num_parameters());
- __ Push(args.GetReceiverOperand());
+ Variable* this_var = scope()->LookupThis();
+ CHECK_NOT_NULL(this_var);
adamk 2015/04/22 15:50:54 DCHECK
wingo 2015/04/23 14:16:02 Done.
+ __ Push(VarOperand(this_var, kScratchRegister));
// Push the language mode.
__ Push(Smi::FromInt(language_mode()));

Powered by Google App Engine
This is Rietveld 408576698