Debian Codegraph @

js/src/jit-test/tests/bug1941446.js

raw
1 function generateObjectLiteral(propCount, computedPropCount) {
2 const parts = [];
3
4 for (let i = 0; i < propCount; i++) {
5 parts.push(`prop${i}: ${i}`);
6 }
7
8 for (let i = 0; i < computedPropCount; i++) {
9 parts.push(`["computedProp${i}"]: ${i}`);
10 }
11
12 return `let obj = {${parts.join(",")}}`;
13 }
14
15 function assertPropCount(obj, count) {
16 assertEq(Object.keys(obj).length === count, true);
17 }
18
19 const objectSizes = [0, 1, 2, 4, 8, 16, 255, 256];
20
21 // objects with computed properties only
22 function testComputedProperties() {
23 for (let numOfProps of objectSizes) {
24 let obj = Function(
25 `${generateObjectLiteral(0, numOfProps)}; return obj;`
26 ).call();
27 assertPropCount(obj, numOfProps);
28 }
29 }
30
31 // objects with one computed properties and the rest are normal;
32 function testMixedProperties() {
33 for (let numOfProps of objectSizes) {
34 let obj = Function(
35 `${generateObjectLiteral(numOfProps, 1)}; return obj;`
36 ).call();
37 assertPropCount(obj, numOfProps + 1);
38 }
39 }
40
41 // objects with normal properties only
42 function testNormalProperties() {
43 for (let numOfProps of objectSizes) {
44 let obj = Function(
45 `${generateObjectLiteral(numOfProps, 0)}; return obj;`
46 ).call();
47 assertPropCount(obj, numOfProps);
48 }
49 }
50
51 testNormalProperties();
52 testMixedProperties();
53 testComputedProperties();