Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions core/src/avm1/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'a> VariableDumper<'a> {
&self.output
}

fn object_id(&mut self, object: &Object) -> (usize, bool) {
fn object_id(&mut self, object: Object) -> (usize, bool) {
let ptr = object.as_ptr();

for (i, other) in self.objects.iter().enumerate() {
Expand Down Expand Up @@ -80,11 +80,7 @@ impl<'a> VariableDumper<'a> {
self.output.push('\"');
}

pub fn print_object<'gc>(
&mut self,
object: &Object<'gc>,
activation: &mut Activation<'_, 'gc>,
) {
pub fn print_object<'gc>(&mut self, object: Object<'gc>, activation: &mut Activation<'_, 'gc>) {
let (id, new) = self.object_id(object);
self.output.push_str("[object #");
self.output.push_str(&id.to_string());
Expand All @@ -97,7 +93,7 @@ impl<'a> VariableDumper<'a> {

pub fn print_property<'gc>(
&mut self,
object: &Object<'gc>,
object: Object<'gc>,
key: AvmString<'gc>,
activation: &mut Activation<'_, 'gc>,
) {
Expand All @@ -115,7 +111,7 @@ impl<'a> VariableDumper<'a> {

pub fn print_properties<'gc>(
&mut self,
object: &Object<'gc>,
object: Object<'gc>,
activation: &mut Activation<'_, 'gc>,
) {
let keys = object.get_keys(activation, false);
Expand All @@ -140,20 +136,20 @@ impl<'a> VariableDumper<'a> {
}

pub fn print_value<'gc>(&mut self, value: &Value<'gc>, activation: &mut Activation<'_, 'gc>) {
match value {
match *value {
Value::Undefined => self.output.push_str("undefined"),
Value::Null => self.output.push_str("null"),
Value::Bool(value) => self.output.push_str(&value.to_string()),
Value::Number(value) => self.output.push_str(&value.to_string()),
Value::String(value) => {
self.print_string(*value);
self.print_string(value);
}
Value::Object(object) => {
self.print_object(object, activation);
}
Value::MovieClip(_) => {
let obj = value.coerce_to_object(activation);
self.print_object(&obj, activation);
self.print_object(obj, activation);
}
}
}
Expand All @@ -162,7 +158,7 @@ impl<'a> VariableDumper<'a> {
&mut self,
header: &str,
name: &str,
object: &Object<'gc>,
object: Object<'gc>,
activation: &mut Activation<'_, 'gc>,
) {
let keys = object.get_keys(activation, false);
Expand Down
42 changes: 21 additions & 21 deletions core/src/avm1/globals/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ impl Date {
}

/// Get milliseconds since epoch.
pub const fn time(&self) -> f64 {
pub const fn time(self) -> f64 {
self.0
}

fn is_valid(&self) -> bool {
fn is_valid(self) -> bool {
self.0.is_finite()
}

/// ECMA-262 Day - Get days since epoch.
fn day(&self) -> f64 {
fn day(self) -> f64 {
(self.0 / f64::from(Self::MS_PER_DAY)).floor()
}

/// ECMA-262 TimeWithinDay - Get milliseconds within day.
fn time_within_day(&self, swf_version: u8) -> f64 {
fn time_within_day(self, swf_version: u8) -> f64 {
if swf_version > 7 {
self.0.rem_euclid(Self::MS_PER_DAY.into())
} else {
Expand All @@ -99,22 +99,22 @@ impl Date {
}

/// ECMA-262 YearFromTime - Get year.
fn year(&self) -> i32 {
fn year(self) -> i32 {
let day = self.day();
// Perform binary search to find the largest `year: i32` such that `Self::from_year(year) <= *self`.
let mut low =
((day / if *self < Self::EPOCH { 365.0 } else { 366.0 }).floor()).clamp_to_i32() + 1970;
((day / if self < Self::EPOCH { 365.0 } else { 366.0 }).floor()).clamp_to_i32() + 1970;
let mut high =
((day / if *self < Self::EPOCH { 366.0 } else { 365.0 }).ceil()).clamp_to_i32() + 1970;
((day / if self < Self::EPOCH { 366.0 } else { 365.0 }).ceil()).clamp_to_i32() + 1970;
while low < high {
let pivot = ((f64::from(low) + f64::from(high)) / 2.0).clamp_to_i32();
if Self::from_year(pivot) <= *self {
if Self::from_year(pivot + 1) > *self {
if Self::from_year(pivot) <= self {
if Self::from_year(pivot + 1) > self {
return pivot;
}
low = pivot + 1;
} else {
debug_assert!(Self::from_year(pivot) > *self);
debug_assert!(Self::from_year(pivot) > self);
high = pivot - 1;
}
}
Expand All @@ -127,12 +127,12 @@ impl Date {
}

/// ECMA-262 InLeapYear
fn in_leap_year(&self) -> bool {
fn in_leap_year(self) -> bool {
Self::is_leap_year(self.year())
}

/// ECMA-262 MonthFromTime - Get month (0-11).
fn month(&self) -> i32 {
fn month(self) -> i32 {
let day = self.day_within_year();
let in_leap_year = self.in_leap_year();
for i in 0..11 {
Expand All @@ -144,24 +144,24 @@ impl Date {
}

/// ECMA-262 DayWithinYear - Get days within year (0-365).
fn day_within_year(&self) -> i32 {
fn day_within_year(self) -> i32 {
(self.day() - Self::day_from_year(self.year().into())).clamp_to_i32()
}

/// ECMA-262 DateFromTime - Get days within month (1-31).
fn date(&self) -> i32 {
fn date(self) -> i32 {
let month = self.month();
let month_offset = Self::MONTH_OFFSETS[usize::from(self.in_leap_year())][month as usize];
self.day_within_year() - i32::from(month_offset) + 1
}

/// ECMA-262 WeekDay - Get days within week (0-6).
fn week_day(&self) -> i32 {
fn week_day(self) -> i32 {
rem_euclid_i32(self.day() + 4.0, 7)
}

/// ECMA-262 LocalTZA - Get local timezone adjustment in milliseconds.
fn local_tza(&self, _is_utc: bool) -> i32 {
fn local_tza(self, _is_utc: bool) -> i32 {
// TODO: Honor `is_utc` flag.
get_timezone().local_minus_utc() * Self::MS_PER_SECOND
}
Expand All @@ -177,36 +177,36 @@ impl Date {
}

/// Get timezone offset in minutes.
fn timezone_offset(&self) -> f64 {
fn timezone_offset(self) -> f64 {
(self.0 - self.local().0) / f64::from(Self::MS_PER_MINUTE)
}

/// ECMA-262 HourFromTime - Get hours (0-23).
fn hours(&self) -> i32 {
fn hours(self) -> i32 {
rem_euclid_i32(
((self.0 + 0.5) / f64::from(Self::MS_PER_HOUR)).floor(),
Self::HOURS_PER_DAY,
)
}

/// ECMA-262 MinFromTime - Get minutes (0-59).
fn minutes(&self) -> i32 {
fn minutes(self) -> i32 {
rem_euclid_i32(
(self.0 / f64::from(Self::MS_PER_MINUTE)).floor(),
Self::MINUTES_PER_HOUR,
)
}

/// ECMA-262 SecFromTime - Get seconds (0-59).
fn seconds(&self) -> i32 {
fn seconds(self) -> i32 {
rem_euclid_i32(
(self.0 / f64::from(Self::MS_PER_SECOND)).floor(),
Self::SECONDS_PER_MINUTE,
)
}

/// ECMA-262 msFromTime - Get milliseconds (0-999).
fn milliseconds(&self) -> i32 {
fn milliseconds(self) -> i32 {
rem_euclid_i32(self.0, Self::MS_PER_SECOND)
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/avm1/globals/local_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ impl<'gc> LocalConnection<'gc> {
None
}

pub fn is_connected(&self) -> bool {
pub fn is_connected(self) -> bool {
self.0.handle.borrow().is_some()
}

pub fn connect(
&self,
self,
activation: &mut Activation<'_, 'gc>,
name: AvmString<'gc>,
this: Object<'gc>,
Expand All @@ -58,7 +58,7 @@ impl<'gc> LocalConnection<'gc> {
result
}

pub fn disconnect(&self, activation: &mut Activation<'_, 'gc>) {
pub fn disconnect(self, activation: &mut Activation<'_, 'gc>) {
if let Some(conn_handle) = self.0.handle.take() {
activation.context.local_connections.close(conn_handle);
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/avm1/globals/movie_clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ fn line_gradient_style<'gc>(
let alphas = alphas.coerce_to_object(activation);
let ratios = ratios.coerce_to_object(activation);
let records = if let Some(records) =
build_gradient_records(activation, "lineGradientStyle()", &colors, &alphas, &ratios)?
build_gradient_records(activation, "lineGradientStyle()", colors, alphas, ratios)?
{
records
} else {
Expand Down Expand Up @@ -480,9 +480,9 @@ fn line_gradient_style<'gc>(
fn build_gradient_records<'gc>(
activation: &mut Activation<'_, 'gc>,
fname: &str,
colors: &Object<'gc>,
alphas: &Object<'gc>,
ratios: &Object<'gc>,
colors: Object<'gc>,
alphas: Object<'gc>,
ratios: Object<'gc>,
) -> Result<Option<Vec<GradientRecord>>, Error<'gc>> {
let colors_length = colors.length(activation)?;
let alphas_length = alphas.length(activation)?;
Expand Down Expand Up @@ -658,7 +658,7 @@ fn begin_gradient_fill<'gc>(
let alphas = alphas.coerce_to_object(activation);
let ratios = ratios.coerce_to_object(activation);
let records = if let Some(records) =
build_gradient_records(activation, "beginGradientFill()", &colors, &alphas, &ratios)?
build_gradient_records(activation, "beginGradientFill()", colors, alphas, ratios)?
{
records
} else {
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/netconnection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ struct NetConnectionData {
pub struct NetConnection<'gc>(Gc<'gc, NetConnectionData>);

impl<'gc> NetConnection<'gc> {
pub fn handle(&self) -> Option<NetConnectionHandle> {
pub fn handle(self) -> Option<NetConnectionHandle> {
self.0.handle.get()
}

pub fn set_handle(&self, handle: Option<NetConnectionHandle>) -> Option<NetConnectionHandle> {
pub fn set_handle(self, handle: Option<NetConnectionHandle>) -> Option<NetConnectionHandle> {
self.0.handle.replace(handle)
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/style_sheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn transform<'gc>(
return Ok(Value::Null);
};

let style_object = match style_object {
let style_object = match *style_object {
Value::Undefined | Value::Null => {
return Ok(Value::Null);
}
Expand All @@ -220,7 +220,7 @@ fn transform<'gc>(

if let Some(style_object) = style_object {
fn get_style<'gc>(
style_object: &Object<'gc>,
style_object: Object<'gc>,
name: &'static str,
activation: &mut Activation<'_, 'gc>,
) -> Option<Value<'gc>> {
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm1/globals/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<'gc> TransformObject<'gc> {
Some(Self { clip })
}

pub fn clip(&self, activation: &mut Activation<'_, 'gc>) -> Option<DisplayObject<'gc>> {
pub fn clip(self, activation: &mut Activation<'_, 'gc>) -> Option<DisplayObject<'gc>> {
let (_, _, clip) = self.clip?.resolve_reference(activation)?;
Some(clip)
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/avm1/globals/xml_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ struct XmlSocketData {
pub struct XmlSocket<'gc>(Gc<'gc, XmlSocketData>);

impl<'gc> XmlSocket<'gc> {
pub fn handle(&self) -> Option<SocketHandle> {
pub fn handle(self) -> Option<SocketHandle> {
self.0.handle.get()
}

pub fn set_handle(&self, handle: SocketHandle) -> Option<SocketHandle> {
pub fn set_handle(self, handle: SocketHandle) -> Option<SocketHandle> {
self.0.handle.replace(Some(handle))
}

pub fn timeout(&self) -> u32 {
pub fn timeout(self) -> u32 {
self.0.timeout.get()
}

pub fn set_timeout(&self, new_timeout: u32) {
pub fn set_timeout(self, new_timeout: u32) {
// FIXME: Check if flash player clamps this to 250 milliseconds like AS3 sockets.
self.0.timeout.set(new_timeout);
}
Expand Down
12 changes: 4 additions & 8 deletions core/src/avm1/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'gc> BoxedF64<'gc> {
}

#[inline]
pub fn value(&self) -> f64 {
pub fn value(self) -> f64 {
#[cfg(target_pointer_width = "64")]
return self.value;
#[cfg(not(target_pointer_width = "64"))]
Expand Down Expand Up @@ -315,7 +315,7 @@ impl<'gc> Object<'gc> {
/// can't implement interfaces within interfaces (fortunately), but if you
/// somehow could this would support that, too.
pub fn is_instance_of(
&self,
self,
activation: &mut Activation<'_, 'gc>,
constructor: Object<'gc>,
prototype: Object<'gc>,
Expand Down Expand Up @@ -351,7 +351,7 @@ impl<'gc> Object<'gc> {
}

/// Get the underlying XML node for this object, if it exists.
pub fn as_xml_node(&self) -> Option<XmlNode<'gc>> {
pub fn as_xml_node(self) -> Option<XmlNode<'gc>> {
match self.native() {
NativeObject::Xml(xml) => Some(xml.root()),
NativeObject::XmlNode(xml_node) => Some(xml_node),
Expand All @@ -360,11 +360,7 @@ impl<'gc> Object<'gc> {
}

/// Check if this object is in the prototype chain of the specified test object.
pub fn is_prototype_of(
&self,
activation: &mut Activation<'_, 'gc>,
other: Object<'gc>,
) -> bool {
pub fn is_prototype_of(self, activation: &mut Activation<'_, 'gc>, other: Object<'gc>) -> bool {
let mut proto = other.proto(activation);

while let Value::Object(proto_ob) = proto {
Expand Down
Loading
Loading