| Index: test/mjsunit/array-constructor-feedback.js
|
| diff --git a/test/mjsunit/array-constructor-feedback.js b/test/mjsunit/array-constructor-feedback.js
|
| index c2c1a1842f7d580800bbed37b62527f45f1454b1..6878e80bf2f281bcc5e4768c31c1c714d50271a3 100644
|
| --- a/test/mjsunit/array-constructor-feedback.js
|
| +++ b/test/mjsunit/array-constructor-feedback.js
|
| @@ -62,6 +62,7 @@ function assertKind(expected, obj, name_opt) {
|
| assertEquals(expected, getKind(obj), name_opt);
|
| }
|
|
|
| +
|
| // Test: If a call site goes megamorphic, it retains the ability to
|
| // use allocation site feedback (if FLAG_allocation_site_pretenuring
|
| // is on).
|
| @@ -217,3 +218,52 @@ function assertKind(expected, obj, name_opt) {
|
| assertFalse(isHoley(a));
|
| }
|
| })();
|
| +
|
| +
|
| +// Test: verify that elements capacity feedback works
|
| +(function() {
|
| + // It works for optimized functions with a no-argument array call.
|
| + function foo() { return new Array(); }
|
| + a = foo();
|
| + a.push(1, 2, 3, 4, 5, 6);
|
| + assertEquals(25, %GetElementsCapacity(a));
|
| + %OptimizeFunctionOnNextCall(foo);
|
| + b = foo();
|
| + assertEquals(25, %GetElementsCapacity(b));
|
| +
|
| + // It works for optimized functions with a constant argument array call.
|
| + function bar() { return new Array(1); }
|
| + a = bar();
|
| + a.push(1, 2, 3, 4, 5, 6);
|
| + assertEquals(26, %GetElementsCapacity(a));
|
| + %OptimizeFunctionOnNextCall(bar);
|
| + b = bar();
|
| + assertEquals(26, %GetElementsCapacity(b));
|
| +
|
| + // It doesn't work for functions with a non-constant length for array.
|
| + function nonconst(l) { return new Array(l); }
|
| + a = nonconst(1);
|
| + a.push(1, 2, 3, 4, 5, 6);
|
| + assertEquals(26, %GetElementsCapacity(a));
|
| + %OptimizeFunctionOnNextCall(nonconst);
|
| + b = nonconst(3);
|
| + assertEquals(3, %GetElementsCapacity(b));
|
| +
|
| + // It doesn't work for multiple arguments to the array constructor.
|
| + function some_args() { return new Array(1, 2, 3); }
|
| + a = some_args();
|
| + a.push(1, 2, 3, 4, 5, 6);
|
| + assertEquals(29, %GetElementsCapacity(a));
|
| + %OptimizeFunctionOnNextCall(some_args);
|
| + b = some_args();
|
| + assertEquals(3, %GetElementsCapacity(b));
|
| +
|
| + // It doesn't work for literals.
|
| + function with_literal() { var a = [1,2]; return a; }
|
| + a = with_literal();
|
| + a.push(1, 2, 3, 4, 5, 6);
|
| + assertEquals(28, %GetElementsCapacity(a));
|
| + %OptimizeFunctionOnNextCall(with_literal);
|
| + b = with_literal();
|
| + assertEquals(0, %GetElementsCapacity(b));
|
| +})();
|
|
|