@@ -1111,14 +1111,14 @@ public class ProgramBuilder {
1111
1111
} else if type. Is ( . wasmFuncRef) {
1112
1112
// TODO(cffsmith): refine this type with the signature if we can.
1113
1113
return . function( )
1114
- } else if type. Is ( . wasmExternRef) {
1115
- return . jsAnything
1116
- } else if type. Is ( . wasmExnRef) {
1117
- return . jsAnything
1118
- } else if type. Is ( . wasmGenericRef) {
1119
- return . jsAnything
1120
1114
} else if type. Is ( . wasmI31Ref) {
1121
1115
return . integer
1116
+ } else if type. Is ( . wasmNullRef) || type. Is ( . wasmNullExternRef) || type. Is ( . wasmNullFuncRef) {
1117
+ // This is slightly imprecise: The null types only accept null, not undefined but
1118
+ // Fuzzilli doesn't differentiate between null and undefined in its type system.
1119
+ return . nullish
1120
+ } else if type. Is ( . wasmGenericRef) {
1121
+ return . jsAnything
1122
1122
} else {
1123
1123
fatalError ( " Unexpected type encountered: \( type) . " )
1124
1124
}
@@ -3950,9 +3950,17 @@ public class ProgramBuilder {
3950
3950
}
3951
3951
3952
3952
public func randomWasmSignature( ) -> WasmSignature {
3953
- // TODO: generalize this to support more types.
3954
- let returnTypes : [ ILType ] = ( 0 ..< Int . random ( in: 0 ... 3 ) ) . map { _ in chooseUniform ( from: [ . wasmi32, . wasmi64, . wasmf32, . wasmf64] ) }
3955
- let params : [ ILType ] = ( 0 ..< Int . random ( in: 0 ... 10 ) ) . map { _ in chooseUniform ( from: [ . wasmi32, . wasmf32, . wasmf64] ) }
3953
+ // TODO: generalize this to support more types. Also add support for simd128 and
3954
+ // (null)exnref, note however that these types raise exceptions when used from JS.
3955
+ let valueTypes : [ ILType ] = [ . wasmi32, . wasmi64, . wasmf32, . wasmf64]
3956
+ let abstractRefTypes : [ ILType ] = [ . wasmExternRef, . wasmAnyRef, . wasmI31Ref]
3957
+ let nullTypes : [ ILType ] = [ . wasmNullRef, . wasmNullExternRef, . wasmNullFuncRef]
3958
+ let randomType = {
3959
+ chooseUniform (
3960
+ from: chooseBiased ( from: [ nullTypes, abstractRefTypes, valueTypes] , factor: 1.5 ) )
3961
+ }
3962
+ let returnTypes : [ ILType ] = ( 0 ..< Int . random ( in: 0 ... 3 ) ) . map { _ in randomType ( ) }
3963
+ let params : [ ILType ] = ( 0 ..< Int . random ( in: 0 ... 10 ) ) . map { _ in randomType ( ) }
3956
3964
return params => returnTypes
3957
3965
}
3958
3966
0 commit comments