respond-after-enqueue.any.js (1879B)
1 // META: global=window,worker,shadowrealm 2 3 'use strict'; 4 5 // Repro for Blink bug https://crbug.com/1255762. 6 promise_test(async () => { 7 const rs = new ReadableStream({ 8 type: 'bytes', 9 autoAllocateChunkSize: 10, 10 pull(controller) { 11 controller.enqueue(new Uint8Array([1, 2, 3])); 12 controller.byobRequest.respond(10); 13 } 14 }); 15 16 const reader = rs.getReader(); 17 const {value, done} = await reader.read(); 18 assert_false(done, 'done should not be true'); 19 assert_array_equals(value, [1, 2, 3], 'value should be 3 bytes'); 20 }, 'byobRequest.respond() after enqueue() should not crash'); 21 22 promise_test(async () => { 23 const rs = new ReadableStream({ 24 type: 'bytes', 25 autoAllocateChunkSize: 10, 26 pull(controller) { 27 const byobRequest = controller.byobRequest; 28 controller.enqueue(new Uint8Array([1, 2, 3])); 29 byobRequest.respond(10); 30 } 31 }); 32 33 const reader = rs.getReader(); 34 const {value, done} = await reader.read(); 35 assert_false(done, 'done should not be true'); 36 assert_array_equals(value, [1, 2, 3], 'value should be 3 bytes'); 37 }, 'byobRequest.respond() with cached byobRequest after enqueue() should not crash'); 38 39 promise_test(async () => { 40 const rs = new ReadableStream({ 41 type: 'bytes', 42 autoAllocateChunkSize: 10, 43 pull(controller) { 44 controller.enqueue(new Uint8Array([1, 2, 3])); 45 controller.byobRequest.respond(2); 46 } 47 }); 48 49 const reader = rs.getReader(); 50 const [read1, read2] = await Promise.all([reader.read(), reader.read()]); 51 assert_false(read1.done, 'read1.done should not be true'); 52 assert_array_equals(read1.value, [1, 2, 3], 'read1.value should be 3 bytes'); 53 assert_false(read2.done, 'read2.done should not be true'); 54 assert_array_equals(read2.value, [0, 0], 'read2.value should be 2 bytes'); 55 }, 'byobRequest.respond() after enqueue() with double read should not crash');