2017-02-03 09:25:16 +00:00
|
|
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-06-22 13:46:04 +00:00
|
|
|
// Flags: --allow-natives-syntax
|
2017-02-03 09:25:16 +00:00
|
|
|
|
|
|
|
(function MaterializeStrictArguments() {
|
|
|
|
"use strict"
|
|
|
|
|
|
|
|
function f(x, y) {
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
2017-02-28 11:16:27 +00:00
|
|
|
function test1() {
|
2017-02-03 09:25:16 +00:00
|
|
|
%DeoptimizeNow();
|
|
|
|
return f.apply(null, arguments);
|
|
|
|
}
|
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(test1);
|
2017-02-28 11:16:27 +00:00
|
|
|
assertEquals(test1(1, 2), 3);
|
|
|
|
assertEquals(test1(1, 2, 3), 3);
|
2017-02-03 09:25:16 +00:00
|
|
|
|
2017-02-28 11:16:27 +00:00
|
|
|
%OptimizeFunctionOnNextCall(test1);
|
|
|
|
assertEquals(test1(1, 2), 3);
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(test1);
|
2017-02-28 11:16:27 +00:00
|
|
|
%OptimizeFunctionOnNextCall(test1);
|
|
|
|
assertEquals(test1(1, 2, 3), 3);
|
2017-02-03 09:25:16 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function MaterializeSloppyArguments() {
|
|
|
|
function f(x, y) {
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
2017-02-28 11:16:27 +00:00
|
|
|
function test2() {
|
2017-02-03 09:25:16 +00:00
|
|
|
%DeoptimizeNow();
|
|
|
|
return f.apply(null, arguments);
|
|
|
|
}
|
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(test2);
|
2017-02-28 11:16:27 +00:00
|
|
|
assertEquals(test2(1, 2), 3);
|
|
|
|
assertEquals(test2(1, 2, 3), 3);
|
2017-02-03 09:25:16 +00:00
|
|
|
|
2017-02-28 11:16:27 +00:00
|
|
|
%OptimizeFunctionOnNextCall(test2);
|
|
|
|
assertEquals(test2(1, 2), 3);
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(test2);
|
2017-02-28 11:16:27 +00:00
|
|
|
%OptimizeFunctionOnNextCall(test2);
|
|
|
|
assertEquals(test2(1, 2, 3), 3);
|
2017-02-03 09:25:16 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function MaterializeStrictOverwrittenArguments() {
|
|
|
|
"use strict"
|
|
|
|
|
|
|
|
function f(x, y) {
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
2017-02-28 11:16:27 +00:00
|
|
|
function test3(a, b) {
|
2017-02-03 09:25:16 +00:00
|
|
|
a = 4;
|
|
|
|
%DeoptimizeNow();
|
|
|
|
return f.apply(null, arguments);
|
|
|
|
}
|
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(test3);
|
2017-02-28 11:16:27 +00:00
|
|
|
assertEquals(test3(1, 2), 3);
|
|
|
|
assertEquals(test3(1, 2, 3), 3);
|
2017-02-03 09:25:16 +00:00
|
|
|
|
2017-02-28 11:16:27 +00:00
|
|
|
%OptimizeFunctionOnNextCall(test3);
|
|
|
|
assertEquals(test3(11, 12), 23);
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(test3);
|
2017-02-28 11:16:27 +00:00
|
|
|
%OptimizeFunctionOnNextCall(test3);
|
|
|
|
assertEquals(test3(11, 12, 13), 23);
|
2017-02-03 09:25:16 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function MaterializeSloppyOverwrittenArguments() {
|
|
|
|
function f(x, y) {
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
2017-02-28 11:16:27 +00:00
|
|
|
function test4(a, b) {
|
2017-02-03 09:25:16 +00:00
|
|
|
a = 4;
|
|
|
|
%DeoptimizeNow();
|
|
|
|
return f.apply(null, arguments);
|
|
|
|
}
|
|
|
|
|
2017-02-28 11:16:27 +00:00
|
|
|
test4(1, 2);
|
|
|
|
test4(3, 4, 5);
|
2017-02-03 09:25:16 +00:00
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(test4);
|
2017-02-28 11:16:27 +00:00
|
|
|
assertEquals(test4(1, 2), 6);
|
|
|
|
assertEquals(test4(1, 2, 3), 6);
|
2017-02-03 09:25:16 +00:00
|
|
|
|
2017-02-28 11:16:27 +00:00
|
|
|
%OptimizeFunctionOnNextCall(test4);
|
|
|
|
assertEquals(test4(1, 2), 6);
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(test4);
|
2017-02-28 11:16:27 +00:00
|
|
|
%OptimizeFunctionOnNextCall(test4);
|
|
|
|
assertEquals(test4(1, 2, 3), 6);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function ArgumentsAccessStrict () {
|
|
|
|
"use strict"
|
|
|
|
function sum1(a,b,c) {
|
|
|
|
var sum = 0;
|
|
|
|
var rest = arguments;
|
|
|
|
for (var i = 0; i < rest.length; ++i) {
|
|
|
|
var j = i;
|
2017-03-03 13:43:40 +00:00
|
|
|
if (rest.length % 15 == 0 && i == 10) j += 10000;
|
|
|
|
sum += rest[j] || i+1;
|
2017-02-28 11:16:27 +00:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
};
|
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(sum1);
|
2017-02-28 11:16:27 +00:00
|
|
|
var args = []
|
|
|
|
for (var i = 1; i < 30; ++i) {
|
|
|
|
args.push(i);
|
|
|
|
if (i%10 == 0) %OptimizeFunctionOnNextCall(sum1);
|
|
|
|
assertEquals(i*(i+1)/2, sum1(...args));
|
2019-06-17 16:13:52 +00:00
|
|
|
if (i%10 == 0) %PrepareFunctionForOptimization(sum1);
|
2017-02-28 11:16:27 +00:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function ArgumentsAccessSloppy () {
|
|
|
|
function sum2(a,b,c) {
|
|
|
|
var sum = 0;
|
2017-03-03 13:43:40 +00:00
|
|
|
for (var i = 0; i < arguments.length; ++i) {
|
2017-02-28 11:16:27 +00:00
|
|
|
var j = i;
|
2017-03-03 13:43:40 +00:00
|
|
|
if (arguments.length % 15 == 0 && i == 10) j += 10000;
|
|
|
|
sum += arguments[j] || i+1;
|
2017-02-28 11:16:27 +00:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
};
|
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(sum2);
|
2017-02-28 11:16:27 +00:00
|
|
|
var args = []
|
|
|
|
for (var i = 1; i < 30; ++i) {
|
|
|
|
args.push(i);
|
|
|
|
if (i%10 == 0) %OptimizeFunctionOnNextCall(sum2);
|
|
|
|
assertEquals(i*(i+1)/2, sum2(...args));
|
2019-06-17 16:13:52 +00:00
|
|
|
if (i%10 == 0) %PrepareFunctionForOptimization(sum2);
|
2017-02-28 11:16:27 +00:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function RestAccess0 () {
|
|
|
|
function sum3(...rest) {
|
|
|
|
var sum = 0;
|
|
|
|
for (var i = 0; i < rest.length; ++i) {
|
|
|
|
var j = i;
|
2017-03-03 13:43:40 +00:00
|
|
|
if (rest.length % 15 == 0 && i == 10) j += 10000;
|
|
|
|
sum += rest[j] || i+1;
|
2017-02-28 11:16:27 +00:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
};
|
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(sum3);
|
2017-02-28 11:16:27 +00:00
|
|
|
var args = []
|
|
|
|
for (var i = 1; i < 30; ++i) {
|
|
|
|
args.push(i);
|
|
|
|
if (i%10 == 0) %OptimizeFunctionOnNextCall(sum3);
|
|
|
|
assertEquals(i*(i+1)/2, sum3(...args));
|
2019-06-17 16:13:52 +00:00
|
|
|
if (i%10 == 0) %PrepareFunctionForOptimization(sum3);
|
2017-02-28 11:16:27 +00:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function RestAccess1 () {
|
|
|
|
function sum4(a,...rest) {
|
|
|
|
var sum = 0;
|
|
|
|
for (var i = 0; i < rest.length; ++i) {
|
|
|
|
var j = i;
|
2017-03-03 13:43:40 +00:00
|
|
|
if (rest.length % 15 == 0 && i == 10) j += 10000;
|
|
|
|
sum += rest[j] || i+2;
|
2017-02-28 11:16:27 +00:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
};
|
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(sum4);
|
2017-02-28 11:16:27 +00:00
|
|
|
var args = []
|
|
|
|
for (var i = 1; i < 30; ++i) {
|
|
|
|
args.push(i);
|
|
|
|
if (i%10 == 0) %OptimizeFunctionOnNextCall(sum4);
|
|
|
|
assertEquals(i*(i+1)/2-1, sum4(...args));
|
2019-06-17 16:13:52 +00:00
|
|
|
if (i%10 == 0) %PrepareFunctionForOptimization(sum4);
|
2017-02-28 11:16:27 +00:00
|
|
|
}
|
2017-02-03 09:25:16 +00:00
|
|
|
})();
|
2017-03-03 13:43:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
(function ReadArguments () {
|
|
|
|
function read() {
|
|
|
|
if (arguments.length % 10 == 5) %DeoptimizeNow();
|
|
|
|
return arguments[arguments.length-1];
|
|
|
|
};
|
|
|
|
|
2019-05-03 12:48:33 +00:00
|
|
|
%PrepareFunctionForOptimization(read);
|
2017-03-03 13:43:40 +00:00
|
|
|
var args = []
|
|
|
|
for (var i = 1; i < 30; ++i) {
|
|
|
|
args.push(i);
|
|
|
|
if (i%10 == 0) %OptimizeFunctionOnNextCall(read);
|
|
|
|
assertEquals(i, read(...args));
|
2019-06-17 16:13:52 +00:00
|
|
|
if (i%10 == 0) %PrepareFunctionForOptimization(read);
|
2017-03-03 13:43:40 +00:00
|
|
|
}
|
|
|
|
})();
|