зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1679322 [wpt PR 26649] - Keep ReadableStreamDefaultReader alive if it has pending requests., a=testonly
Automatic update from web-platform-tests Keep ReadableStreamDefaultReader alive if it has pending requests. If the only reference to a ReadableStreamDefaultReader is from javascript code that is used as fulfillment handler for its "read" promise the reader can get garbage collected, resulting in the promise never resolving. This fixes that issue by making ReadableStreamDefaultReader implement HasPendingActivity to return true if there are any pending read promises. Bug: 1092048 Change-Id: Iccf2d6db453c6a27c82542af7a1dc1a2d792c3ef Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2561043 Reviewed-by: Adam Rice <ricea@chromium.org> Reviewed-by: Yutaka Hirano <yhirano@chromium.org> Commit-Queue: Marijn Kruisselbrink <mek@chromium.org> Cr-Commit-Position: refs/heads/master@{#832599} -- wpt-commits: 2f95271debcba3e26e7294beeee4fa5a2ecfbfa0 wpt-pr: 26649
This commit is contained in:
Родитель
c63f07c141
Коммит
1f8ccd1bc4
|
@ -3,15 +3,25 @@
|
|||
// META: script=../../streams/resources/test-utils.js
|
||||
'use strict';
|
||||
|
||||
// Helper function that triggers garbage collection while reading a chunk
|
||||
// if perform_gc is true.
|
||||
async function read_and_gc(reader, perform_gc) {
|
||||
const read_promise = reader.read();
|
||||
if (perform_gc)
|
||||
garbageCollect();
|
||||
return read_promise;
|
||||
}
|
||||
|
||||
// Takes in a ReadableStream and reads from it until it is done, returning
|
||||
// an array that contains the results of each read operation
|
||||
async function read_all_chunks(stream) {
|
||||
// an array that contains the results of each read operation. If perform_gc
|
||||
// is true, garbage collection is triggered while reading every chunk.
|
||||
async function read_all_chunks(stream, perform_gc = false) {
|
||||
assert_true(stream instanceof ReadableStream);
|
||||
assert_true('getReader' in stream);
|
||||
const reader = stream.getReader();
|
||||
|
||||
assert_true('read' in reader);
|
||||
let read_value = await reader.read();
|
||||
let read_value = await read_and_gc(reader, perform_gc);
|
||||
|
||||
let out = [];
|
||||
let i = 0;
|
||||
|
@ -19,7 +29,7 @@ async function read_all_chunks(stream) {
|
|||
for (let val of read_value.value) {
|
||||
out[i++] = val;
|
||||
}
|
||||
read_value = await reader.read();
|
||||
read_value = await read_and_gc(reader, perform_gc);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -56,7 +66,7 @@ promise_test(async() => {
|
|||
const stream = blob.stream();
|
||||
blob = null;
|
||||
garbageCollect();
|
||||
const chunks = await read_all_chunks(stream);
|
||||
const chunks = await read_all_chunks(stream, /*perform_gc=*/true);
|
||||
assert_array_equals(chunks, input_arr);
|
||||
}, "Blob.stream() garbage collection of blob shouldn't break stream" +
|
||||
"consumption")
|
||||
|
|
Загрузка…
Ссылка в новой задаче