Skip to content

Commit

Permalink
Fix html test for BigInt support
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Jul 1, 2021
1 parent 6f4b713 commit 66fb6fe
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,37 @@ self.setViewValue = (view, index, value) => {
}
};

self.maybeBigInt = (view, value) => {
if (view.constructor.name === "BigInt64Array" || view.constructor.name === "BigUint64Array") {
return BigInt(value);
}
return value;
};

self.testSharingViaIncrementerScript = (t, whereToListen, whereToListenLabel, whereToSend, whereToSendLabel, origin, type = "Int32Array") => {
return new Promise(resolve => {
const sab = new SharedArrayBuffer(8);
const view = new self[type](sab);
setViewValue(view, 0, 1);
setViewValue(view, 0, maybeBigInt(view, 1));

whereToListen.onmessage = t.step_func(({ data }) => {
switch (data.message) {
case "initial payload received": {
assert_equals(data.value, 1, `The ${whereToSendLabel} must see the same value in the SharedArrayBuffer`);
assert_equals(data.value, maybeBigInt(view, 1), `The ${whereToSendLabel} must see the same value in the SharedArrayBuffer`);
break;
}

case "changed to 2": {
assert_equals(getViewValue(view, 0), 2, `The ${whereToListenLabel} must see changes made in the ${whereToSendLabel}`);
assert_equals(getViewValue(view, 0), maybeBigInt(view, 2), `The ${whereToListenLabel} must see changes made in the ${whereToSendLabel}`);

setViewValue(view, 0, 3);
setViewValue(view, 0, maybeBigInt(view, 3));
whereToSend.postMessage({ message: "changed to 3" }, origin);

break;
}

case "changed to 3 received": {
assert_equals(data.value, 3, `The ${whereToSendLabel} must see changes made in the ${whereToListenLabel}`);
assert_equals(data.value, maybeBigInt(view, 3), `The ${whereToSendLabel} must see changes made in the ${whereToListenLabel}`);
resolve();
break;
}
Expand All @@ -57,7 +64,7 @@ self.setupDestinationIncrementer = (whereToListen, whereToSendBackTo, origin) =>
view = data.view;
whereToSendBackTo.postMessage({ message: "initial payload received", value: getViewValue(view, 0) }, origin);

setViewValue(view, 0, 2);
setViewValue(view, 0, maybeBigInt(view, 2));
whereToSendBackTo.postMessage({ message: "changed to 2" }, origin);

break;
Expand Down

0 comments on commit 66fb6fe

Please sign in to comment.