Improve test coverage for non-extensible array when possible

Bug: v8:6831
Change-Id: I7d51a49dfbf2e5a1fa2675fe0d70bb4091a4db78
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1544274
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#60611}
This commit is contained in:
Z Duong Nguyen-Huu 2019-03-28 11:33:13 -07:00 committed by Commit Bot
parent be83fea988
commit 9d2f267f42
5 changed files with 149 additions and 34 deletions

View File

@ -35,3 +35,45 @@
assertEquals(42, foo());
assertUnoptimized(foo);
})();
// Non-extensible
(function() {
const a = Object.preventExtensions([1, 2, 3]);
const foo = () => a[0];
%PrepareFunctionForOptimization(foo);
assertEquals(1, foo());
assertEquals(1, foo());
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo());
assertOptimized(foo);
a[0] = 42;
assertEquals(42, foo());
})();
// Sealed
(function() {
const a = Object.seal([1, 2, 3]);
const foo = () => a[0];
%PrepareFunctionForOptimization(foo);
assertEquals(1, foo());
assertEquals(1, foo());
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo());
assertOptimized(foo);
a[0] = 42;
assertEquals(42, foo());
})();
// Frozen
(function() {
const a = Object.freeze([1, 2, 3]);
const foo = () => a[0];
%PrepareFunctionForOptimization(foo);
assertEquals(1, foo());
assertEquals(1, foo());
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo());
assertOptimized(foo);
a[0] = 42;
assertEquals(1, foo());
})();

View File

@ -16,11 +16,27 @@ function f(a) {
return sum;
}
var a = new Array(10000);
for (var i = 0; i < 10000; i++) {
a[i] = (i * 999) % 77;
}
function test(a) {
for (var i = 0; i < 10000; i++) {
a[i] = (i * 999) % 77;
}
for (var i = 0; i < 3; i++) {
assertEquals(480270, f(a));
for (var i = 0; i < 3; i++) {
console.log(f(a));
assertEquals(480270, f(a));
}
}
var a = new Array(10000);
test(a);
// Non-extensible
var b = Object.preventExtensions(a);
test(b);
// Sealed
var c = Object.seal(a);
test(c);
// Frozen
var d = Object.freeze(a);
test(d);

View File

@ -15,15 +15,6 @@ function f(a) {
return sum;
}
var a = new Array(10000);
for (var i = 0; i < 10000; i++) {
a[i] = (i * 999) % 77;
}
for (var i = 0; i < 3; i++) {
assertEquals(480270, f(wrap(a)));
}
function wrap(array) {
var iterable = {};
var i = 0;
@ -33,3 +24,28 @@ function wrap(array) {
iterable[Symbol.iterator] = function() { return { next:next }; };
return iterable;
}
function test(a) {
for (var i = 0; i < 10000; i++) {
a[i] = (i * 999) % 77;
}
for (var i = 0; i < 3; i++) {
assertEquals(480270, f(wrap(a)));
}
}
var a = new Array(10000);
test(a);
// Non-extensible
var b = Object.preventExtensions(a);
test(b);
// Sealed
var c = Object.seal(a);
test(c);
// Frozen
var d = Object.freeze(a);
test(d);

View File

@ -406,8 +406,22 @@ for (test in tests) {
}
var ary = [0,1,2,3];
assertTrue(test(ary, 1));
assertTrue(test(ary, 1));
function testArray(ary) {
assertTrue(test(ary, 1));
assertTrue(test(ary, 1));
}
testArray(ary);
// Non-extensible
var b = Object.preventExtensions(ary);
testArray(b);
// Sealed
var c = Object.seal(ary);
testArray(c);
// Frozen
var d = Object.freeze(ary);
testArray(d);
var str = "string";
assertFalse(test(str, 0));
@ -418,7 +432,7 @@ for (test in tests) {
const heap_constant_ary = [0,1,2,3];
(function() {
function testHeapConstantArray(heap_constant_ary) {
function test() {
return 1 in heap_constant_ary;
@ -433,5 +447,17 @@ const heap_constant_ary = [0,1,2,3];
assertTrue(test());
%OptimizeFunctionOnNextCall(test);
assertTrue(test());
}
testHeapConstantArray(heap_constant_ary);
})()
// Non-extensible
var b = Object.preventExtensions(heap_constant_ary);
testHeapConstantArray(b);
// Sealed
var c = Object.seal(heap_constant_ary);
testHeapConstantArray(c);
// Frozen
var d = Object.freeze(heap_constant_ary);
testHeapConstantArray(d);

View File

@ -150,24 +150,39 @@ runTest();
runTest = function() {
var o = [ 42, 43 ];
var initial_X = 0;
var X = initial_X;
var Y = 1;
function test(o) {
var initial_X = 0;
var X = initial_X;
var Y = 1;
function fieldTest(change_index) {
for (var i = 0; i < 10; i++) {
var property = o[X];
if (i <= change_index) {
assertEquals(42, property);
} else {
assertEquals(43, property);
function fieldTest(change_index) {
for (var i = 0; i < 10; i++) {
var property = o[X];
if (i <= change_index) {
assertEquals(42, property);
} else {
assertEquals(43, property);
}
if (i == change_index) X = Y;
}
if (i == change_index) X = Y;
}
X = initial_X;
};
X = initial_X;
};
for (var i = 0; i < 10; i++) fieldTest(i);
for (var i = 0; i < 10; i++) fieldTest(i);
}
test(o);
// Non-extensible
var b = Object.preventExtensions(o);
test(b);
// Sealed
var c = Object.seal(o);
test(c);
// Frozen
var d = Object.freeze(o);
test(d);
}
runTest();