LibWeb: Import detached ReadableStream buffer tests

This commit is contained in:
Timothy Flynn 2025-04-17 09:58:47 -04:00 committed by Tim Flynn
parent cef714732e
commit 0c309d4660
Notes: github-actions[bot] 2025-04-17 17:47:47 +00:00
3 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,6 @@
Harness status: OK
Found 1 tests
1 Fail
Fail enqueue after detaching byobRequest.view.buffer should throw

View file

@ -0,0 +1,15 @@
<!doctype html>
<meta charset=utf-8>
<script>
self.GLOBAL = {
isWindow: function() { return true; },
isWorker: function() { return false; },
isShadowRealm: function() { return false; },
};
</script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id=log></div>
<script src="../../streams/readable-byte-streams/enqueue-with-detached-buffer.any.js"></script>

View file

@ -0,0 +1,21 @@
// META: global=window,worker,shadowrealm
promise_test(async t => {
const error = new Error('cannot proceed');
const rs = new ReadableStream({
type: 'bytes',
pull: t.step_func((controller) => {
const buffer = controller.byobRequest.view.buffer;
// Detach the buffer.
structuredClone(buffer, { transfer: [buffer] });
// Try to enqueue with a new buffer.
assert_throws_js(TypeError, () => controller.enqueue(new Uint8Array([42])));
// If we got here the test passed.
controller.error(error);
})
});
const reader = rs.getReader({ mode: 'byob' });
await promise_rejects_exactly(t, error, reader.read(new Uint8Array(1)));
}, 'enqueue after detaching byobRequest.view.buffer should throw');