Debian Codegraph @

testing/web-platform/tests/streams/readable-streams/read-task-handling.window.js

raw
1 // META: global=window,worker
2 'use strict';
3
4 function performMicrotaskCheckpoint() {
5 document.createNodeIterator(document, -1, {
6 acceptNode() {
7 return NodeFilter.FILTER_ACCEPT;
8 }
9 }).nextNode();
10 }
11
12 test(() => {
13 // Add a getter for "then" that will incidentally be invoked
14 // during promise resolution.
15 Object.prototype.__defineGetter__('then', () => {
16 // Clean up behind ourselves.
17 delete Object.prototype.then;
18
19 // This promise should (like all promises) be resolved
20 // asynchronously.
21 var executed = false;
22 Promise.resolve().then(_ => { executed = true; });
23
24 // This shouldn't run microtasks! They should only run
25 // after the fetch is resolved.
26 performMicrotaskCheckpoint();
27
28 // The fulfill handler above shouldn't have run yet. If it has run,
29 // throw to reject this promise and fail the test.
30 assert_false(executed, "shouldn't have run microtasks yet");
31
32 // Otherwise act as if there's no "then" property so the promise
33 // fulfills and the test passes.
34 return undefined;
35 });
36
37 const readable = new ReadableStream({
38 pull(c) {
39 c.enqueue({});
40 }
41 }, { highWaterMark: 0 });
42
43 // Create a read request, incidentally resolving a promise with an
44 // object value, thereby invoking the getter installed above.
45 readable.getReader().read();
46 }, "reading from a stream should occur in a microtask scope");