Skip to content

Commit a9b341f

Browse files
committed
[GR-51680] Add regression test.
1 parent 84cdb60 commit a9b341f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* Regression test checking successful transition from sealed JSObjectArray to ObjectArray strategy.
10+
*
11+
* @option debug-builtin
12+
*/
13+
14+
load("assert.js");
15+
16+
const o = {};
17+
const x = 42;
18+
19+
for (const jsobjectArrayType of ["ZeroBasedJSObjectArray", "ContiguousJSObjectArray", "HolesJSObjectArray"]) {
20+
const objectArrayType = jsobjectArrayType.replace("JS", "");
21+
switch (jsobjectArrayType) {
22+
case "ZeroBasedJSObjectArray": {
23+
let a = [];
24+
for (let i = 0; i < 8; i++) {
25+
a[i] = o;
26+
}
27+
Object.seal(a);
28+
assertArrayType(a, jsobjectArrayType);
29+
30+
a[5] = x;
31+
32+
assertArrayType(a, objectArrayType);
33+
assertSameContent([o,o,o,o,o,x,o,o], a);
34+
assertTrue(Object.isSealed(a));
35+
break;
36+
}
37+
case "ContiguousJSObjectArray": {
38+
let a = [];
39+
for (let i = 1; i < 8; i++) {
40+
a[i] = o;
41+
}
42+
Object.seal(a);
43+
assertArrayType(a, jsobjectArrayType);
44+
45+
a[0] = x;
46+
assertArrayType(a, jsobjectArrayType);
47+
48+
a[5] = x;
49+
assertArrayType(a, objectArrayType);
50+
assertSameContent([ ,o,o,o,o,x,o,o], a);
51+
assertTrue(Object.isSealed(a));
52+
break;
53+
}
54+
case "HolesJSObjectArray": {
55+
let a = [];
56+
for (let i = 0; i < 8; i++) {
57+
if (i == 4) {
58+
continue;
59+
}
60+
a[i] = o;
61+
}
62+
Object.seal(a);
63+
assertArrayType(a, jsobjectArrayType);
64+
65+
a[4] = x;
66+
assertArrayType(a, jsobjectArrayType);
67+
a[5] = x;
68+
69+
assertArrayType(a, objectArrayType);
70+
assertSameContent([o,o,o,o, ,x,o,o], a);
71+
assertTrue(Object.isSealed(a));
72+
break;
73+
}
74+
default: throw new TypeError(jsobjectArrayType);
75+
}
76+
}
77+
78+
function assertArrayType(array, expected) {
79+
assertSame(expected, Debug.arraytype(array))
80+
}

0 commit comments

Comments
 (0)