1 function checkEquals(value
, expected
, valueCheckFn
= (a
, b
) => a
== b
) {
2 if (!valueCheckFn(value
, expected
)) {
3 return `, got ${value}, expected ${expected}`;
8 function checkReflectedAttributeWithFrozenArrayValues(obj
, values
, valueCheck
) {
9 if (!SimpleTest
.isa(obj
.reflectedHTMLAttribute
, "Array")) {
10 return `, expected array`;
12 let failure
= checkEquals(obj
.reflectedHTMLAttribute
.length
, values
.length
);
14 for (let [i
, v
] of obj
.reflectedHTMLAttribute
.entries()) {
15 failure
= checkEquals(values
[i
], v
, valueCheck
);
24 function checkReflectedAttributeWithFrozenArray(
30 let failure
= checkReflectedAttributeWithFrozenArrayValues(
37 `Cached value on object for HTML reflected FrozenArray attribute should contain the right values ${suffix}${
43 function testReflectedAttributeWithFrozenArray(win
) {
44 let testObject
= new win
.TestReflectedHTMLAttribute();
46 testObject
instanceof win
.TestReflectedHTMLAttribute
,
47 "Got a TestReflectedHTMLAttribute object"
51 testObject
.reflectedHTMLAttribute
,
53 "Initial value for HTML reflected FrozenArray attribute should be null"
56 let values
= [win
.document
.head
];
57 testObject
.setReflectedHTMLAttributeValue(values
);
58 checkReflectedAttributeWithFrozenArray(testObject
, values
, "after setting");
60 values
= [win
.document
.body
, win
.document
.body
.firstElementChild
];
61 testObject
.setReflectedHTMLAttributeValue(values
);
62 checkReflectedAttributeWithFrozenArray(testObject
, values
, "after resetting");
64 // Use a loop to ensure the JITs optimize the getter access.
66 for (let i
= 0; i
< 10_000
; i
++) {
67 failure
= checkReflectedAttributeWithFrozenArrayValues(testObject
, values
);
72 values
= [win
.document
.head
];
73 testObject
.setReflectedHTMLAttributeValue(values
);
78 `Shouldn't use the cached value for HTML reflected FrozenArray attribute directly from JITted code${
84 testObject
.reflectedHTMLAttribute
,
85 testObject
.reflectedHTMLAttribute
,
86 "Getter for HTML reflected FrozenArray attribute should return the cached value"
89 return [testObject
, values
];