Debian Codegraph @

testing/web-platform/mozilla/tests/compression/zstd/decompression-bad-chunks.tentative.any.js

raw
1 // META: global=window,worker
2
3 "use strict";
4
5 const badChunks = [
6 {
7 name: "undefined",
8 value: undefined,
9 },
10 {
11 name: "null",
12 value: null,
13 },
14 {
15 name: "numeric",
16 value: 3.14,
17 },
18 {
19 name: "object, not BufferSource",
20 value: {},
21 },
22 {
23 name: "array",
24 value: [65],
25 },
26 {
27 name: "SharedArrayBuffer",
28 // Use a getter to postpone construction so that all tests don't fail where
29 // SharedArrayBuffer is not yet implemented.
30 get value() {
31 // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
32 return new WebAssembly.Memory({ shared: true, initial: 1, maximum: 1 })
33 .buffer;
34 },
35 },
36 {
37 name: "shared Uint8Array",
38 get value() {
39 // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
40 return new Uint8Array(
41 new WebAssembly.Memory({ shared: true, initial: 1, maximum: 1 }).buffer
42 );
43 },
44 },
45 {
46 name: "invalid zstd bytes",
47 value: new Uint8Array([0x00, 0x01, 0x02, 0x03]),
48 },
49 ];
50
51 for (const badChunk of badChunks) {
52 promise_test(async t => {
53 const ds = new DecompressionStream("zstd");
54 const reader = ds.readable.getReader();
55 const writer = ds.writable.getWriter();
56
57 writer.write(badChunk.value).catch(() => {});
58 reader.read().catch(() => {});
59
60 await promise_rejects_js(t, TypeError, writer.close(), "writer.close() should reject");
61 await promise_rejects_js(t, TypeError, writer.closed, "write.closed should reject");
62
63 await promise_rejects_js(t, TypeError, reader.read(), "reader.read() should reject");
64 await promise_rejects_js(t, TypeError, reader.closed, "read.closed should reject");
65 }, `"zstd" decompression for bad chunk of type "${badChunk.name}" should produce an error`);
66 }