io-protocol-probe.mjs (2018B)
1 // Real WASM engines, inert header inspection only, no source compiler substitute. 2 export async function run(_control,backend){ 3 const base=new URL('../',document.querySelector('script[type=module][src]').src); 4 const fixtures=await(await fetch('/runtime-fixtures.json')).json(),checks=[]; 5 let inspect,dispose; 6 const {CompilerWorker}=await import(new URL('runtime/haskell/client.mjs',base)); 7 const client=new CompilerWorker();dispose=()=>client.dispose(); 8 await client.request({type:'init',compiler:false}); 9 inspect=async fixture=>{await client.request({type:'load',bytes:new Uint8Array(fixture.bytes).buffer,hash:fixture.hash});return JSON.parse((await client.request({type:'io-header',name:'root',arguments:[]})).text);}; 10 const equal=(got,want)=>{if(JSON.stringify(got)!==JSON.stringify(want))throw Error('Header mismatch: '+JSON.stringify(got));}; 11 try{ 12 for(let code=0;code<10;code++)equal(await inspect(fixtures['v2-header-core-'+code]),{kind:'core',code}); 13 checks.push('all ten core headers without expanding shared payloads'); 14 equal(await inspect(fixtures['v2-header-future']),{kind:'request',group:'future-9',revision:65535,operation:'unknown'}); 15 equal(await inspect(fixtures['v2-header-long-name']),{kind:'request',group:'a'.repeat(64),revision:1,operation:'read'}); 16 checks.push('future named request and exact name/revision bounds'); 17 for(const [name,message] of [['bad-tag','unknown computation constructor'],['bad-name','invalid facility header'],['bad-revision','invalid facility header'],['zero-revision','invalid facility header'],['bad-shape','invalid computation shape']]){ 18 let rejected=false;try{await inspect(fixtures['v2-header-'+name]);}catch(error){if(!error.message.includes(message))throw error;rejected=true;} 19 if(!rejected)throw Error('Accepted '+name); 20 equal(await inspect(fixtures['v2-header-core-0']),{kind:'core',code:0}); 21 } 22 checks.push('five malformed headers reject; runtime remains usable after each'); 23 }finally{dispose();} 24 return {backend,checks}; 25 }