@@ -827,6 +827,7 @@ impl Bindgen for FunctionBindgen<'_> {
827827 results : result_types,
828828 ..
829829 } => {
830+ let debug_log_fn = self . intrinsic ( Intrinsic :: DebugLog ) ;
830831 let ( mut some, some_results) = self . blocks . pop ( ) . unwrap ( ) ;
831832 let ( mut none, none_results) = self . blocks . pop ( ) . unwrap ( ) ;
832833
@@ -847,20 +848,21 @@ impl Bindgen for FunctionBindgen<'_> {
847848 if maybe_null ( resolve, payload) {
848849 uwriteln ! (
849850 self . src,
850- "switch (variant{tmp}.tag) {{
851+ r# "switch (variant{tmp}.tag) {{
851852 case 'none': {{
852- {none}\
853+ {none}
853854 break;
854855 }}
855856 case 'some': {{
856857 const e = variant{tmp}.val;
857- {some}\
858+ {some}
858859 break;
859860 }}
860861 default: {{
862+ {debug_log_fn}("ERROR: invalid value (expected option as object with 'tag' member)", {{ value: variant{tmp} }});
861863 throw new TypeError('invalid variant specified for option');
862864 }}
863- }}" ,
865+ }}"# ,
864866 ) ;
865867 } else {
866868 uwriteln ! (
@@ -940,6 +942,7 @@ impl Bindgen for FunctionBindgen<'_> {
940942 results : result_types,
941943 ..
942944 } => {
945+ let debug_log_fn = self . intrinsic ( Intrinsic :: DebugLog ) ;
943946 let ( mut err, err_results) = self . blocks . pop ( ) . unwrap ( ) ;
944947 let ( mut ok, ok_results) = self . blocks . pop ( ) . unwrap ( ) ;
945948
@@ -959,21 +962,22 @@ impl Bindgen for FunctionBindgen<'_> {
959962
960963 uwriteln ! (
961964 self . src,
962- "switch (variant{tmp}.tag) {{
965+ r# "switch (variant{tmp}.tag) {{
963966 case 'ok': {{
964967 const e = variant{tmp}.val;
965- {ok}\
968+ {ok}
966969 break;
967970 }}
968971 case 'err': {{
969972 const e = variant{tmp}.val;
970- {err}\
973+ {err}
971974 break;
972975 }}
973976 default: {{
977+ {debug_log_fn}("ERROR: invalid value (expected result as object with 'tag' member)", {{ value: variant{tmp} }});
974978 throw new TypeError('invalid variant specified for result');
975979 }}
976- }}" ,
980+ }}"# ,
977981 ) ;
978982 }
979983
0 commit comments