@@ -1249,13 +1249,13 @@ impl ExternType {
1249
1249
}
1250
1250
}
1251
1251
/// Construct a default value, if possible for the underlying type. Tags do not have a default value.
1252
- pub fn default_value ( & self , store : impl AsContextMut ) -> Option < Extern > {
1252
+ pub fn default_value ( & self , store : impl AsContextMut ) -> Result < Extern > {
1253
1253
match self {
1254
1254
ExternType :: Func ( func_ty) => func_ty. default_value ( store) . map ( Extern :: Func ) ,
1255
1255
ExternType :: Global ( global_ty) => global_ty. default_value ( store) . map ( Extern :: Global ) ,
1256
1256
ExternType :: Table ( table_ty) => table_ty. default_value ( store) . map ( Extern :: Table ) ,
1257
1257
ExternType :: Memory ( mem_ty) => mem_ty. default_value ( store) . map ( Extern :: Memory ) ,
1258
- ExternType :: Tag ( _) => None , // FIXME: #10252
1258
+ ExternType :: Tag ( _) => bail ! ( "default tags not supported yet" ) , // FIXME: #10252
1259
1259
}
1260
1260
}
1261
1261
}
@@ -2434,12 +2434,13 @@ impl FuncType {
2434
2434
Self { registered_type }
2435
2435
}
2436
2436
/// Construct a func which returns results of default value, if each result type has a default value.
2437
- pub fn default_value ( & self , mut store : impl AsContextMut ) -> Option < Func > {
2437
+ pub fn default_value ( & self , mut store : impl AsContextMut ) -> Result < Func > {
2438
2438
let dummy_results = self
2439
2439
. results ( )
2440
2440
. map ( |ty| ty. default_value ( ) )
2441
- . collect :: < Option < Vec < _ > > > ( ) ?;
2442
- Some ( Func :: new ( & mut store, self . clone ( ) , move |_, _, results| {
2441
+ . collect :: < Option < Vec < _ > > > ( )
2442
+ . ok_or_else ( || anyhow ! ( "function results do not have a default value" ) ) ?;
2443
+ Ok ( Func :: new ( & mut store, self . clone ( ) , move |_, _, results| {
2443
2444
for ( slot, dummy) in results. iter_mut ( ) . zip ( dummy_results. iter ( ) ) {
2444
2445
* slot = * dummy;
2445
2446
}
@@ -2502,9 +2503,12 @@ impl GlobalType {
2502
2503
GlobalType :: new ( ty, mutability)
2503
2504
}
2504
2505
///
2505
- pub fn default_value ( & self , store : impl AsContextMut ) -> Option < RuntimeGlobal > {
2506
- let val = self . content ( ) . default_value ( ) ?;
2507
- RuntimeGlobal :: new ( store, self . clone ( ) , val) . ok ( )
2506
+ pub fn default_value ( & self , store : impl AsContextMut ) -> Result < RuntimeGlobal > {
2507
+ let val = self
2508
+ . content ( )
2509
+ . default_value ( )
2510
+ . ok_or_else ( || anyhow ! ( "global type has no default value" ) ) ?;
2511
+ RuntimeGlobal :: new ( store, self . clone ( ) , val)
2508
2512
}
2509
2513
}
2510
2514
@@ -2637,10 +2641,14 @@ impl TableType {
2637
2641
& self . ty
2638
2642
}
2639
2643
///
2640
- pub fn default_value ( & self , store : impl AsContextMut ) -> Option < RuntimeTable > {
2644
+ pub fn default_value ( & self , store : impl AsContextMut ) -> Result < RuntimeTable > {
2641
2645
let val: ValType = self . element ( ) . clone ( ) . into ( ) ;
2642
- let init_val = val. default_value ( ) ?. ref_ ( ) ?;
2643
- RuntimeTable :: new ( store, self . clone ( ) , init_val) . ok ( )
2646
+ let init_val = val
2647
+ . default_value ( )
2648
+ . context ( "table element type does not have a default value" ) ?
2649
+ . ref_ ( )
2650
+ . unwrap ( ) ;
2651
+ RuntimeTable :: new ( store, self . clone ( ) , init_val)
2644
2652
}
2645
2653
}
2646
2654
@@ -2974,8 +2982,8 @@ impl MemoryType {
2974
2982
& self . ty
2975
2983
}
2976
2984
///
2977
- pub fn default_value ( & self , store : impl AsContextMut ) -> Option < RuntimeMemory > {
2978
- RuntimeMemory :: new ( store, self . clone ( ) ) . ok ( )
2985
+ pub fn default_value ( & self , store : impl AsContextMut ) -> Result < RuntimeMemory > {
2986
+ RuntimeMemory :: new ( store, self . clone ( ) )
2979
2987
}
2980
2988
}
2981
2989
0 commit comments