1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -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 Yoshiya Hinosawa
parent eafec30b7a
commit f92224c6db
No known key found for this signature in database
GPG key ID: 0E8BFAA8A5B4E92B
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!(