1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

feat(serde_v8): Support StringObject as unit enum variant (#15715)

This commit is contained in:
Jakub Łabor 2022-09-02 16:49:44 +02:00 committed by GitHub
parent 8178665bd1
commit e719a02bb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -201,8 +201,8 @@ impl<'de, 'a, 'b, 's, 'x> de::Deserializer<'de>
where
V: Visitor<'de>,
{
if self.input.is_string() {
let v8_string = v8::Local::<v8::String>::try_from(self.input).unwrap();
if self.input.is_string() || self.input.is_string_object() {
let v8_string = self.input.to_string(self.scope).unwrap();
let string = to_utf8(v8_string, self.scope);
visitor.visit_string(string)
} else {
@ -396,7 +396,7 @@ impl<'de, 'a, 'b, 's, 'x> de::Deserializer<'de>
V: Visitor<'de>,
{
// Unit variant
if self.input.is_string() {
if self.input.is_string() || self.input.is_string_object() {
let payload = v8::undefined(self.scope).into();
visitor.visit_enum(EnumAccess {
scope: self.scope,

View file

@ -125,8 +125,11 @@ detest!(
// Unit enums
detest!(de_enum_unit_a, EnumUnit, "'A'", EnumUnit::A);
detest!(de_enum_unit_so_a, EnumUnit, "new String('A')", EnumUnit::A);
detest!(de_enum_unit_b, EnumUnit, "'B'", EnumUnit::B);
detest!(de_enum_unit_so_b, EnumUnit, "new String('B')", EnumUnit::B);
detest!(de_enum_unit_c, EnumUnit, "'C'", EnumUnit::C);
detest!(de_enum_unit_so_c, EnumUnit, "new String('C')", EnumUnit::C);
// Enums with payloads (tuples & struct)
detest!(