11cb0ef41Sopenharmony_ci// META: global=window,worker 21cb0ef41Sopenharmony_ci// META: script=../resources/test-utils.js 31cb0ef41Sopenharmony_ci'use strict'; 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cipromise_test(async () => { 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci let controller; 81cb0ef41Sopenharmony_ci new ReadableStream({ 91cb0ef41Sopenharmony_ci start(c) { 101cb0ef41Sopenharmony_ci controller = c; 111cb0ef41Sopenharmony_ci } 121cb0ef41Sopenharmony_ci }); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci await garbageCollect(); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci return delay(50).then(() => { 171cb0ef41Sopenharmony_ci controller.close(); 181cb0ef41Sopenharmony_ci assert_throws_js(TypeError, () => controller.close(), 'close should throw a TypeError the second time'); 191cb0ef41Sopenharmony_ci controller.error(); 201cb0ef41Sopenharmony_ci }); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci}, 'ReadableStreamController methods should continue working properly when scripts lose their reference to the ' + 231cb0ef41Sopenharmony_ci 'readable stream'); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_cipromise_test(async () => { 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci let controller; 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci const closedPromise = new ReadableStream({ 301cb0ef41Sopenharmony_ci start(c) { 311cb0ef41Sopenharmony_ci controller = c; 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci }).getReader().closed; 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci await garbageCollect(); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci return delay(50).then(() => controller.close()).then(() => closedPromise); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci}, 'ReadableStream closed promise should fulfill even if the stream and reader JS references are lost'); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_cipromise_test(async t => { 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci const theError = new Error('boo'); 441cb0ef41Sopenharmony_ci let controller; 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci const closedPromise = new ReadableStream({ 471cb0ef41Sopenharmony_ci start(c) { 481cb0ef41Sopenharmony_ci controller = c; 491cb0ef41Sopenharmony_ci } 501cb0ef41Sopenharmony_ci }).getReader().closed; 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci await garbageCollect(); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci return delay(50).then(() => controller.error(theError)) 551cb0ef41Sopenharmony_ci .then(() => promise_rejects_exactly(t, theError, closedPromise)); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci}, 'ReadableStream closed promise should reject even if stream and reader JS references are lost'); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_cipromise_test(async () => { 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci const rs = new ReadableStream({}); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci rs.getReader(); 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci await garbageCollect(); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci return delay(50).then(() => assert_throws_js(TypeError, () => rs.getReader(), 681cb0ef41Sopenharmony_ci 'old reader should still be locking the stream even after garbage collection')); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci}, 'Garbage-collecting a ReadableStreamDefaultReader should not unlock its stream'); 71