@@ -50,25 +50,60 @@ function generateImportObject(module) {
5050 for ( const pair of depsByRequest ) {
5151 const properties = [ ] ;
5252 for ( const data of pair [ 1 ] ) {
53- let params = "" ;
54- let result = "void 0" ;
55-
5653 if ( data . description . type === "FuncImportDescr" ) {
57- params = data . description . params . map (
54+ const params = data . description . params . map (
5855 ( param , k ) => "p" + k + param . valtype
5956 ) ;
6057
61- result = `__webpack_require__(${ JSON . stringify (
58+ const result = `__webpack_require__(${ JSON . stringify (
6259 data . module . id
6360 ) } )[${ JSON . stringify ( data . usedName ) } ](${ params } )`;
61+
62+ properties . push (
63+ `\n\t\t${ JSON . stringify ( data . exportName ) } : function(${ params } ) {
64+ return ${ result } ;
65+ }`
66+ ) ;
6467 }
6568
66- properties . push (
67- `\n\t\t${ JSON . stringify ( data . exportName ) } : function(${ params } ) {
68- return ${ result } ;
69- }`
70- ) ;
69+ if ( data . description . type === "Memory" ) {
70+ const { min, max} = data . description . limits ;
71+
72+ const params = {
73+ initial : min
74+ } ;
75+
76+ if ( typeof max === "number" ) {
77+ params . maximum = max ;
78+ }
79+
80+ properties . push (
81+ `\n\t\t${ JSON . stringify (
82+ data . exportName
83+ ) } : new WebAssembly.Memory(${ JSON . stringify ( params ) } )`
84+ ) ;
85+ }
86+
87+ if ( data . description . type === "Table" ) {
88+ const { min, max} = data . description . limits ;
89+
90+ const params = {
91+ element : data . description . elementType ,
92+ initial : min
93+ } ;
94+
95+ if ( typeof max === "number" ) {
96+ params . maximum = max ;
97+ }
98+
99+ properties . push (
100+ `\n\t\t${ JSON . stringify (
101+ data . exportName
102+ ) } : new WebAssembly.Table(${ JSON . stringify ( params ) } )`
103+ ) ;
104+ }
71105 }
106+
72107 importsCode . push (
73108 `\n\t${ JSON . stringify ( pair [ 0 ] ) } : {${ properties . join ( "," ) } \n\t}`
74109 ) ;
0 commit comments