Skip to content

Commit 81dd67d

Browse files
duongnhnCommit Bot
authored andcommitted
Improve test coverage for non-extensible holey array in optimized code
Bug: v8:6831 Change-Id: Icb4b504771e623b3c9503c6daffd7b771fbef3a6 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1575036 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com> Cr-Commit-Position: refs/heads/master@{#60990}
1 parent 6ee0c87 commit 81dd67d

12 files changed

Lines changed: 551 additions & 107 deletions

test/mjsunit/compiler/array-access.js

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,43 @@ function GetAAN(a,n) {
4545
return a[a[a[n]]];
4646
}
4747

48-
function RunGetTests() {
49-
var a = [2,0,1];
50-
assertEquals(2, Get0(a));
48+
function RunGetTests(packed=true) {
49+
if (packed) {
50+
var a = [2,0,1];
51+
assertEquals(2, Get0(a));
5152

52-
assertEquals(2, GetN(a, 0));
53-
assertEquals(0, GetN(a, 1));
54-
assertEquals(1, GetN(a, 2));
53+
assertEquals(2, GetN(a, 0));
54+
assertEquals(0, GetN(a, 1));
55+
assertEquals(1, GetN(a, 2));
5556

56-
assertEquals(1, GetA0(a));
57+
assertEquals(1, GetA0(a));
5758

58-
assertEquals(1, GetAN(a,0));
59-
assertEquals(2, GetAN(a,1));
60-
assertEquals(0, GetAN(a,2));
59+
assertEquals(1, GetAN(a,0));
60+
assertEquals(2, GetAN(a,1));
61+
assertEquals(0, GetAN(a,2));
6162

62-
assertEquals(0, GetAAN(a,0));
63-
assertEquals(1, GetAAN(a,1));
64-
assertEquals(2, GetAAN(a,2));
63+
assertEquals(0, GetAAN(a,0));
64+
assertEquals(1, GetAAN(a,1));
65+
assertEquals(2, GetAAN(a,2));
66+
}
67+
else {
68+
var a = ['2','0','1'];
69+
assertEquals('2', Get0(a));
70+
71+
assertEquals('2', GetN(a, 0));
72+
assertEquals('0', GetN(a, 1));
73+
assertEquals('1', GetN(a, 2));
74+
75+
assertEquals('1', GetA0(a));
76+
77+
assertEquals('1', GetAN(a,0));
78+
assertEquals('2', GetAN(a,1));
79+
assertEquals('0', GetAN(a,2));
80+
81+
assertEquals('0', GetAAN(a,0));
82+
assertEquals('1', GetAAN(a,1));
83+
assertEquals('2', GetAAN(a,2));
84+
}
6585
}
6686

6787

@@ -81,29 +101,39 @@ function SetNX(a, n, x) {
81101
a[n] = x;
82102
}
83103

84-
function RunSetTests(a) {
104+
function RunSetTests(a, packed=true) {
85105
Set07(a);
86-
assertEquals(7, a[0]);
106+
if (packed) {
107+
assertEquals(7, a[0]);
108+
}
87109
assertEquals(0, a[1]);
88110
assertEquals(0, a[2]);
89111

90112
Set0V(a, 1);
91-
assertEquals(1, a[0]);
113+
if (packed) {
114+
assertEquals(1, a[0]);
115+
}
92116
assertEquals(0, a[1]);
93117
assertEquals(0, a[2]);
94118

95119
SetN7(a, 2);
96-
assertEquals(1, a[0]);
120+
if (packed) {
121+
assertEquals(1, a[0]);
122+
}
97123
assertEquals(0, a[1]);
98124
assertEquals(7, a[2]);
99125

100126
SetNX(a, 1, 5);
101-
assertEquals(1, a[0]);
127+
if (packed) {
128+
assertEquals(1, a[0]);
129+
}
102130
assertEquals(5, a[1]);
103131
assertEquals(7, a[2]);
104132

105133
for (var i = 0; i < 3; i++) SetNX(a, i, 0);
106-
assertEquals(0, a[0]);
134+
if (packed) {
135+
assertEquals(0, a[0]);
136+
}
107137
assertEquals(0, a[1]);
108138
assertEquals(0, a[2]);
109139
}
@@ -131,31 +161,55 @@ for (var i = 0; i < 1000; i++) {
131161

132162
RunArrayBoundsCheckTest();
133163

164+
// Packed
134165
// Non-extensible
135-
a = Object.seal([0,0,0]);
136-
o = Object.seal({0: 0, 1: 0, 2: 0});
166+
a = Object.preventExtensions([0,0,0,'a']);
167+
o = Object.preventExtensions({0: 0, 1: 0, 2: 0});
137168
for (var i = 0; i < 1000; i++) {
138169
RunGetTests();
170+
RunGetTests(false);
139171
RunSetTests(a);
140172
RunSetTests(o);
141173
}
142174

143-
RunArrayBoundsCheckTest();
144-
145175
// Sealed
146-
a = Object.seal([0,0,0]);
176+
a = Object.seal([0,0,0,'a']);
147177
o = Object.seal({0: 0, 1: 0, 2: 0});
148178
for (var i = 0; i < 1000; i++) {
149179
RunGetTests();
180+
RunGetTests(false);
150181
RunSetTests(a);
151182
RunSetTests(o);
152183
}
153184

154-
RunArrayBoundsCheckTest();
185+
// Frozen
186+
a = Object.freeze([0,0,0,'a']);
187+
o = Object.freeze({0: 0, 1: 0, 2: 0});
188+
for (var i = 0; i < 1000; i++) {
189+
RunGetTests();
190+
RunGetTests(false);
191+
}
192+
193+
// Holey
194+
// Non-extensible
195+
a = Object.preventExtensions([,0,0,'a']);
196+
for (var i = 0; i < 1000; i++) {
197+
RunGetTests();
198+
RunGetTests(false);
199+
RunSetTests(a, false);
200+
}
201+
202+
// Sealed
203+
a = Object.seal([,0,0,'a']);
204+
for (var i = 0; i < 1000; i++) {
205+
RunGetTests();
206+
RunGetTests(false);
207+
RunSetTests(a, false);
208+
}
155209

156210
// Frozen
157-
a = Object.seal([0,0,0]);
158-
o = Object.seal({0: 0, 1: 0, 2: 0});
211+
a = Object.freeze([,0,0,'a']);
159212
for (var i = 0; i < 1000; i++) {
160213
RunGetTests();
214+
RunGetTests(false);
161215
}

test/mjsunit/compiler/array-constructor.js

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,41 +108,82 @@
108108
assertInstanceof(foo(-1), RangeError);
109109
})();
110110

111+
// Packed
111112
// Test non-extensible Array call with multiple parameters.
112113
(() => {
113-
function foo(x, y, z) { return Object.preventExtensions(new Array(x, y, z)); }
114+
function foo(x, y, z, t) { return Object.preventExtensions(new Array(x, y, z, t)); }
114115

115116
%PrepareFunctionForOptimization(foo);
116-
assertEquals([1, 2, 3], foo(1, 2, 3));
117-
assertEquals([1, 2, 3], foo(1, 2, 3));
118-
assertFalse(Object.isExtensible(foo(1,2,3)));
117+
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
118+
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
119+
assertFalse(Object.isExtensible(foo(1,2,3, 'a')));
119120
%OptimizeFunctionOnNextCall(foo);
120-
assertEquals([1, 2, 3], foo(1, 2, 3));
121-
assertFalse(Object.isExtensible(foo(1,2,3)));
121+
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
122+
assertFalse(Object.isExtensible(foo(1,2,3, 'a')));
122123
})();
123124

124125
// Test sealed Array call with multiple parameters.
125126
(() => {
126-
function foo(x, y, z) { return Object.seal(new Array(x, y, z)); }
127+
function foo(x, y, z, t) { return Object.seal(new Array(x, y, z, t)); }
127128

128129
%PrepareFunctionForOptimization(foo);
129-
assertEquals([1, 2, 3], foo(1, 2, 3));
130-
assertEquals([1, 2, 3], foo(1, 2, 3));
131-
assertTrue(Object.isSealed(foo(1,2,3)));
130+
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
131+
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
132+
assertTrue(Object.isSealed(foo(1,2,3, 'a')));
132133
%OptimizeFunctionOnNextCall(foo);
133-
assertEquals([1, 2, 3], foo(1, 2, 3));
134-
assertTrue(Object.isSealed(foo(1,2,3)));
134+
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
135+
assertTrue(Object.isSealed(foo(1,2,3, 'a')));
135136
})();
136137

137138
// Test frozen Array call with multiple parameters.
138139
(() => {
139-
function foo(x, y, z) { return Object.freeze(new Array(x, y, z)); }
140+
function foo(x, y, z, t) { return Object.freeze(new Array(x, y, z, t)); }
140141

141142
%PrepareFunctionForOptimization(foo);
142-
assertEquals([1, 2, 3], foo(1, 2, 3));
143-
assertEquals([1, 2, 3], foo(1, 2, 3));
144-
assertTrue(Object.isFrozen(foo(1,2,3)));
143+
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
144+
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
145+
assertTrue(Object.isFrozen(foo(1,2,3, 'a')));
145146
%OptimizeFunctionOnNextCall(foo);
146-
assertEquals([1, 2, 3], foo(1, 2, 3));
147-
assertTrue(Object.isFrozen(foo(1,2,3)));
147+
assertEquals([1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
148+
assertTrue(Object.isFrozen(foo(1,2,3, 'a')));
149+
})();
150+
151+
// Holey
152+
// Test non-extensible Array call with multiple parameters.
153+
(() => {
154+
function foo(x, y, z, t) { return Object.preventExtensions([, x, y, z, t]); }
155+
156+
%PrepareFunctionForOptimization(foo);
157+
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
158+
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
159+
assertFalse(Object.isExtensible(foo(1,2,3, 'a')));
160+
%OptimizeFunctionOnNextCall(foo);
161+
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
162+
assertFalse(Object.isExtensible(foo(1,2,3, 'a')));
163+
})();
164+
165+
// Test sealed Array call with multiple parameters.
166+
(() => {
167+
function foo(x, y, z, t) { return Object.seal([, x, y, z, t]); }
168+
169+
%PrepareFunctionForOptimization(foo);
170+
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
171+
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
172+
assertTrue(Object.isSealed(foo(1,2,3, 'a')));
173+
%OptimizeFunctionOnNextCall(foo);
174+
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
175+
assertTrue(Object.isSealed(foo(1,2,3, 'a')));
176+
})();
177+
178+
// Test frozen Array call with multiple parameters.
179+
(() => {
180+
function foo(x, y, z, t) { return Object.freeze([, x, y, z, t]); }
181+
182+
%PrepareFunctionForOptimization(foo);
183+
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
184+
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
185+
assertTrue(Object.isFrozen(foo(1,2,3, 'a')));
186+
%OptimizeFunctionOnNextCall(foo);
187+
assertEquals([, 1, 2, 3, 'a'], foo(1, 2, 3, 'a'));
188+
assertTrue(Object.isFrozen(foo(1,2,3, 'a')));
148189
})();

test/mjsunit/compiler/array-every.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,53 @@
1717
assertTrue(foo([3, 3, 3], {x:3}));
1818
assertFalse(foo([3, 3, 2], {x:3}));
1919

20+
// Packed
2021
// Non-extensible array
2122
%PrepareFunctionForOptimization(foo);
22-
assertTrue(foo(Object.preventExtensions([3, 3, 3]), {x:3}));
23-
assertFalse(foo(Object.preventExtensions([3, 3, 2]), {x:3}));
23+
assertTrue(foo(Object.preventExtensions(['3', '3', '3']), {x:'3'}));
24+
assertFalse(foo(Object.preventExtensions(['3', '3', '2']), {x:'3'}));
2425
%OptimizeFunctionOnNextCall(foo);
25-
assertTrue(foo(Object.preventExtensions([3, 3, 3]), {x:3}));
26-
assertFalse(foo(Object.preventExtensions([3, 3, 2]), {x:3}));
26+
assertTrue(foo(Object.preventExtensions(['3', '3', '3']), {x:'3'}));
27+
assertFalse(foo(Object.preventExtensions(['3', '3', '2']), {x:'3'}));
2728

2829
// Sealed array
2930
%PrepareFunctionForOptimization(foo);
30-
assertTrue(foo(Object.seal([3, 3, 3]), {x:3}));
31-
assertFalse(foo(Object.seal([3, 3, 2]), {x:3}));
31+
assertTrue(foo(Object.seal(['3', '3', '3']), {x:'3'}));
32+
assertFalse(foo(Object.seal(['3', '3', '2']), {x:'3'}));
3233
%OptimizeFunctionOnNextCall(foo);
33-
assertTrue(foo(Object.seal([3, 3, 3]), {x:3}));
34-
assertFalse(foo(Object.seal([3, 3, 2]), {x:3}));
34+
assertTrue(foo(Object.seal(['3', '3', '3']), {x:'3'}));
35+
assertFalse(foo(Object.seal(['3', '3', '2']), {x:'3'}));
3536

3637
// Frozen array
3738
%PrepareFunctionForOptimization(foo);
38-
assertTrue(foo(Object.freeze([3, 3, 3]), {x:3}));
39-
assertFalse(foo(Object.freeze([3, 3, 2]), {x:3}));
39+
assertTrue(foo(Object.freeze(['3', '3', '3']), {x:'3'}));
40+
assertFalse(foo(Object.freeze(['3', '3', '2']), {x:'3'}));
4041
%OptimizeFunctionOnNextCall(foo);
41-
assertTrue(foo(Object.freeze([3, 3, 3]), {x:3}));
42-
assertFalse(foo(Object.freeze([3, 3, 2]), {x:3}));
42+
assertTrue(foo(Object.freeze(['3', '3', '3']), {x:'3'}));
43+
assertFalse(foo(Object.freeze(['3', '3', '2']), {x:'3'}));
44+
45+
// Holey
46+
// Non-extensible array
47+
%PrepareFunctionForOptimization(foo);
48+
assertTrue(foo(Object.preventExtensions([, '3', '3', '3']), {x:'3'}));
49+
assertFalse(foo(Object.preventExtensions([, '3', '3', '2']), {x:'3'}));
50+
%OptimizeFunctionOnNextCall(foo);
51+
assertTrue(foo(Object.preventExtensions([, '3', '3', '3']), {x:'3'}));
52+
assertFalse(foo(Object.preventExtensions([, '3', '3', '2']), {x:'3'}));
53+
54+
// Sealed array
55+
%PrepareFunctionForOptimization(foo);
56+
assertTrue(foo(Object.seal([, '3', '3', '3']), {x:'3'}));
57+
assertFalse(foo(Object.seal([, '3', '3', '2']), {x:'3'}));
58+
%OptimizeFunctionOnNextCall(foo);
59+
assertTrue(foo(Object.seal([, '3', '3', '3']), {x:'3'}));
60+
assertFalse(foo(Object.seal([, '3', '3', '2']), {x:'3'}));
61+
62+
// Frozen array
63+
%PrepareFunctionForOptimization(foo);
64+
assertTrue(foo(Object.freeze([, '3', '3', '3']), {x:'3'}));
65+
assertFalse(foo(Object.freeze([, '3', '3', '2']), {x:'3'}));
66+
%OptimizeFunctionOnNextCall(foo);
67+
assertTrue(foo(Object.freeze([, '3', '3', '3']), {x:'3'}));
68+
assertFalse(foo(Object.freeze([, '3', '3', '2']), {x:'3'}));
4369
})();

test/mjsunit/compiler/array-find.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,53 @@
1717
assertEquals(3, foo([1, 2, 3], {x:3}));
1818
assertEquals(undefined, foo([0, 1, 2], {x:3}));
1919

20+
// Packed
2021
// Non-extensible
2122
%PrepareFunctionForOptimization(foo);
22-
assertEquals(3, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
23-
assertEquals(undefined, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
23+
assertEquals(3, foo(Object.preventExtensions(['1', 2, 3]), {x:3}));
24+
assertEquals(undefined, foo(Object.preventExtensions(['0', 1, 2]), {x:3}));
2425
%OptimizeFunctionOnNextCall(foo);
25-
assertEquals(3, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
26-
assertEquals(undefined, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
26+
assertEquals(3, foo(Object.preventExtensions(['1', 2, 3]), {x:3}));
27+
assertEquals(undefined, foo(Object.preventExtensions(['0', 1, 2]), {x:3}));
2728

2829
// Sealed
2930
%PrepareFunctionForOptimization(foo);
30-
assertEquals(3, foo(Object.seal([1, 2, 3]), {x:3}));
31-
assertEquals(undefined, foo(Object.seal([0, 1, 2]), {x:3}));
31+
assertEquals(3, foo(Object.seal(['1', 2, 3]), {x:3}));
32+
assertEquals(undefined, foo(Object.seal(['0', 1, 2]), {x:3}));
3233
%OptimizeFunctionOnNextCall(foo);
33-
assertEquals(3, foo(Object.seal([1, 2, 3]), {x:3}));
34-
assertEquals(undefined, foo(Object.seal([0, 1, 2]), {x:3}));
34+
assertEquals(3, foo(Object.seal(['1', 2, 3]), {x:3}));
35+
assertEquals(undefined, foo(Object.seal(['0', 1, 2]), {x:3}));
3536

3637
// Frozen
3738
%PrepareFunctionForOptimization(foo);
38-
assertEquals(3, foo(Object.freeze([1, 2, 3]), {x:3}));
39-
assertEquals(undefined, foo(Object.freeze([0, 1, 2]), {x:3}));
39+
assertEquals(3, foo(Object.freeze(['1', 2, 3]), {x:3}));
40+
assertEquals(undefined, foo(Object.freeze(['0', 1, 2]), {x:3}));
4041
%OptimizeFunctionOnNextCall(foo);
41-
assertEquals(3, foo(Object.freeze([1, 2, 3]), {x:3}));
42-
assertEquals(undefined, foo(Object.freeze([0, 1, 2]), {x:3}));
42+
assertEquals(3, foo(Object.freeze(['1', 2, 3]), {x:3}));
43+
assertEquals(undefined, foo(Object.freeze(['0', 1, 2]), {x:3}));
44+
45+
// Holey
46+
// Non-extensible
47+
%PrepareFunctionForOptimization(foo);
48+
assertEquals(3, foo(Object.preventExtensions([, '1', 2, 3]), {x:3}));
49+
assertEquals(undefined, foo(Object.preventExtensions([, '0', 1, 2]), {x:3}));
50+
%OptimizeFunctionOnNextCall(foo);
51+
assertEquals(3, foo(Object.preventExtensions([, '1', 2, 3]), {x:3}));
52+
assertEquals(undefined, foo(Object.preventExtensions([, '0', 1, 2]), {x:3}));
53+
54+
// Sealed
55+
%PrepareFunctionForOptimization(foo);
56+
assertEquals(3, foo(Object.seal([, '1', 2, 3]), {x:3}));
57+
assertEquals(undefined, foo(Object.seal([, '0', 1, 2]), {x:3}));
58+
%OptimizeFunctionOnNextCall(foo);
59+
assertEquals(3, foo(Object.seal([, '1', 2, 3]), {x:3}));
60+
assertEquals(undefined, foo(Object.seal([, '0', 1, 2]), {x:3}));
61+
62+
// Frozen
63+
%PrepareFunctionForOptimization(foo);
64+
assertEquals(3, foo(Object.freeze([, 1, 2, 3]), {x:3}));
65+
assertEquals(undefined, foo(Object.freeze([, 0, 1, 2]), {x:3}));
66+
%OptimizeFunctionOnNextCall(foo);
67+
assertEquals(3, foo(Object.freeze([, 1, 2, 3]), {x:3}));
68+
assertEquals(undefined, foo(Object.freeze([, 0, 1, 2]), {x:3}));
4369
})();

0 commit comments

Comments
 (0)