From 9812fab9f8feae8a8dad30410903a34eb042645d Mon Sep 17 00:00:00 2001 From: CUB3D Date: Wed, 21 Apr 2021 05:07:02 +0100 Subject: [PATCH] chore: Format and fix clippy lints --- core/src/avm2/activation.rs | 65 +++++++++++++++--------- core/src/avm2/domain.rs | 5 +- core/src/avm2/object/bytearray_object.rs | 5 +- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/core/src/avm2/activation.rs b/core/src/avm2/activation.rs index 299549425..23f981a72 100644 --- a/core/src/avm2/activation.rs +++ b/core/src/avm2/activation.rs @@ -1,12 +1,13 @@ //! Activation frames use crate::avm2::array::ArrayStorage; -use crate::avm2::bytearray::ByteArrayStorage; use crate::avm2::class::Class; use crate::avm2::method::BytecodeMethod; use crate::avm2::method::Method; use crate::avm2::names::{Multiname, Namespace, QName}; -use crate::avm2::object::{ArrayObject, FunctionObject, NamespaceObject, ScriptObject, ByteArrayObject}; +use crate::avm2::object::{ + ArrayObject, ByteArrayObject, FunctionObject, NamespaceObject, ScriptObject, +}; use crate::avm2::object::{Object, TObject}; use crate::avm2::scope::Scope; use crate::avm2::script::Script; @@ -23,8 +24,6 @@ use swf::avm2::types::{ Class as AbcClass, Index, Method as AbcMethod, Multiname as AbcMultiname, Namespace as AbcNamespace, Op, }; -use std::cell::RefMut; -use std::io::Write; /// Represents a particular register set. /// @@ -2519,13 +2518,15 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_i32(self)?; let val = self.context.avm2.pop().coerce_to_i32(self)?; - let mut dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; - if address < 0 || address as usize >= dm.len() { - return Err("RangeError: The specified range is invalid".into()); - } + let dm = self.domain_memory()?; + let mut dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; + if address < 0 || address as usize >= dm.len() { + return Err("RangeError: The specified range is invalid".into()); + } - dm.write_bytes_at(&val.to_le_bytes(), address as usize); + dm.write_bytes_at(&val.to_le_bytes(), address as usize); Ok(FrameControl::Continue) } @@ -2535,8 +2536,10 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_i32(self)?; let val = self.context.avm2.pop().coerce_to_i32(self)?; - let mut dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; + let dm = self.domain_memory()?; + let mut dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; if address < 0 || (address as usize + 1) >= dm.len() { return Err("RangeError: The specified range is invalid".into()); @@ -2552,8 +2555,10 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_i32(self)?; let val = self.context.avm2.pop().coerce_to_i32(self)?; - let mut dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; + let dm = self.domain_memory()?; + let mut dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; if address < 0 || (address as usize + 3) >= dm.len() { return Err("RangeError: The specified range is invalid".into()); @@ -2569,8 +2574,10 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_i32(self)?; let val = self.context.avm2.pop().coerce_to_number(self)? as f32; - let mut dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; + let dm = self.domain_memory()?; + let mut dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; if address < 0 || (address as usize + 3) >= dm.len() { return Err("RangeError: The specified range is invalid".into()); @@ -2586,8 +2593,10 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_i32(self)?; let val = self.context.avm2.pop().coerce_to_number(self)?; - let mut dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; + let dm = self.domain_memory()?; + let mut dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; if address < 0 || (address as usize + 7) >= dm.len() { return Err("RangeError: The specified range is invalid".into()); @@ -2603,7 +2612,9 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_u32(self)? as usize; let dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; + let dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; let val = dm.get(address); if let Some(val) = val { @@ -2620,7 +2631,9 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_u32(self)? as usize; let dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; + let dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; let val = dm.get_range(address..address + 2); if let Some(val) = val { @@ -2639,7 +2652,9 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_u32(self)? as usize; let dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; + let dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; let val = dm.get_range(address..address + 4); if let Some(val) = val { @@ -2658,7 +2673,9 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_u32(self)? as usize; let dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; + let dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; let val = dm.get_range(address..address + 4); if let Some(val) = val { @@ -2677,7 +2694,9 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { let address = self.context.avm2.pop().coerce_to_u32(self)? as usize; let dm = self.domain_memory()?; - let mut dm = dm.as_bytearray_mut(self.context.gc_context).ok_or("Unable to get bytearray storage".to_string())?; + let dm = dm + .as_bytearray_mut(self.context.gc_context) + .ok_or_else(|| "Unable to get bytearray storage".to_string())?; let val = dm.get_range(address..address + 8); if let Some(val) = val { diff --git a/core/src/avm2/domain.rs b/core/src/avm2/domain.rs index 8221cdf89..3a77ed68f 100644 --- a/core/src/avm2/domain.rs +++ b/core/src/avm2/domain.rs @@ -1,12 +1,11 @@ //! Application Domains use crate::avm2::activation::Activation; -use crate::avm2::bytearray::{ByteArrayStorage, Endian}; use crate::avm2::names::{Multiname, QName}; -use crate::avm2::object::{TObject, ByteArrayObject}; +use crate::avm2::object::{ByteArrayObject, TObject}; use crate::avm2::script::Script; use crate::avm2::value::Value; -use crate::avm2::{Error, Object}; +use crate::avm2::Error; use gc_arena::{Collect, GcCell, MutationContext}; use std::collections::HashMap; diff --git a/core/src/avm2/object/bytearray_object.rs b/core/src/avm2/object/bytearray_object.rs index 7d43c58e3..18a84a9fc 100644 --- a/core/src/avm2/object/bytearray_object.rs +++ b/core/src/avm2/object/bytearray_object.rs @@ -27,7 +27,10 @@ pub struct ByteArrayObjectData<'gc> { } impl<'gc> ByteArrayObject<'gc> { - pub fn new(mc: MutationContext<'gc, '_>, base_proto: Option>) -> ByteArrayObject<'gc> { + pub fn new( + mc: MutationContext<'gc, '_>, + base_proto: Option>, + ) -> ByteArrayObject<'gc> { let base = ScriptObjectData::base_new(base_proto, ScriptObjectClass::NoClass); ByteArrayObject(GcCell::allocate(