linking.js (1591B)
1 function linkGlobals(typeSection, exportInit, linkType) { 2 let {global} = wasmEvalText(`(module 3 ${typeSection} 4 (global (export "global") ${linkType} ${exportInit}) 5 )`).exports; 6 7 wasmEvalText(`(module 8 ${typeSection} 9 (import "" "global" 10 (global ${linkType}) 11 ) 12 )`, {"": {global}}); 13 } 14 15 function linkTables(typeSection, exportInit, linkType) { 16 let {table} = wasmEvalText(`(module 17 ${typeSection} 18 (table (export "table") ${linkType} (elem (${exportInit}))) 19 )`).exports; 20 21 wasmEvalText(`(module 22 ${typeSection} 23 (import "" "table" 24 (table 0 1 ${linkType}) 25 ) 26 )`, {"": {table}}); 27 } 28 29 function linkFuncs(typeSection, exportInit, linkType) { 30 let {func} = wasmEvalText(`(module 31 ${typeSection} 32 (func 33 (export "func") 34 (param ${linkType}) 35 (result ${linkType}) 36 unreachable 37 ) 38 )`).exports; 39 40 wasmEvalText(`(module 41 ${typeSection} 42 (import "" "func" 43 (func (param ${linkType}) (result ${linkType})) 44 ) 45 )`, {"": {func}}); 46 } 47 48 const TESTS = [ 49 [ 50 "(type (struct (field i32)))", 51 "ref.null 0", 52 "(ref null 0)", 53 ], 54 [ 55 "(type (array i32))", 56 "ref.null 0", 57 "(ref null 0)", 58 ], 59 [ 60 "(type (struct (field i32))) (type (struct (field (ref 0))))", 61 "ref.null 1", 62 "(ref null 1)", 63 ] 64 ]; 65 66 for (let test of TESTS) { 67 linkGlobals(...test); 68 linkTables(...test); 69 linkFuncs(...test); 70 }