X87: Reapply "Resolve references to "this" the same way as normal variables""
authorchunyang.dai <chunyang.dai@intel.com>
Tue, 19 May 2015 10:05:35 +0000 (03:05 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 19 May 2015 10:05:23 +0000 (10:05 +0000)
port 1efc1e4f7a3d30d5225e9d5cb2585cad7cb17099 (r28458).

original commit message:

  This reapplies https://codereview.chromium.org/1136073002, along with
    the followups:

      Remove Scope::scope_uses_this_ flag
      https://codereview.chromium.org/1128963005

    and

      PPC: Resolve references to "this" the same way as normal variables
      https://codereview.chromium.org/1134073003

BUG=

Review URL: https://codereview.chromium.org/1135233003

Cr-Commit-Position: refs/heads/master@{#28469}

src/x87/full-codegen-x87.cc
src/x87/lithium-codegen-x87.cc

index 703ec75..e05b738 100644 (file)
@@ -210,8 +210,9 @@ void FullCodeGenerator::Generate() {
 
     // Copy parameters into context if necessary.
     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);
       if (var->IsContextSlot()) {
         int parameter_offset = StandardFrameConstants::kCallerSPOffset +
             (num_parameters - 1 - i) * kPointerSize;
@@ -2929,7 +2930,9 @@ void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) {
   // Push the enclosing function.
   __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
   // Push the receiver of the enclosing function.
-  __ push(Operand(ebp, (2 + info_->scope()->num_parameters()) * kPointerSize));
+  Variable* this_var = scope()->LookupThis();
+  DCHECK_NOT_NULL(this_var);
+  __ push(VarOperand(this_var, ecx));
   // Push the language mode.
   __ push(Immediate(Smi::FromInt(language_mode())));
 
index ca42917..08ef2be 100644 (file)
@@ -110,8 +110,8 @@ bool LCodeGen::GeneratePrologue() {
     // 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()->MayUseThis() &&
-        !info_->is_native()) {
+    if (is_sloppy(info()->language_mode()) && info()->MayUseThis() &&
+        !info()->is_native() && info()->scope()->has_this_declaration()) {
       Label ok;
       // +1 for return address.
       int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize;
@@ -242,8 +242,9 @@ bool LCodeGen::GeneratePrologue() {
 
     // Copy parameters into context if necessary.
     int num_parameters = scope()->num_parameters();
-    for (int i = 0; i < num_parameters; i++) {
-      Variable* var = scope()->parameter(i);
+    int first_parameter = scope()->has_this_declaration() ? -1 : 0;
+    for (int i = first_parameter; 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;