diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/non262/ReadableStream/basic-push.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/ReadableStream/basic-push.js')
-rw-r--r-- | js/src/tests/non262/ReadableStream/basic-push.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/js/src/tests/non262/ReadableStream/basic-push.js b/js/src/tests/non262/ReadableStream/basic-push.js new file mode 100644 index 0000000000..65bb29880d --- /dev/null +++ b/js/src/tests/non262/ReadableStream/basic-push.js @@ -0,0 +1,53 @@ +// |reftest| skip-if(!this.ReadableStream||!this.drainJobQueue) + +if ("ignoreUnhandledRejections" in this) { + ignoreUnhandledRejections(); +} + +// Example of a stream that enqueues data asynchronously, whether the reader +// wants it or not, the "push" model. +let fbStream = new ReadableStream({ + start(controller) { + simulatePacketsDriftingIn(controller); + }, +}); + +async function simulatePacketsDriftingIn(controller) { + for (let i = 1; i <= 30; i++) { + let importantData = + (i % 15 == 0 ? "FizzBuzz" : + i % 5 == 0 ? "Buzz": + i % 3 == 0 ? "Fizz" : + String(i)); + controller.enqueue(importantData); + await asyncSleep(1 + i % 7); + } + controller.close(); +} + +const expected = [ + "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", + "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", + "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz" +]; + +async function test() { + assertEq(fbStream.locked, false); + let reader = fbStream.getReader(); + assertEq(fbStream.locked, true); + + let results = []; + while (true) { + let r = await reader.read(); + if (r.done) { + break; + } + results.push(r.value); + } + + assertEq(results.join("-"), expected.join("-")); + reader.releaseLock(); + assertEq(fbStream.locked, false); +} + +runAsyncTest(test); |