Skip to content

Commit

Permalink
Add tests for new Worker() and worker.postMessage() to happen in para…
Browse files Browse the repository at this point in the history
…llel with main page executing JS code. Resolves whatwg/html#10228.
  • Loading branch information
juj committed Apr 3, 2024
1 parent ad97a5b commit a8a022a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions workers/Worker-creation-happens-in-parallel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<title>Test that creation of a "new Worker()" will occur in parallel to the main JS thread performing other computation, and can be joined with.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(t => {
return new Promise(resolve => {
let worker = new Worker("support/Worker-creation-happens-in-parallel.js");
let sab = new Uint8Array(new SharedArrayBuffer(16));
worker.postMessage(sab);
while(sab[0] != 1) /*wait to join with the result*/;
resolve();
});
}, 'Tests that creation of a "new Worker()" will occur in parallel');
</script>
2 changes: 2 additions & 0 deletions workers/Worker-creation-happens-in-parallel.html.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cross-Origin-Opener-Policy:same-origin
Cross-Origin-Embedder-Policy:require-corp
18 changes: 18 additions & 0 deletions workers/Worker-postMessage-happens-in-parallel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>Test that calling "worker.postMessage()" will occur truly in parallel to the main JS thread performing other computation.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(t => {
return new Promise(resolve => {
let worker = new Worker("support/Worker-postMessage-happens-in-parallel.js");
worker.postMessage('init');
worker.onmessage = () => {
let sab = new Uint8Array(new SharedArrayBuffer(16));
worker.postMessage(sab);
while(sab[0] != 1) /*wait to join with the result*/;
resolve();
};
});
}, 'Tests that calling "worker.postMessage()" will occur truly in parallel to the main JS thread');
</script>
2 changes: 2 additions & 0 deletions workers/Worker-postMessage-happens-in-parallel.html.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cross-Origin-Opener-Policy:same-origin
Cross-Origin-Embedder-Policy:require-corp
3 changes: 3 additions & 0 deletions workers/support/Worker-creation-happens-in-parallel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
onmessage = (e) => {
e.data[0] = 1;
}
7 changes: 7 additions & 0 deletions workers/support/Worker-postMessage-happens-in-parallel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
onmessage = (e) => {
if (e.data == 'init') {
postMessage(0);
} else {
e.data[0] = 1;
}
}

0 comments on commit a8a022a

Please # to comment.