Commit 8b0cbd23 authored by Paolo Severini's avatar Paolo Severini Committed by V8 LUCI CQ

Fix flaky tests mjsunit/compiler/call-with-arraylike-or-spread*

The tests are not compatible with the --stress-background-compile flag.

Bug: v8:11821
Change-Id: Iecef6a2838109fddc9f0ecc145a9f8971bc9bc3c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2918214Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Paolo Severini <paolosev@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#74959}
parent 906193e0
...@@ -17,25 +17,25 @@ ...@@ -17,25 +17,25 @@
"use strict"; "use strict";
// Setting value to be retrieved in place of hole. // Setting value to be retrieved in place of hole.
Array.prototype[1] = 'x'; Array.prototype[2] = 'x';
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
function foo(x, y) { function foo(x, y) {
return sum_js3.apply(null, [x, , y]); return sum_js.apply(null, ["", x, ,y]);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('AxB', foo('A', 'B')); assertEquals('AxB', foo('A', 'B'));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
// The protector should be invalidated, which prevents inlining. // The protector should be invalidated, which prevents inlining.
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertEquals('AxB', foo('A', 'B')); assertEquals('AxB', foo('A', 'B'));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
...@@ -20,33 +20,33 @@ ...@@ -20,33 +20,33 @@
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
function foo(x, y) { function foo(x, y) {
return sum_js3.apply(null, [x, , y]); return sum_js.apply(null, ["", x, ,y]);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('AundefinedB', foo('A', 'B')); assertEquals('AundefinedB', foo('A', 'B'));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertEquals('AundefinedB', foo('A', 'B')); assertEquals('AundefinedB', foo('A', 'B'));
assertFalse(sum_js3_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
// Modify the array prototype, define a default value for element [1]. // Modify the array prototype, define a default value for element [1].
Array.prototype[1] = 'x'; Array.prototype[2] = 'x';
assertUnoptimized(foo); assertUnoptimized(foo);
// Now the call will not be inlined. // Now the call will not be inlined.
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertEquals('AxB', foo('A', 'B')); assertEquals('AxB', foo('A', 'B'));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
// Test deopt when array map changes. // Test deopt when array map changes.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c;
} }
function foo(x, y, z, str) { function foo(x, y, z, str) {
...@@ -28,25 +28,25 @@ ...@@ -28,25 +28,25 @@
if (str) { if (str) {
v[0] = str; v[0] = str;
} }
return sum_js3.apply(null, v); return sum_js.apply(null, v);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals(78, foo(26, 6, 46, null)); assertEquals(78, foo(26, 6, 46, null));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
// Compile function foo; inlines 'sum_js3' into 'foo'. // Compile function foo; inlines 'sum_js' into 'foo'.
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertEquals(78, foo(26, 6, 46, null)); assertEquals(78, foo(26, 6, 46, null));
assertOptimized(foo); assertOptimized(foo);
if (i < 3) { if (i < 3) {
assertFalse(sum_js3_got_interpreted); assertFalse(sum_js_got_interpreted);
} else { } else {
// i: 3: Speculation mode prevents optimization of sum_js3.apply() call. // i: 3: Speculation mode prevents optimization of sum_js.apply() call.
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
} }
// This should deoptimize: // This should deoptimize:
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
// i: 1,2: Deopt eager: wrong map. // i: 1,2: Deopt eager: wrong map.
// i: 3: Won't deopt anymore. // i: 3: Won't deopt anymore.
assertEquals("v8646", foo(26, 6, 46, "v8")); assertEquals("v8646", foo(26, 6, 46, "v8"));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
if (i < 3) { if (i < 3) {
assertUnoptimized(foo); assertUnoptimized(foo);
......
...@@ -18,133 +18,133 @@ ...@@ -18,133 +18,133 @@
// Test JSCallReducer::ReduceJSCallWithArrayLike. // Test JSCallReducer::ReduceJSCallWithArrayLike.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
function foo(x, y, z) { function foo(x, y, z) {
return sum_js3.apply(null, [x, y, z]); return sum_js.apply(null, ["", x, y, z]);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
assertFalse(sum_js3_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
assertFalse(sum_js_got_interpreted);
})(); })();
// Test with holey array. // Test with holey array.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
function foo(x, y) { function foo(x, y) {
return sum_js3.apply(null, [x,,y]); return sum_js.apply(null, ["",x,,y]);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('AundefinedB', foo('A', 'B')); assertEquals('AundefinedB', foo('A', 'B'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals('AundefinedB', foo('A', 'B')); assertEquals('AundefinedB', foo('A', 'B'));
assertFalse(sum_js3_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
// Test with holey-double array. // Test with holey-double array.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + (b ? b : .0) + c; return a + b + (c ? c : .0) + d;
} }
function foo(x, y) { function foo(x, y) {
return sum_js3.apply(null, [x,,y]); return sum_js.apply(null, [3.14, x, , y]);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals(42.17, foo(16.11, 26.06)); assertEquals(45.31, foo(16.11, 26.06));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
// This is expected to deoptimize // This is expected to deoptimize
assertEquals(42.17, foo(16.11, 26.06)); assertEquals(45.31, foo(16.11, 26.06));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertUnoptimized(foo); assertUnoptimized(foo);
// Optimize again // Optimize again
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals(42.17, foo(16.11, 26.06)); assertEquals(45.31, foo(16.11, 26.06));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
// This this it should stay optimized, but with the call not inlined. // This should stay optimized, but with the call not inlined.
assertEquals(42.17, foo(16.11, 26.06)); assertEquals(45.31, foo(16.11, 26.06));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
// Test deopt when array size changes. // Test deopt when array size changes.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
function foo(x, y, z) { function foo(x, y, z) {
let a = [x, y, z]; let a = ["", x, y, z];
a.push('*'); a.push('*');
return sum_js3.apply(null, a); return sum_js.apply(null, a);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
// Here array size changes. // Here array size changes.
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
// Here it should deoptimize. // Here it should deoptimize.
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
assertUnoptimized(foo); assertUnoptimized(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
// Now speculation mode prevents the optimization. // Now speculation mode prevents the optimization.
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
// Test with FixedDoubleArray. // Test with FixedDoubleArray.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
function foo(x, y, z) { function foo(x, y, z) {
return sum_js3.apply(null, [x, y, z]); return sum_js.apply(null, [3.14, x, y, z]);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals(53.2, foo(11.03, 16.11, 26.06)); assertEquals(56.34, foo(11.03, 16.11, 26.06));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals(53.2, foo(11.03, 16.11, 26.06)); assertEquals(56.34, foo(11.03, 16.11, 26.06));
assertFalse(sum_js3_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
...@@ -207,68 +207,68 @@ ...@@ -207,68 +207,68 @@
// Test Reflect.apply(). // Test Reflect.apply().
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
function foo(x, y ,z) { function foo(x, y ,z) {
return Reflect.apply(sum_js3, null, [x, y, z]); return Reflect.apply(sum_js, null, ["", x, y, z]);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
assertFalse(sum_js3_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
// Test JSCallReducer::ReduceJSCallWithSpread. // Test JSCallReducer::ReduceJSCallWithSpread.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
function foo(x, y, z) { function foo(x, y, z) {
const numbers = [x, y, z]; const numbers = ["", x, y, z];
return sum_js3(...numbers); return sum_js(...numbers);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
assertFalse(sum_js3_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
// Test spread call with empty array. // Test spread call with empty array.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c;
} }
function foo(x, y, z) { function foo(x, y, z) {
const args = []; const args = [];
return sum_js3(x, y, z, ...args); return sum_js(x, y, z, ...args);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
assertFalse(sum_js3_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
...@@ -276,13 +276,13 @@ ...@@ -276,13 +276,13 @@
(function () { (function () {
"use strict"; "use strict";
var sum_js_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js(a, b, c, d, e, f) { function sum_js(a, b, c, d, e, f, g) {
assertEquals(6, arguments.length); assertEquals(7, arguments.length);
sum_js_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c + d + e + f; return a + b + c + d + e + f + g;
} }
function foo(x, y, z) { function foo(x, y, z) {
const numbers = [z, y, x]; const numbers = ["", z, y, x];
return sum_js(x, y, z, ...numbers); return sum_js(x, y, z, ...numbers);
} }
...@@ -301,16 +301,16 @@ ...@@ -301,16 +301,16 @@
"use strict"; "use strict";
var sum_got_interpreted = true; var sum_got_interpreted = true;
function foo_closure() { function foo_closure() {
return function(a, b, c) { return function(a, b, c, d) {
sum_got_interpreted = %IsBeingInterpreted(); sum_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
} }
const _foo_closure = foo_closure(); const _foo_closure = foo_closure();
%PrepareFunctionForOptimization(_foo_closure); %PrepareFunctionForOptimization(_foo_closure);
function foo(x, y, z) { function foo(x, y, z) {
return foo_closure().apply(null, [x, y, z]); return foo_closure().apply(null, ["", x, y, z]);
} }
%PrepareFunctionForOptimization(foo_closure); %PrepareFunctionForOptimization(foo_closure);
...@@ -376,15 +376,15 @@ ...@@ -376,15 +376,15 @@
(function () { (function () {
"use strict"; "use strict";
var sum_got_interpreted = true; var sum_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_got_interpreted = %IsBeingInterpreted(); sum_got_interpreted = %IsBeingInterpreted();
return this.x + a + b + c; return this.x + a + b + c + d;
} }
function foo(x, y, z) { function foo(x, y, z) {
return sum_js3.bind({ x: 42 }).apply(null, [x, y, z]); return sum_js.bind({ x: 42 }).apply(null, ["", x, y, z]);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('42abc', foo('a', 'b', 'c')); assertEquals('42abc', foo('a', 'b', 'c'));
assertTrue(sum_got_interpreted); assertTrue(sum_got_interpreted);
...@@ -399,12 +399,12 @@ ...@@ -399,12 +399,12 @@
(function () { (function () {
"use strict"; "use strict";
var sum_got_interpreted = true; var sum_got_interpreted = true;
function sum_js(a, b, c, d, e) { function sum_js(a, b, c, d, e, f) {
sum_got_interpreted = %IsBeingInterpreted(); sum_got_interpreted = %IsBeingInterpreted();
return this.x + a + b + c + d + e; return this.x + a + b + c + d + e + f;
} }
function foo(x, y, z) { function foo(x, y, z) {
return sum_js.bind({ x: 3 }, 11, 31).apply(null, [x, y, z]); return sum_js.bind({ x: 3 }, 11, 31).apply(null, ["", x, y, z]);
} }
%PrepareFunctionForOptimization(sum_js); %PrepareFunctionForOptimization(sum_js);
...@@ -422,20 +422,20 @@ ...@@ -422,20 +422,20 @@
(function () { (function () {
"use strict"; "use strict";
var sum_js_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js(a, b, c) { function sum_js(a, b, c, d) {
sum_js_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c + arguments.length; return a + b + c + d + arguments.length;
} }
function foo(x, y) { function foo(x, y) {
return sum_js.apply(null, [x, y]); return sum_js.apply(null, ["", x, y]);
} }
%PrepareFunctionForOptimization(sum_js); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('ABundefined2', foo('A', 'B')); assertEquals('ABundefined3', foo('A', 'B'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals('ABundefined2', foo('A', 'B')); assertEquals('ABundefined3', foo('A', 'B'));
assertFalse(sum_js_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
...@@ -444,20 +444,20 @@ ...@@ -444,20 +444,20 @@
(function () { (function () {
"use strict"; "use strict";
var sum_js_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js(a, b, c) { function sum_js(a, b, c, d) {
sum_js_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c + arguments.length; return a + b + c + d + arguments.length;
} }
function foo(v, w, x, y, z) { function foo(v, w, x, y, z) {
return sum_js.apply(null, [v, w, x, y, z]); return sum_js.apply(null, ["", v, w, x, y, z]);
} }
%PrepareFunctionForOptimization(sum_js); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('abc5', foo('a', 'b', 'c', 'd', 'e')); assertEquals('abc6', foo('a', 'b', 'c', 'd', 'e'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals('abc5', foo('a', 'b', 'c', 'd', 'e')); assertEquals('abc6', foo('a', 'b', 'c', 'd', 'e'));
assertFalse(sum_js_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
...@@ -466,21 +466,21 @@ ...@@ -466,21 +466,21 @@
(function () { (function () {
"use strict"; "use strict";
var sum_js_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js(a, b, c) { function sum_js(a, b, c, d) {
sum_js_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c + arguments.length; return a + b + c + d + arguments.length;
} }
function foo(x, y) { function foo(x, y) {
const numbers = [x, y]; const numbers = ["", x, y];
return sum_js(...numbers); return sum_js(...numbers);
} }
%PrepareFunctionForOptimization(sum_js); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('ABundefined2', foo('A', 'B')); assertEquals('ABundefined3', foo('A', 'B'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals('ABundefined2', foo('A', 'B')); assertEquals('ABundefined3', foo('A', 'B'));
assertFalse(sum_js_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
...@@ -488,23 +488,23 @@ ...@@ -488,23 +488,23 @@
// Test call with spread over-application. // Test call with spread over-application.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c + arguments.length; return a + b + c + d + arguments.length;
} }
function foo(v, w, x, y, z) { function foo(v, w, x, y, z) {
const numbers = [v, w, x, y, z]; const numbers = ["", v, w, x, y, z];
return sum_js3(...numbers); return sum_js(...numbers);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('abc5', foo('a', 'b', 'c', 'd', 'e')); assertEquals('abc6', foo('a', 'b', 'c', 'd', 'e'));
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertEquals('abc5', foo('a', 'b', 'c', 'd', 'e')); assertEquals('abc6', foo('a', 'b', 'c', 'd', 'e'));
assertFalse(sum_js3_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
...@@ -514,10 +514,10 @@ ...@@ -514,10 +514,10 @@
var sum_js_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js(a, b, ...moreArgs) { function sum_js(a, b, ...moreArgs) {
sum_js_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + moreArgs[0] + moreArgs[1] + moreArgs[2]; return a + b + moreArgs[0] + moreArgs[1] + moreArgs[2] + moreArgs[3];
} }
function foo(v, w, x, y, z) { function foo(v, w, x, y, z) {
return sum_js.apply(null, [v, w, x, y, z]); return sum_js.apply(null, ["", v, w, x, y, z]);
} }
%PrepareFunctionForOptimization(sum_js); %PrepareFunctionForOptimization(sum_js);
...@@ -533,51 +533,51 @@ ...@@ -533,51 +533,51 @@
// Test with 'arguments'. // Test with 'arguments'.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c;
} }
function foo() { function foo() {
return sum_js3.apply(null, arguments); return sum_js.apply(null, arguments);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
// The call is not inlined with CreateArguments. // The call is not inlined with CreateArguments.
%OptimizeFunctionOnNextCall(foo); %OptimizeFunctionOnNextCall(foo);
assertEquals('abc', foo('a', 'b', 'c')); assertEquals('abc', foo('a', 'b', 'c'));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
assertOptimized(foo); assertOptimized(foo);
})(); })();
// Test with inlined calls. // Test with inlined calls.
(function () { (function () {
"use strict"; "use strict";
var sum_js3_got_interpreted = true; var sum_js_got_interpreted = true;
function sum_js3(a, b, c) { function sum_js(a, b, c, d) {
sum_js3_got_interpreted = %IsBeingInterpreted(); sum_js_got_interpreted = %IsBeingInterpreted();
return a + b + c; return a + b + c + d;
} }
function foo(x, y, z) { function foo(x, y, z) {
return sum_js3.apply(null, [x, y, z]); return sum_js.apply(null, ["", x, y, z]);
} }
function bar(a, b, c) { function bar(a, b, c) {
return foo(c, b, a); return foo(c, b, a);
} }
%PrepareFunctionForOptimization(sum_js3); %PrepareFunctionForOptimization(sum_js);
%PrepareFunctionForOptimization(foo); %PrepareFunctionForOptimization(foo);
%PrepareFunctionForOptimization(bar); %PrepareFunctionForOptimization(bar);
assertEquals('cba', bar('a', 'b', 'c')); assertEquals('cba', bar('a', 'b', 'c'));
assertTrue(sum_js3_got_interpreted); assertTrue(sum_js_got_interpreted);
// Optimization also works if the call is in an inlined function. // Optimization also works if the call is in an inlined function.
%OptimizeFunctionOnNextCall(bar); %OptimizeFunctionOnNextCall(bar);
assertEquals('cba', bar('a', 'b', 'c')); assertEquals('cba', bar('a', 'b', 'c'));
assertFalse(sum_js3_got_interpreted); assertFalse(sum_js_got_interpreted);
assertOptimized(bar); assertOptimized(bar);
})(); })();
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