compression-bad-chunks.any.js (1571B)
1 // META: global=window,worker,shadowrealm 2 // META: script=resources/formats.js 3 4 'use strict'; 5 6 const badChunks = [ 7 { 8 name: 'undefined', 9 value: undefined 10 }, 11 { 12 name: 'null', 13 value: null 14 }, 15 { 16 name: 'numeric', 17 value: 3.14 18 }, 19 { 20 name: 'object, not BufferSource', 21 value: {} 22 }, 23 { 24 name: 'array', 25 value: [65] 26 }, 27 { 28 name: 'SharedArrayBuffer', 29 // Use a getter to postpone construction so that all tests don't fail where 30 // SharedArrayBuffer is not yet implemented. 31 get value() { 32 // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()` 33 return new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).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(new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer) 41 } 42 }, 43 ]; 44 45 for (const format of formats) { 46 for (const chunk of badChunks) { 47 promise_test(async t => { 48 const cs = new CompressionStream(format); 49 const reader = cs.readable.getReader(); 50 const writer = cs.writable.getWriter(); 51 const writePromise = writer.write(chunk.value); 52 const readPromise = reader.read(); 53 await promise_rejects_js(t, TypeError, writePromise, 'write should reject'); 54 await promise_rejects_js(t, TypeError, readPromise, 'read should reject'); 55 }, `chunk of type ${chunk.name} should error the stream for ${format}`); 56 } 57 }