diff --git a/core/src/avm1/globals/shared_object.rs b/core/src/avm1/globals/shared_object.rs index 19b0aeff0..48cecede2 100644 --- a/core/src/avm1/globals/shared_object.rs +++ b/core/src/avm1/globals/shared_object.rs @@ -39,23 +39,23 @@ fn recursive_serialize<'gc>( json_obj: &mut JsonValue, ) { for k in &obj.get_keys(avm) { - let elem = obj.get(k, avm, action_context).unwrap(); - - 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.into(), - Value::Object(o) => { - // Don't attempt to serialize functions - if !o - .is_instance_of(avm, action_context, o, avm.prototypes.function) - .unwrap() - { - let mut sub_data_json = JsonValue::new_object(); - recursive_serialize(avm, action_context, o, &mut sub_data_json); - json_obj[k] = sub_data_json; + if let Ok(elem) = obj.get(k, avm, action_context) { + 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.into(), + Value::Object(o) => { + // Don't attempt to serialize functions + if !o + .is_instance_of(avm, action_context, o, avm.prototypes.function) + .unwrap_or_default() + { + let mut sub_data_json = JsonValue::new_object(); + recursive_serialize(avm, action_context, o, &mut sub_data_json); + json_obj[k] = sub_data_json; + } } } } @@ -293,11 +293,7 @@ pub fn clear<'gc>( this: Object<'gc>, _args: &[Value<'gc>], ) -> Result, Error> { - let data = this - .get("data", avm, action_context) - .unwrap() - .as_object() - .unwrap(); + let data = this.get("data", avm, action_context)?.as_object()?; for k in &data.get_keys(avm) { data.delete(avm, action_context.gc_context, k); @@ -337,11 +333,7 @@ pub fn flush<'gc>( this: Object<'gc>, _args: &[Value<'gc>], ) -> Result, Error> { - let data = this - .get("data", avm, action_context) - .unwrap() - .as_object() - .unwrap(); + let data = this.get("data", avm, action_context)?.as_object()?; let mut data_json = JsonValue::new_object(); recursive_serialize(avm, action_context, data, &mut data_json); diff --git a/desktop/src/storage.rs b/desktop/src/storage.rs index 817a1549e..33f3315b0 100644 --- a/desktop/src/storage.rs +++ b/desktop/src/storage.rs @@ -16,7 +16,7 @@ impl DiskStorageBackend { .join(scope); // Create a base dir if one doesn't exist yet - if !&base_path.exists() { + if !base_path.exists() { log::info!("Creating storage dir"); if let Err(r) = fs::create_dir_all(&base_path) { log::warn!("Unable to create storage dir {}", r); diff --git a/web/src/storage.rs b/web/src/storage.rs index d7c37175e..b2ceb318e 100644 --- a/web/src/storage.rs +++ b/web/src/storage.rs @@ -16,7 +16,7 @@ impl StorageBackend for LocalStorageBackend { fn get_string(&self, name: &str) -> Option { self.storage .get(&format!("{}-{}", self.prefix, name)) - .unwrap() + .unwrap_or_default() } fn put_string(&mut self, name: &str, value: String) -> bool {