@@ -824,19 +824,19 @@ extension Parser {
824824 /// > Note:
825825 /// <https://webassembly.github.io/spec/core/binary/modules.html#binary-importdesc>
826826 func parseImportDescriptor( ) throws ( WasmParserError) -> ImportDescriptor {
827- let maxKind : UInt8 = features . contains ( . exceptionHandling ) ? 0x04 : 0x03
828- let b = try stream. consume ( Set ( 0x00 ... maxKind ) )
827+ let descriptorOffset = stream . currentIndex
828+ let b = try stream. consumeAny ( )
829829 switch b {
830830 case 0x00 : return try . function( parseUnsigned ( ) )
831831 case 0x01 : return try . table( parseTableType ( ) )
832832 case 0x02 : return try . memory( parseMemoryType ( ) )
833833 case 0x03 : return try . global( parseGlobalType ( ) )
834- case 0x04 :
834+ case 0x04 where features . contains ( . exceptionHandling ) :
835835 let attribute : UInt8 = try parseUnsigned ( )
836836 guard attribute == 0 else { throw makeError ( . invalidTagAttribute( attribute) ) }
837837 return try . tag( parseUnsigned ( ) )
838838 default :
839- preconditionFailure ( " should never reach here " )
839+ throw WasmParserError ( kind : . parserUnexpectedByte ( b , expected : nil ) , offset : descriptorOffset )
840840 }
841841 }
842842
@@ -898,16 +898,16 @@ extension Parser {
898898 /// > Note:
899899 /// <https://webassembly.github.io/spec/core/binary/modules.html#binary-exportdesc>
900900 func parseExportDescriptor( ) throws ( WasmParserError) -> ExportDescriptor {
901- let maxKind : UInt8 = features . contains ( . exceptionHandling ) ? 0x04 : 0x03
902- let b = try stream. consume ( Set ( 0x00 ... maxKind ) )
901+ let descriptorOffset = stream . currentIndex
902+ let b = try stream. consumeAny ( )
903903 switch b {
904904 case 0x00 : return try . function( parseUnsigned ( ) )
905905 case 0x01 : return try . table( parseUnsigned ( ) )
906906 case 0x02 : return try . memory( parseUnsigned ( ) )
907907 case 0x03 : return try . global( parseUnsigned ( ) )
908- case 0x04 : return try . tag( parseUnsigned ( ) )
908+ case 0x04 where features . contains ( . exceptionHandling ) : return try . tag( parseUnsigned ( ) )
909909 default :
910- preconditionFailure ( " should never reach here " )
910+ throw WasmParserError ( kind : . parserUnexpectedByte ( b , expected : nil ) , offset : descriptorOffset )
911911 }
912912 }
913913
0 commit comments