Index: test/mjsunit/compiler/inline-function-apply.js |
diff --git a/test/mjsunit/compiler/property-static.js b/test/mjsunit/compiler/inline-function-apply.js |
similarity index 50% |
copy from test/mjsunit/compiler/property-static.js |
copy to test/mjsunit/compiler/inline-function-apply.js |
index 07021340cd7aa94440638f925eeed921ee78c9c7..76bfa4510acbd0c1f94328901e5369163f12570c 100644 |
--- a/test/mjsunit/compiler/property-static.js |
+++ b/test/mjsunit/compiler/inline-function-apply.js |
@@ -27,43 +27,64 @@ |
// Flags: --allow-natives-syntax |
-// Test usage of static type information for loads that would otherwise |
-// turn into polymorphic or generic loads. |
+// Test inlining and deoptimization of function.apply(this, arguments) |
+// calls for which the exact number of arguments is known. |
+(function () { |
+ "use strict"; |
+ function test(argumentsCount) { |
+ var dispatcher = {}; |
+ var deoptimize = { deopt:false }; |
+ dispatcher["const" + argumentsCount] = 0; |
+ dispatcher.func = C; |
-// Prepare a highly polymorphic load to be used by all tests. |
-Object.prototype.load = function() { return this.property; }; |
-Object.prototype.load.call({ A:0, property:10 }); |
-Object.prototype.load.call({ A:0, B:0, property:11 }); |
-Object.prototype.load.call({ A:0, B:0, C:0, property:12 }); |
-Object.prototype.load.call({ A:0, B:0, C:0, D:0, property:13 }); |
-Object.prototype.load.call({ A:0, B:0, C:0, D:0, E:0, property:14 }); |
-Object.prototype.load.call({ A:0, B:0, C:0, D:0, E:0, F:0, property:15 }); |
+ function A(x,y) { |
+ var r = "A"; |
+ if (argumentsCount == 1) r += B(10); |
+ if (argumentsCount == 2) r += B(10, 11); |
+ if (argumentsCount == 3) r += B(10, 11, 12); |
+ assertSame(1, x); |
+ assertSame(2, y); |
+ return r; |
+ } |
-// Test for object literals. |
-(function() { |
- function f(x) { |
- var object = { property:x }; |
- return object.load(); |
- } |
+ function B(x,y) { |
+ // TODO(2539): Enable the mutation below once bug is fixed. |
Michael Starzinger
2013/02/13 11:53:00
Note that this is a bug that is already present in
|
+ //x = 0; y = 0; |
+ var r = "B" + dispatcher.func.apply(this, arguments); |
+ assertSame(argumentsCount, arguments.length); |
+ for (var i = 0; i < arguments.length; i++) { |
+ assertSame(10 + i, arguments[i]); |
+ } |
+ return r; |
+ } |
- assertSame(1, f(1)); |
- assertSame(2, f(2)); |
- %OptimizeFunctionOnNextCall(f); |
- assertSame(3, f(3)); |
-})(); |
+ function C(x,y) { |
+ x = 0; y = 0; |
+ var r = "C" |
+ deoptimize.deopt; |
+ assertSame(argumentsCount, arguments.length); |
+ for (var i = 0; i < arguments.length; i++) { |
+ assertSame(10 + i, arguments[i]); |
+ } |
+ return r; |
+ } |
-// Test for inlined constructors. |
-(function() { |
- function c(x) { |
- this.property = x; |
- } |
- function f(x) { |
- var object = new c(x); |
- return object.load(); |
+ assertEquals("ABC", A(1,2)); |
+ assertEquals("ABC", A(1,2)); |
+ %OptimizeFunctionOnNextCall(A); |
+ assertEquals("ABC", A(1,2)); |
+ delete deoptimize.deopt; |
+ assertEquals("ABC", A(1,2)); |
+ |
+ %DeoptimizeFunction(A); |
+ %ClearFunctionTypeFeedback(A); |
+ %DeoptimizeFunction(B); |
+ %ClearFunctionTypeFeedback(B); |
+ %DeoptimizeFunction(C); |
+ %ClearFunctionTypeFeedback(C); |
} |
- assertSame(1, f(1)); |
- assertSame(2, f(2)); |
- %OptimizeFunctionOnNextCall(f); |
- assertSame(3, f(3)); |
+ for (var a = 1; a <= 3; a++) { |
+ test(a); |
+ } |
})(); |