2018-01-25 09:35:39 +00:00
|
|
|
// Copyright 2018 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.
|
|
|
|
|
|
|
|
// Flags: --allow-natives-syntax
|
|
|
|
|
|
|
|
|
|
|
|
function f1() {
|
|
|
|
const x = [,];
|
|
|
|
x[1] = 42;
|
2022-12-09 08:56:42 +00:00
|
|
|
assertEquals([, 42], x);
|
2018-01-25 09:35:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-14 10:59:02 +00:00
|
|
|
%PrepareFunctionForOptimization(f1);
|
2018-01-25 09:35:39 +00:00
|
|
|
f1();
|
|
|
|
f1();
|
|
|
|
%OptimizeFunctionOnNextCall(f1);
|
|
|
|
f1();
|
|
|
|
f1();
|
|
|
|
|
|
|
|
|
|
|
|
function f2() {
|
|
|
|
const x = [0];
|
|
|
|
for (const y of [1, 2, 3, 4]) {
|
|
|
|
x[x.length] = y;
|
|
|
|
}
|
|
|
|
assertEquals([0, 1, 2, 3, 4], x);
|
|
|
|
}
|
|
|
|
|
2019-06-14 10:59:02 +00:00
|
|
|
%PrepareFunctionForOptimization(f2);
|
2018-01-25 09:35:39 +00:00
|
|
|
f2();
|
|
|
|
f2();
|
|
|
|
%OptimizeFunctionOnNextCall(f2);
|
|
|
|
f2();
|
|
|
|
f2();
|
|
|
|
|
|
|
|
|
|
|
|
function f3() {
|
|
|
|
const x = [0];
|
|
|
|
for (const y of [1.1, {}]) {
|
|
|
|
x[x.length] = y;
|
|
|
|
}
|
|
|
|
assertEquals([0, 1.1, {}], x);
|
|
|
|
}
|
|
|
|
|
2019-06-14 10:59:02 +00:00
|
|
|
%PrepareFunctionForOptimization(f3);
|
2018-01-25 09:35:39 +00:00
|
|
|
f3();
|
|
|
|
f3();
|
|
|
|
%OptimizeFunctionOnNextCall(f3);
|
|
|
|
f3();
|
|
|
|
f3();
|
|
|
|
|
|
|
|
|
|
|
|
function f4(x) {
|
|
|
|
x[x.length] = x.length;
|
|
|
|
}
|
|
|
|
|
2019-06-14 10:59:02 +00:00
|
|
|
%PrepareFunctionForOptimization(f4);
|
2018-01-25 09:35:39 +00:00
|
|
|
let x1 = [];
|
|
|
|
f4(x1);
|
|
|
|
assertEquals([0], x1);
|
|
|
|
f4(x1);
|
|
|
|
assertEquals([0, 1], x1);
|
|
|
|
%OptimizeFunctionOnNextCall(f4);
|
|
|
|
f4(x1);
|
|
|
|
assertEquals([0, 1, 2], x1);
|
|
|
|
f4(x1);
|
|
|
|
assertEquals([0, 1, 2, 3], x1);
|
|
|
|
|
2019-06-14 10:59:02 +00:00
|
|
|
%PrepareFunctionForOptimization(f4);
|
2018-01-25 09:35:39 +00:00
|
|
|
let x2 = {length: 42};
|
|
|
|
f4(x2);
|
|
|
|
assertEquals(42, x2[42]);
|
|
|
|
f4(x2);
|
|
|
|
assertEquals(42, x2[42]);
|
|
|
|
%OptimizeFunctionOnNextCall(f4);
|
|
|
|
f4(x2);
|
|
|
|
assertEquals(42, x2[42]);
|
|
|
|
f4(x2);
|
|
|
|
assertEquals(42, x2[42]);
|