Commit 34e1c071 authored by Z Duong Nguyen-Huu's avatar Z Duong Nguyen-Huu Committed by Commit Bot

Improve test coverage for non-extensible array in optimized code

This cover all test files under mjsunit/compiler/array-*

Bug: v8:6831
Change-Id: I7a5632ccb3895a6e23ebfb92598dd1939de133b1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1531030
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60484}
parent 52d14460
......@@ -130,3 +130,32 @@ for (var i = 0; i < 1000; i++) {
}
RunArrayBoundsCheckTest();
// Non-extensible
a = Object.seal([0,0,0]);
o = Object.seal({0: 0, 1: 0, 2: 0});
for (var i = 0; i < 1000; i++) {
RunGetTests();
RunSetTests(a);
RunSetTests(o);
}
RunArrayBoundsCheckTest();
// Sealed
a = Object.seal([0,0,0]);
o = Object.seal({0: 0, 1: 0, 2: 0});
for (var i = 0; i < 1000; i++) {
RunGetTests();
RunSetTests(a);
RunSetTests(o);
}
RunArrayBoundsCheckTest();
// Frozen
a = Object.seal([0,0,0]);
o = Object.seal({0: 0, 1: 0, 2: 0});
for (var i = 0; i < 1000; i++) {
RunGetTests();
}
......@@ -107,3 +107,42 @@
assertEquals([], foo(0));
assertInstanceof(foo(-1), RangeError);
})();
// Test non-extensible Array call with multiple parameters.
(() => {
function foo(x, y, z) { return Object.preventExtensions(new Array(x, y, z)); }
%PrepareFunctionForOptimization(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertEquals([1, 2, 3], foo(1, 2, 3));
assertFalse(Object.isExtensible(foo(1,2,3)));
%OptimizeFunctionOnNextCall(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertFalse(Object.isExtensible(foo(1,2,3)));
})();
// Test sealed Array call with multiple parameters.
(() => {
function foo(x, y, z) { return Object.seal(new Array(x, y, z)); }
%PrepareFunctionForOptimization(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertEquals([1, 2, 3], foo(1, 2, 3));
assertTrue(Object.isSealed(foo(1,2,3)));
%OptimizeFunctionOnNextCall(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertTrue(Object.isSealed(foo(1,2,3)));
})();
// Test frozen Array call with multiple parameters.
(() => {
function foo(x, y, z) { return Object.freeze(new Array(x, y, z)); }
%PrepareFunctionForOptimization(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertEquals([1, 2, 3], foo(1, 2, 3));
assertTrue(Object.isFrozen(foo(1,2,3)));
%OptimizeFunctionOnNextCall(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertTrue(Object.isFrozen(foo(1,2,3)));
})();
......@@ -16,4 +16,28 @@
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo([3, 3, 3], {x:3}));
assertFalse(foo([3, 3, 2], {x:3}));
// Non-extensible array
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.preventExtensions([3, 3, 3]), {x:3}));
assertFalse(foo(Object.preventExtensions([3, 3, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.preventExtensions([3, 3, 3]), {x:3}));
assertFalse(foo(Object.preventExtensions([3, 3, 2]), {x:3}));
// Sealed array
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.seal([3, 3, 3]), {x:3}));
assertFalse(foo(Object.seal([3, 3, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.seal([3, 3, 3]), {x:3}));
assertFalse(foo(Object.seal([3, 3, 2]), {x:3}));
// Frozen array
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.freeze([3, 3, 3]), {x:3}));
assertFalse(foo(Object.freeze([3, 3, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.freeze([3, 3, 3]), {x:3}));
assertFalse(foo(Object.freeze([3, 3, 2]), {x:3}));
})();
......@@ -16,4 +16,28 @@
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo([1, 2, 3], {x:3}));
assertEquals(undefined, foo([0, 1, 2], {x:3}));
// Non-extensible
%PrepareFunctionForOptimization(foo);
assertEquals(3, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
// Sealed
%PrepareFunctionForOptimization(foo);
assertEquals(3, foo(Object.seal([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.seal([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo(Object.seal([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.seal([0, 1, 2]), {x:3}));
// Frozen
%PrepareFunctionForOptimization(foo);
assertEquals(3, foo(Object.freeze([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.freeze([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo(Object.freeze([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.freeze([0, 1, 2]), {x:3}));
})();
......@@ -16,4 +16,28 @@
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo([1, 2, 3], {x:3}));
assertEquals(-1, foo([0, 1, 2], {x:3}));
// Non-extensible
%PrepareFunctionForOptimization(foo);
assertEquals(2, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
// Sealed
%PrepareFunctionForOptimization(foo);
assertEquals(2, foo(Object.seal([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.seal([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo(Object.seal([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.seal([0, 1, 2]), {x:3}));
// Frozen
%PrepareFunctionForOptimization(foo);
assertEquals(2, foo(Object.freeze([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.freeze([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo(Object.freeze([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.freeze([0, 1, 2]), {x:3}));
})();
......@@ -109,3 +109,45 @@
assertInstanceof(foo([]), TypeError);
assertInstanceof(foo({}), TypeError);
})();
// Test JSObjectIsArray in JSTypedLowering for the case that the
// input value is known to be a non-extensible Array literal.
(function() {
function foo() {
return Array.isArray(Object.preventExtensions([]));
}
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
// Test JSObjectIsArray in JSTypedLowering for the case that the
// input value is known to be a sealed Array literal.
(function() {
function foo() {
return Array.isArray(Object.seal([]));
}
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
// Test JSObjectIsArray in JSTypedLowering for the case that the
// input value is known to be a frozen Array literal.
(function() {
function foo() {
return Array.isArray(Object.freeze([]));
}
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
......@@ -38,16 +38,36 @@ function Test(a0, a2, a5) {
var a0 = [];
var a2 = [1,2];
var a5 = [1,2,3,4,5];
%PrepareFunctionForOptimization(ArrayLength);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(ArrayLength);
Test(a0, a2, a5);
%PrepareFunctionForOptimization(Test);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals("undefined", typeof(ArrayLength(0)));
%PrepareFunctionForOptimization(Test);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals(4, ArrayLength("hest"));
function MainTest() {
%PrepareFunctionForOptimization(ArrayLength);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(ArrayLength);
Test(a0, a2, a5);
%PrepareFunctionForOptimization(Test);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals("undefined", typeof(ArrayLength(0)));
%PrepareFunctionForOptimization(Test);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals(4, ArrayLength("hest"));
}
MainTest();
// Non-extensible, sealed, frozen
a0 = Object.preventExtensions([]);
a2 = Object.seal([1,2]);
a5 = Object.freeze([1,2,3,4,5]);
MainTest();
a0 = Object.seal([]);
a2 = Object.freeze([1,2]);
a5 = Object.preventExtensions([1,2,3,4,5]);
MainTest();
a0 = Object.freeze([]);
a2 = Object.preventExtensions([1,2]);
a5 = Object.seal([1,2,3,4,5]);
MainTest();
......@@ -398,3 +398,43 @@
assertNotEquals(Object.getOwnPropertyDescriptor(narr, 1), undefined);
assertEquals(narr, [6,6,6]);
})();
// Trigger JSCallReducer on slice() and slice(0)
(function() {
// Non-extensible:
var arr = Object.preventExtensions([1,2,3,4,5]);
function slice() {
return arr.slice();
}
function slice0() {
return arr.slice(0);
}
function test() {
%PrepareFunctionForOptimization(slice0);
assertEquals(arr, slice());
assertFalse(arr === slice());
assertEquals(slice(), slice0());
assertEquals(slice0(), slice());
%OptimizeFunctionOnNextCall(slice0);
assertEquals(slice(), slice0());
%PrepareFunctionForOptimization(slice);
%OptimizeFunctionOnNextCall(slice);
assertEquals(slice(), slice0());
assertOptimized(slice); assertOptimized(slice0);
}
test();
// Sealed
arr = Object.seal([1,2,3,4,5]);
test();
// Frozen
arr = Object.freeze([1,2,3,4,5]);
test();
})();
......@@ -16,4 +16,28 @@
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo([1, 2, 3], {x:3}));
assertFalse(foo([0, 1, 2], {x:3}));
// Non-extensible
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertFalse(foo(Object.preventExtensions([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertFalse(foo(Object.preventExtensions([0, 1, 2]), {x:3}));
// Sealed
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.seal([1, 2, 3]), {x:3}));
assertFalse(foo(Object.seal([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.seal([1, 2, 3]), {x:3}));
assertFalse(foo(Object.seal([0, 1, 2]), {x:3}));
// Frozen
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.freeze([1, 2, 3]), {x:3}));
assertFalse(foo(Object.freeze([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.freeze([1, 2, 3]), {x:3}));
assertFalse(foo(Object.freeze([0, 1, 2]), {x:3}));
})();
This diff is collapsed.
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