@@ -21,6 +21,35 @@ function assert_ModuleExportDescriptor(export_, expected) {
2121 assert_true ( kind . enumerable , "kind: enumerable" ) ;
2222 assert_true ( kind . configurable , "kind: configurable" ) ;
2323 assert_equals ( kind . value , expected . kind ) ;
24+
25+ if ( expected . type ) {
26+ const type = Object . getOwnPropertyDescriptor ( export_ , 'type' ) ;
27+ assert_true ( type . writable , 'type: writable' ) ;
28+ assert_true ( type . enumerable , 'type: enumerable' ) ;
29+ assert_true ( type . configurable , 'type: configurable' ) ;
30+
31+ if ( expected . type . parameters !== undefined ) {
32+ assert_array_equals ( type . value . parameters , expected . type . parameters ) ;
33+ }
34+ if ( expected . type . results !== undefined ) {
35+ assert_array_equals ( type . value . results , expected . type . results ) ;
36+ }
37+ if ( expected . type . value !== undefined ) {
38+ assert_equals ( type . value . value , expected . type . value ) ;
39+ }
40+ if ( expected . type . mutable !== undefined ) {
41+ assert_equals ( type . value . mutable , expected . type . mutable ) ;
42+ }
43+ if ( expected . type . mimimum !== undefined ) {
44+ assert_equals ( type . value . mimimum , expected . type . mimimum ) ;
45+ }
46+ if ( expected . type . maximum !== undefined ) {
47+ assert_equals ( type . value . maximum , expected . type . maximum ) ;
48+ }
49+ if ( expected . type . element !== undefined ) {
50+ assert_equals ( type . value . element , expected . type . element ) ;
51+ }
52+ }
2453}
2554
2655function assert_exports ( exports , expected ) {
@@ -75,6 +104,12 @@ test(() => {
75104 }
76105} , "Branding" ) ;
77106
107+ test ( ( ) => {
108+ const module = new WebAssembly . Module ( emptyModuleBinary ) ;
109+ const exports = WebAssembly . Module . exports ( module ) ;
110+ assert_true ( Array . isArray ( exports ) ) ;
111+ } , "Return type" ) ;
112+
78113test ( ( ) => {
79114 const module = new WebAssembly . Module ( emptyModuleBinary ) ;
80115 const exports = WebAssembly . Module . exports ( module ) ;
@@ -83,7 +118,8 @@ test(() => {
83118
84119test ( ( ) => {
85120 const module = new WebAssembly . Module ( emptyModuleBinary ) ;
86- assert_not_equals ( WebAssembly . Module . exports ( module ) , WebAssembly . Module . exports ( module ) ) ;
121+ assert_not_equals (
122+ WebAssembly . Module . exports ( module ) , WebAssembly . Module . exports ( module ) ) ;
87123} , "Empty module: array caching" ) ;
88124
89125test ( ( ) => {
@@ -114,18 +150,112 @@ test(() => {
114150 const module = new WebAssembly . Module ( buffer ) ;
115151 const exports = WebAssembly . Module . exports ( module ) ;
116152 const expected = [
117- { "kind" : "function" , "name" : "fn" } ,
118- { "kind" : "function" , "name" : "fn2" } ,
119- { "kind" : "table" , "name" : "table" } ,
120- { "kind" : "global" , "name" : "global" } ,
121- { "kind" : "global" , "name" : "global2" } ,
122- { "kind" : "memory" , "name" : "memory" } ,
153+ {
154+ 'kind' : 'function' ,
155+ 'name' : 'fn' ,
156+ 'type' : { 'parameters' : [ ] , 'results' : [ ] }
157+ } ,
158+ {
159+ 'kind' : 'function' ,
160+ 'name' : 'fn2' ,
161+ 'type' : { 'parameters' : [ ] , 'results' : [ ] }
162+ } ,
163+ { 'kind' : 'table' , 'name' : 'table' } ,
164+ { 'kind' : 'global' , 'name' : 'global' } ,
165+ { 'kind' : 'global' , 'name' : 'global2' } ,
166+ { 'kind' : 'memory' , 'name' : 'memory' } ,
123167 ] ;
124168 assert_exports ( exports , expected ) ;
125169} , "exports" ) ;
126170
171+ test ( ( ) => {
172+ const builder = new WasmModuleBuilder ( ) ;
173+
174+ builder
175+ . addFunction ( "" , kSig_v_v )
176+ . addBody ( [ ] )
177+ . exportFunc ( ) ;
178+
179+ const buffer = builder . toBuffer ( )
180+ const module = new WebAssembly . Module ( buffer ) ;
181+ const exports = WebAssembly . Module . exports ( module ) ;
182+ const expected = [
183+ { 'kind' : 'function' , 'name' : '' , 'type' : { 'parameters' : [ ] , 'results' : [ ] } } ,
184+ ] ;
185+ assert_exports ( exports , expected ) ;
186+ } , "exports with empty name: function" ) ;
187+
188+ test ( ( ) => {
189+ const builder = new WasmModuleBuilder ( ) ;
190+
191+ builder . setTableBounds ( 1 ) ;
192+ builder . addExportOfKind ( "" , kExternalTable , 0 ) ;
193+
194+ const buffer = builder . toBuffer ( )
195+ const module = new WebAssembly . Module ( buffer ) ;
196+ const exports = WebAssembly . Module . exports ( module ) ;
197+ const expected = [
198+ { "kind" : "table" , "name" : "" } ,
199+ ] ;
200+ assert_exports ( exports , expected ) ;
201+ } , "exports with empty name: table" ) ;
202+
203+ test ( ( ) => {
204+ const builder = new WasmModuleBuilder ( ) ;
205+
206+ builder . addGlobal ( kWasmI32 , true )
207+ . exportAs ( "" )
208+ . init = 7 ;
209+
210+ const buffer = builder . toBuffer ( )
211+ const module = new WebAssembly . Module ( buffer ) ;
212+ const exports = WebAssembly . Module . exports ( module ) ;
213+ const expected = [
214+ { "kind" : "global" , "name" : "" } ,
215+ ] ;
216+ assert_exports ( exports , expected ) ;
217+ } , "exports with empty name: global" ) ;
218+
127219test ( ( ) => {
128220 const module = new WebAssembly . Module ( emptyModuleBinary ) ;
129221 const exports = WebAssembly . Module . exports ( module , { } ) ;
130222 assert_exports ( exports , [ ] ) ;
131223} , "Stray argument" ) ;
224+
225+ test ( ( ) => {
226+ const builder = new WasmModuleBuilder ( ) ;
227+
228+ builder
229+ . addFunction ( "fn" , kSig_a_a )
230+ . addBody ( [ kExprLocalGet , 0 ] )
231+ . exportFunc ( ) ;
232+
233+ builder . addTable ( kWasmAnyFunc , 10 , 100 ) ;
234+ builder . addExportOfKind ( "table" , kExternalTable , 0 ) ;
235+
236+ builder . addGlobal ( kWasmAnyFunc , true )
237+ . exportAs ( "global" ) . function_index = 0 ;
238+
239+ const buffer = builder . toBuffer ( ) ;
240+ const module = new WebAssembly . Module ( buffer ) ;
241+ const exports = WebAssembly . Module . exports ( module ) ;
242+ const expected = [
243+ {
244+ 'kind' : 'function' ,
245+ 'name' : 'fn' ,
246+ 'type' : { 'parameters' : [ 'funcref' ] , 'results' : [ 'funcref' ] }
247+ } ,
248+ {
249+ 'kind' : 'table' ,
250+ 'name' : 'table' ,
251+ 'type' : { 'minimum' : 10 , 'maximum' : 100 , 'element' : 'funcref' }
252+ } ,
253+ {
254+ 'kind' : 'global' ,
255+ 'name' : 'global' ,
256+ 'type' : { 'value' : 'funcref' , 'mutable' : true }
257+ } ,
258+ ] ;
259+ assert_exports ( exports , expected ) ;
260+ } , "exports with type funcref" ) ;
261+
0 commit comments