diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/ReadableStream/basic-push.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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); |