fn recursive_serialize<'gc>(
    activation: &mut Activation<'_, 'gc, '_>,
    obj: Object<'gc>,
    json_obj: &mut JsonValue,
) {
    for k in &obj.get_keys(activation) {
        if let Ok(elem) = obj.get(k, activation) {
            match elem {
                Value::Undefined => {}
                Value::Null => json_obj[k] = JsonValue::Null,
                Value::Bool(b) => json_obj[k] = b.into(),
                Value::Number(f) => json_obj[k] = f.into(),
                Value::String(s) => json_obj[k] = s.to_string().into(),
                Value::Object(o) => {
                    // Don't attempt to serialize functions
                    let function = activation.context.avm1.prototypes.function;
                    let array = activation.context.avm1.prototypes.array;
                    if !o
                        .is_instance_of(activation, o, function)
                        .unwrap_or_default()
                    {
                        let mut sub_data_json = JsonValue::new_object();
                        recursive_serialize(activation, o, &mut sub_data_json);
                        if o.is_instance_of(activation, o, array).unwrap_or_default() {
                            sub_data_json["__proto__"] = "Array".into();
                            sub_data_json["length"] = o.length().into();
                        }
                        json_obj[k] = sub_data_json;
                    }
                }
            }
        }
    }
}
/// Serialize an Object and any children to a JSON object
/// It would be best if this was implemented via serde but due to avm and context it can't
/// Undefined fields aren't serialized
Serialize an Object and any children to a JSON object
It would be best if this was implemented via serde but due to avm and context it can't
Undefined fields aren't serialized
Serialize an Object and any children to a JSON object It would be best if this was implemented via serde but due to avm and context it can ' t Undefined fields aren ' t serialized
fn recursive_serialize<'gc>(
    activation: &mut Activation<'_, 'gc, '_>,
    obj: Object<'gc>,
    json_obj: &mut JsonValue,
) {
    for k in &obj.get_keys(activation) {
        if let Ok(elem) = obj.get(k, activation) {
            match elem {
                Value::Undefined => {}
                Value::Null => json_obj[k] = JsonValue::Null,
                Value::Bool(b) => json_obj[k] = b.into(),
                Value::Number(f) => json_obj[k] = f.into(),
                Value::String(s) => json_obj[k] = s.to_string().into(),
                Value::Object(o) => {
                    // Don't attempt to serialize functions
                    let function = activation.context.avm1.prototypes.function;
                    let array = activation.context.avm1.prototypes.array;
                    if !o
                        .is_instance_of(activation, o, function)
                        .unwrap_or_default()
                    {
                        let mut sub_data_json = JsonValue::new_object();
                        recursive_serialize(activation, o, &mut sub_data_json);
                        if o.is_instance_of(activation, o, array).unwrap_or_default() {
                            sub_data_json["__proto__"] = "Array".into();
                            sub_data_json["length"] = o.length().into();
                        }
                        json_obj[k] = sub_data_json;
                    }
                }
            }
        }
    }
}
fn recursive_serialize < ' gc > ( activation : & mut Activation < ' _ , ' gc , ' _ > , obj : Object < ' gc > , json_obj : & mut JsonValue , ) { for k in & obj . get_keys ( activation ) { if let Ok ( elem ) = obj . get ( k , activation ) { match elem { Value :: Undefined => { } Value :: Null => json_obj [ k ] = JsonValue :: Null , Value :: Bool ( b ) => json_obj [ k ] = b . into ( ) , Value :: Number ( f ) => json_obj [ k ] = f . into ( ) , Value :: String ( s ) => json_obj [ k ] = s . to_string ( ) . into ( ) , Value :: Object ( o ) => { // Don't attempt to serialize functions let function = activation . context . avm1 . prototypes . function ; let array = activation . context . avm1 . prototypes . array ; if ! o . is_instance_of ( activation , o , function ) . unwrap_or_default ( ) { let mut sub_data_json = JsonValue :: new_object ( ) ; recursive_serialize ( activation , o , & mut sub_data_json ) ; if o . is_instance_of ( activation , o , array ) . unwrap_or_default ( ) { sub_data_json [ " " ] = " " . into ( ) ; sub_data_json [ " " ] = o . length ( ) . into ( ) ; } json_obj [ k ] = sub_data_json ; } } } } } }
Serialize an Object and any children to a JSON object
It would be best if this was implemented via serde but due to avm and context it can't
Undefined fields aren't serialized
Serialize an Object and any children to a JSON object It would be best if this was implemented via serde but due to avm and context it can ' t Undefined fields aren ' t serialized
activation
&mut Activation<'_, 'gc, '_>
obj
Object<'gc>
json_obj
&mut JsonValue
activation
&mut Activation<'_, 'gc, '_>
obj
Object<'gc>
json_obj
&mut JsonValue