Commit 790219ec authored by vegorov@chromium.org's avatar vegorov@chromium.org

Use correct arguments adaptation environment when inlining function containing arguments.

R=mstarzinger@google.com
BUG=V8:2014
TEST=test/mjsunit/compile/inline-arguments.js

Review URL: https://chromiumcodereview.appspot.com/9750007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11098 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a615abd8
......@@ -5749,20 +5749,11 @@ bool HGraphBuilder::TryCallApply(Call* expr) {
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();
HEnvironment* arguments_env = environment()->arguments_environment();
for (int i = environment()->parameter_count();
i < adaptor->parameter_count();
i++) {
PushAndAdd(new(zone()) HPushArgument(adaptor->Lookup(i)));
}
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(
......
......@@ -400,6 +400,10 @@ class HEnvironment: public ZoneObject {
return outer;
}
HEnvironment* arguments_environment() {
return outer()->frame_type() == ARGUMENTS_ADAPTOR ? outer() : this;
}
// Simple accessors.
Handle<JSFunction> closure() const { return closure_; }
const ZoneList<HValue*>* values() const { return &values_; }
......
......@@ -80,3 +80,36 @@ F4(1);
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();
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment