chore: Clean up useage of unwrap

This commit is contained in:
CUB3D 2020-06-21 21:10:20 +01:00
parent 62834fd690
commit 166cb60d89
3 changed files with 21 additions and 29 deletions

View File

@ -39,23 +39,23 @@ fn recursive_serialize<'gc>(
json_obj: &mut JsonValue, json_obj: &mut JsonValue,
) { ) {
for k in &obj.get_keys(avm) { for k in &obj.get_keys(avm) {
let elem = obj.get(k, avm, action_context).unwrap(); if let Ok(elem) = obj.get(k, avm, action_context) {
match elem {
match elem { Value::Undefined => {}
Value::Undefined => {} Value::Null => json_obj[k] = JsonValue::Null,
Value::Null => json_obj[k] = JsonValue::Null, Value::Bool(b) => json_obj[k] = b.into(),
Value::Bool(b) => json_obj[k] = b.into(), Value::Number(f) => json_obj[k] = f.into(),
Value::Number(f) => json_obj[k] = f.into(), Value::String(s) => json_obj[k] = s.into(),
Value::String(s) => json_obj[k] = s.into(), Value::Object(o) => {
Value::Object(o) => { // Don't attempt to serialize functions
// Don't attempt to serialize functions if !o
if !o .is_instance_of(avm, action_context, o, avm.prototypes.function)
.is_instance_of(avm, action_context, o, avm.prototypes.function) .unwrap_or_default()
.unwrap() {
{ let mut sub_data_json = JsonValue::new_object();
let mut sub_data_json = JsonValue::new_object(); recursive_serialize(avm, action_context, o, &mut sub_data_json);
recursive_serialize(avm, action_context, o, &mut sub_data_json); json_obj[k] = sub_data_json;
json_obj[k] = sub_data_json; }
} }
} }
} }
@ -293,11 +293,7 @@ pub fn clear<'gc>(
this: Object<'gc>, this: Object<'gc>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
) -> Result<ReturnValue<'gc>, Error> { ) -> Result<ReturnValue<'gc>, Error> {
let data = this let data = this.get("data", avm, action_context)?.as_object()?;
.get("data", avm, action_context)
.unwrap()
.as_object()
.unwrap();
for k in &data.get_keys(avm) { for k in &data.get_keys(avm) {
data.delete(avm, action_context.gc_context, k); data.delete(avm, action_context.gc_context, k);
@ -337,11 +333,7 @@ pub fn flush<'gc>(
this: Object<'gc>, this: Object<'gc>,
_args: &[Value<'gc>], _args: &[Value<'gc>],
) -> Result<ReturnValue<'gc>, Error> { ) -> Result<ReturnValue<'gc>, Error> {
let data = this let data = this.get("data", avm, action_context)?.as_object()?;
.get("data", avm, action_context)
.unwrap()
.as_object()
.unwrap();
let mut data_json = JsonValue::new_object(); let mut data_json = JsonValue::new_object();
recursive_serialize(avm, action_context, data, &mut data_json); recursive_serialize(avm, action_context, data, &mut data_json);

View File

@ -16,7 +16,7 @@ impl DiskStorageBackend {
.join(scope); .join(scope);
// Create a base dir if one doesn't exist yet // Create a base dir if one doesn't exist yet
if !&base_path.exists() { if !base_path.exists() {
log::info!("Creating storage dir"); log::info!("Creating storage dir");
if let Err(r) = fs::create_dir_all(&base_path) { if let Err(r) = fs::create_dir_all(&base_path) {
log::warn!("Unable to create storage dir {}", r); log::warn!("Unable to create storage dir {}", r);

View File

@ -16,7 +16,7 @@ impl StorageBackend for LocalStorageBackend {
fn get_string(&self, name: &str) -> Option<String> { fn get_string(&self, name: &str) -> Option<String> {
self.storage self.storage
.get(&format!("{}-{}", self.prefix, name)) .get(&format!("{}-{}", self.prefix, name))
.unwrap() .unwrap_or_default()
} }
fn put_string(&mut self, name: &str, value: String) -> bool { fn put_string(&mut self, name: &str, value: String) -> bool {