@@ -6,9 +6,7 @@ use core::fmt;
66use core:: iter:: { repeat_n, RepeatN } ;
77use core:: mem:: MaybeUninit ;
88use derive_more:: From ;
9- use spacetimedb_sats:: de:: {
10- self , ArrayVisitor , DeserializeSeed , NoneAccess , ProductVisitor , SliceVisitor , SomeAccess , SumVisitor ,
11- } ;
9+ use spacetimedb_sats:: de:: { self , ArrayVisitor , DeserializeSeed , ProductVisitor , SliceVisitor , SumVisitor } ;
1210use spacetimedb_sats:: { i256, u256} ;
1311use std:: borrow:: { Borrow , Cow } ;
1412use v8:: { Array , Global , HandleScope , Local , Name , Object , Uint8Array , Value } ;
@@ -175,40 +173,9 @@ impl<'de, 'this, 'scope: 'de> de::Deserializer<'de> for Deserializer<'this, 'sco
175173 let sum_name = visitor. sum_name ( ) . unwrap_or ( "<unknown>" ) ;
176174
177175 // We expect a canonical representation of a sum value in JS to be
178- // `{ tag: "foo", value: a_value_for_foo }`
179- // with special convenience for optionals
180- // where we also accept `null`, `undefined` and an object without `tag`.
181- let ( object, tag_field) = ' treat_as_regular_sum: {
182- // Optionals receive some special handling for added convenience in JS.
183- if visitor. is_option ( ) {
184- // If we don't have an object at all,
185- // it's either `null | undefined` which means `none`
186- // or it is `some(the_value)`.
187- if let Some ( object) = self . input . to_object ( scope) {
188- // If there is `tag` field, treat this as a normal sum.
189- // Otherwise, we have `some(the_value)`.
190- let tag_field = self . common . key_cache . tag ( scope) ;
191- if object
192- . has_own_property ( scope, tag_field. into ( ) )
193- . ok_or_else ( exception_already_thrown) ?
194- {
195- break ' treat_as_regular_sum ( object, tag_field) ;
196- }
197- } else if self . input . is_null_or_undefined ( ) {
198- // JS has support for `undefined` and `null` values.
199- // It's reasonable to interpret these as `None`
200- // when we're deserializing to an optional value
201- // rust-side, such as `Option<T>`.
202- return visitor. visit_sum ( NoneAccess :: new ( ) ) ;
203- }
204-
205- return visitor. visit_sum ( SomeAccess :: new ( self ) ) ;
206- } else {
207- let tag_field = self . common . key_cache . tag ( scope) ;
208- let val = cast ! ( scope, self . input, Object , "object for sum type `{}`" , sum_name) ?;
209- ( val, tag_field)
210- }
211- } ;
176+ // `{ tag: "foo", value: a_value_for_foo }`.
177+ let tag_field = self . common . key_cache . tag ( scope) ;
178+ let object = cast ! ( scope, self . input, Object , "object for sum type `{}`" , sum_name) ?;
212179
213180 // Extract the `tag` field. It needs to contain a string.
214181 let tag = object
0 commit comments