@@ -1020,6 +1020,55 @@ function test_binaries() {
10201020 module . dispose ( ) ;
10211021}
10221022
1023+ function test_binaries_with_features ( ) {
1024+ var builder = new binaryen . TypeBuilder ( 1 ) ;
1025+ builder . setStructType ( 0 , [
1026+ { type : binaryen . i32 , packedType : binaryen . notPacked , mutable : true } ,
1027+ { type : binaryen . f64 , packedType : binaryen . notPacked , mutable : true }
1028+ ] ) ;
1029+ var [ structHeapType ] = builder . buildAndDispose ( ) ;
1030+ var structType = binaryen . getTypeFromHeapType ( structHeapType , true ) ;
1031+
1032+ var features = binaryen . Features . ReferenceTypes | binaryen . Features . GC ;
1033+ module = new binaryen . Module ( ) ;
1034+ module . setFeatures ( features ) ;
1035+
1036+ module . addGlobal ( "struct-global" ,
1037+ structType ,
1038+ true ,
1039+ module . struct . new (
1040+ [ module . i32 . const ( 42 ) , module . f64 . const ( 3.14 ) ] ,
1041+ binaryen . getHeapType ( structType )
1042+ )
1043+ ) ;
1044+
1045+ module . addFunction ( "get-field" , binaryen . none , binaryen . i32 , [ ] ,
1046+ module . struct . get (
1047+ 0 ,
1048+ module . global . get ( "struct-global" , structType ) ,
1049+ binaryen . i32 ,
1050+ false
1051+ )
1052+ ) ;
1053+
1054+ assert ( module . validate ( ) ) ;
1055+ binaryen . setDebugInfo ( true ) ;
1056+ var buffer = module . emitBinary ( ) ;
1057+ binaryen . setDebugInfo ( false ) ;
1058+ module . dispose ( ) ;
1059+
1060+ module = binaryen . readBinaryWithFeatures ( buffer , features ) ;
1061+
1062+ assert ( module . validate ( ) ) ;
1063+ console . log ( "module loaded from binary with features:" ) ;
1064+ console . log ( module . emitText ( ) ) ;
1065+ module . dispose ( ) ;
1066+
1067+ module = binaryen . readBinaryWithFeatures ( buffer , binaryen . Features . MVP ) ;
1068+ assert ( ! module . validate ( ) ) ;
1069+ module . dispose ( ) ;
1070+ }
1071+
10231072function test_interpret ( ) {
10241073 // create a simple module with a start method that prints a number, and interpret it, printing that number.
10251074 module = new binaryen . Module ( ) ;
@@ -1230,6 +1279,7 @@ test_ids();
12301279test_core ( ) ;
12311280test_relooper ( ) ;
12321281test_binaries ( ) ;
1282+ test_binaries_with_features ( ) ;
12331283test_interpret ( ) ;
12341284test_nonvalid ( ) ;
12351285test_parsing ( ) ;
0 commit comments