Bug 1941046 - Part 4: Send a callback request for impression and clicks of MARS Top...
[gecko.git] / dom / bindings / test / file_reflected_attribute_frozenarray.js
blob03513aed2bdb9fa8cb8bcdcfc8a1e63735ea5271
1 function checkEquals(value, expected, valueCheckFn = (a, b) => a == b) {
2 if (!valueCheckFn(value, expected)) {
3 return `, got ${value}, expected ${expected}`;
5 return undefined;
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);
13 if (!failure) {
14 for (let [i, v] of obj.reflectedHTMLAttribute.entries()) {
15 failure = checkEquals(values[i], v, valueCheck);
16 if (failure) {
17 break;
21 return failure;
24 function checkReflectedAttributeWithFrozenArray(
25 obj,
26 values,
27 suffix,
28 valueCheck
29 ) {
30 let failure = checkReflectedAttributeWithFrozenArrayValues(
31 obj,
32 values,
33 valueCheck
35 ok(
36 !failure,
37 `Cached value on object for HTML reflected FrozenArray attribute should contain the right values ${suffix}${
38 failure || ""
43 function testReflectedAttributeWithFrozenArray(win) {
44 let testObject = new win.TestReflectedHTMLAttribute();
45 ok(
46 testObject instanceof win.TestReflectedHTMLAttribute,
47 "Got a TestReflectedHTMLAttribute object"
50 is(
51 testObject.reflectedHTMLAttribute,
52 null,
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.
65 let failure;
66 for (let i = 0; i < 10_000; i++) {
67 failure = checkReflectedAttributeWithFrozenArrayValues(testObject, values);
68 if (!failure) {
69 break;
71 if (i == 9_990) {
72 values = [win.document.head];
73 testObject.setReflectedHTMLAttributeValue(values);
76 ok(
77 !failure,
78 `Shouldn't use the cached value for HTML reflected FrozenArray attribute directly from JITted code${
79 failure || ""
83 is(
84 testObject.reflectedHTMLAttribute,
85 testObject.reflectedHTMLAttribute,
86 "Getter for HTML reflected FrozenArray attribute should return the cached value"
89 return [testObject, values];