Revision: 11098
Author:   [email protected]
Date:     Tue Mar 20 11:15:31 2012
Log: Use correct arguments adaptation environment when inlining function containing arguments.

[email protected]
BUG=V8:2014
TEST=test/mjsunit/compile/inline-arguments.js

Review URL: https://chromiumcodereview.appspot.com/9750007
http://code.google.com/p/v8/source/detail?r=11098

Modified:
 /branches/bleeding_edge/src/hydrogen.cc
 /branches/bleeding_edge/src/hydrogen.h
 /branches/bleeding_edge/test/mjsunit/compiler/inline-arguments.js

=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Mon Mar 19 08:54:37 2012
+++ /branches/bleeding_edge/src/hydrogen.cc     Tue Mar 20 11:15:31 2012
@@ -5749,20 +5749,11 @@
         AddInstruction(new(zone()) HWrapReceiver(receiver, function));
     PushAndAdd(new(zone()) HPushArgument(wrapped_receiver));

-    int parameter_count = environment()->parameter_count();
-    for (int i = 1; i < environment()->parameter_count(); i++) {
-      PushAndAdd(new(zone()) HPushArgument(environment()->Lookup(i)));
-    }
-
-    if (environment()->outer()->frame_type() == ARGUMENTS_ADAPTOR) {
-      HEnvironment* adaptor = environment()->outer();
-      parameter_count = adaptor->parameter_count();
-
-      for (int i = environment()->parameter_count();
-           i < adaptor->parameter_count();
-           i++) {
-        PushAndAdd(new(zone()) HPushArgument(adaptor->Lookup(i)));
-      }
+    HEnvironment* arguments_env = environment()->arguments_environment();
+
+    int parameter_count = arguments_env->parameter_count();
+    for (int i = 1; i < arguments_env->parameter_count(); i++) {
+      PushAndAdd(new(zone()) HPushArgument(arguments_env->Lookup(i)));
     }

     HInvokeFunction* call = new(zone()) HInvokeFunction(
=======================================
--- /branches/bleeding_edge/src/hydrogen.h      Thu Mar 15 05:21:29 2012
+++ /branches/bleeding_edge/src/hydrogen.h      Tue Mar 20 11:15:31 2012
@@ -399,6 +399,10 @@
     if (drop_extra) outer->Drop(1);
     return outer;
   }
+
+  HEnvironment* arguments_environment() {
+    return outer()->frame_type() == ARGUMENTS_ADAPTOR ? outer() : this;
+  }

   // Simple accessors.
   Handle<JSFunction> closure() const { return closure_; }
=======================================
--- /branches/bleeding_edge/test/mjsunit/compiler/inline-arguments.js Tue Mar 13 07:45:03 2012 +++ /branches/bleeding_edge/test/mjsunit/compiler/inline-arguments.js Tue Mar 20 11:15:31 2012
@@ -80,3 +80,36 @@
 F4(1);
 %OptimizeFunctionOnNextCall(F4);
 F4(1);
+
+
+// Test correct adapation of arguments.
+// Strict mode prevents arguments object from shadowing parameters.
+(function () {
+  "use strict";
+
+  function G2() {
+    assertArrayEquals([1,2], arguments);
+  }
+
+  function G4() {
+    assertArrayEquals([1,2,3,4], arguments);
+  }
+
+  function adapt2to4(a, b, c, d) {
+    G2.apply(this, arguments);
+  }
+
+  function adapt4to2(a, b) {
+    G4.apply(this, arguments);
+  }
+
+  function test_adaptation() {
+    adapt2to4(1, 2);
+    adapt4to2(1, 2, 3, 4);
+  }
+
+  test_adaptation();
+  test_adaptation();
+  %OptimizeFunctionOnNextCall(test_adaptation);
+  test_adaptation();
+})();

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to