|
| 1 | +// Text*Stream should still work even if the realm is detached. |
| 2 | + |
| 3 | +// Adds an iframe to the document and returns it. |
| 4 | +function addIframe() { |
| 5 | + const iframe = document.createElement('iframe'); |
| 6 | + document.body.appendChild(iframe); |
| 7 | + return iframe; |
| 8 | +} |
| 9 | + |
| 10 | +promise_test(async t => { |
| 11 | + const iframe = addIframe(); |
| 12 | + const stream = new iframe.contentWindow.TextDecoderStream(); |
| 13 | + const readPromise = stream.readable.getReader().read(); |
| 14 | + const writer = stream.writable.getWriter(); |
| 15 | + await writer.ready; |
| 16 | + iframe.remove(); |
| 17 | + return Promise.all([writer.write(new Uint8Array([65])),readPromise]); |
| 18 | +}, 'TextDecoderStream: write in detached realm should succeed'); |
| 19 | + |
| 20 | +promise_test(async t => { |
| 21 | + const iframe = addIframe(); |
| 22 | + const stream = new iframe.contentWindow.TextEncoderStream(); |
| 23 | + const readPromise = stream.readable.getReader().read(); |
| 24 | + const writer = stream.writable.getWriter(); |
| 25 | + await writer.ready; |
| 26 | + iframe.remove(); |
| 27 | + return Promise.all([writer.write('A'), readPromise]); |
| 28 | +}, 'TextEncoderStream: write in detached realm should succeed'); |
| 29 | + |
| 30 | +for (const type of ['TextEncoderStream', 'TextDecoderStream']) { |
| 31 | + promise_test(async t => { |
| 32 | + const iframe = addIframe(); |
| 33 | + const stream = new iframe.contentWindow[type](); |
| 34 | + iframe.remove(); |
| 35 | + return stream.writable.close(); |
| 36 | + }, `${type}: close in detached realm should succeed`); |
| 37 | +} |
0 commit comments