11cb0ef41Sopenharmony_ci// Text*Stream should still work even if the realm is detached. 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Adds an iframe to the document and returns it. 41cb0ef41Sopenharmony_cifunction addIframe() { 51cb0ef41Sopenharmony_ci const iframe = document.createElement('iframe'); 61cb0ef41Sopenharmony_ci document.body.appendChild(iframe); 71cb0ef41Sopenharmony_ci return iframe; 81cb0ef41Sopenharmony_ci} 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cipromise_test(async t => { 111cb0ef41Sopenharmony_ci const iframe = addIframe(); 121cb0ef41Sopenharmony_ci const stream = new iframe.contentWindow.TextDecoderStream(); 131cb0ef41Sopenharmony_ci const readPromise = stream.readable.getReader().read(); 141cb0ef41Sopenharmony_ci const writer = stream.writable.getWriter(); 151cb0ef41Sopenharmony_ci await writer.ready; 161cb0ef41Sopenharmony_ci iframe.remove(); 171cb0ef41Sopenharmony_ci return Promise.all([writer.write(new Uint8Array([65])),readPromise]); 181cb0ef41Sopenharmony_ci}, 'TextDecoderStream: write in detached realm should succeed'); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cipromise_test(async t => { 211cb0ef41Sopenharmony_ci const iframe = addIframe(); 221cb0ef41Sopenharmony_ci const stream = new iframe.contentWindow.TextEncoderStream(); 231cb0ef41Sopenharmony_ci const readPromise = stream.readable.getReader().read(); 241cb0ef41Sopenharmony_ci const writer = stream.writable.getWriter(); 251cb0ef41Sopenharmony_ci await writer.ready; 261cb0ef41Sopenharmony_ci iframe.remove(); 271cb0ef41Sopenharmony_ci return Promise.all([writer.write('A'), readPromise]); 281cb0ef41Sopenharmony_ci}, 'TextEncoderStream: write in detached realm should succeed'); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_cifor (const type of ['TextEncoderStream', 'TextDecoderStream']) { 311cb0ef41Sopenharmony_ci promise_test(async t => { 321cb0ef41Sopenharmony_ci const iframe = addIframe(); 331cb0ef41Sopenharmony_ci const stream = new iframe.contentWindow[type](); 341cb0ef41Sopenharmony_ci iframe.remove(); 351cb0ef41Sopenharmony_ci return stream.writable.close(); 361cb0ef41Sopenharmony_ci }, `${type}: close in detached realm should succeed`); 371cb0ef41Sopenharmony_ci} 38