Skip to content

Commit a73e717

Browse files
committed
core: Move TDisplayObject downcast methods to DisplayObject
Calling these methods on concrete `TDisplayObject` types never makes sense, and defining them directly on `DisplayObject` allows a substantial reduction in boilerplate.
1 parent 9c5c3cd commit a73e717

28 files changed

+110
-195
lines changed

core/src/avm1/globals/button.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn tab_index<'gc>(
164164
this: Avm1Button<'gc>,
165165
_activation: &mut Activation<'_, 'gc>,
166166
) -> Result<Value<'gc>, Error<'gc>> {
167-
if let Some(index) = this.as_interactive().and_then(|this| this.tab_index()) {
167+
if let Some(index) = this.tab_index() {
168168
Ok(Value::Number(index as f64))
169169
} else {
170170
Ok(Value::Undefined)
@@ -176,18 +176,16 @@ fn set_tab_index<'gc>(
176176
activation: &mut Activation<'_, 'gc>,
177177
value: Value<'gc>,
178178
) -> Result<(), Error<'gc>> {
179-
if let Some(this) = this.as_interactive() {
180-
let value = match value {
181-
Value::Undefined | Value::Null => None,
182-
Value::Bool(_) | Value::Number(_) => {
183-
// FIXME This coercion is not perfect, as it wraps
184-
// instead of falling back to MIN, as FP does
185-
let i32_value = value.coerce_to_i32(activation)?;
186-
Some(i32_value)
187-
}
188-
_ => Some(i32::MIN),
189-
};
190-
this.set_tab_index(value);
191-
}
179+
let value = match value {
180+
Value::Undefined | Value::Null => None,
181+
Value::Bool(_) | Value::Number(_) => {
182+
// FIXME This coercion is not perfect, as it wraps
183+
// instead of falling back to MIN, as FP does
184+
let i32_value = value.coerce_to_i32(activation)?;
185+
Some(i32_value)
186+
}
187+
_ => Some(i32::MIN),
188+
};
189+
this.set_tab_index(value);
192190
Ok(())
193191
}

core/src/avm1/globals/movie_clip.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ fn tab_index<'gc>(
17931793
this: MovieClip<'gc>,
17941794
_activation: &mut Activation<'_, 'gc>,
17951795
) -> Result<Value<'gc>, Error<'gc>> {
1796-
if let Some(index) = this.as_interactive().and_then(|this| this.tab_index()) {
1796+
if let Some(index) = this.tab_index() {
17971797
Ok(Value::Number(index as f64))
17981798
} else {
17991799
Ok(Value::Undefined)
@@ -1805,18 +1805,16 @@ fn set_tab_index<'gc>(
18051805
activation: &mut Activation<'_, 'gc>,
18061806
value: Value<'gc>,
18071807
) -> Result<(), Error<'gc>> {
1808-
if let Some(this) = this.as_interactive() {
1809-
let value = match value {
1810-
Value::Undefined | Value::Null => None,
1811-
Value::Bool(_) | Value::Number(_) => {
1812-
// FIXME This coercion is not perfect, as it wraps
1813-
// instead of falling back to MIN, as FP does
1814-
let i32_value = value.coerce_to_i32(activation)?;
1815-
Some(i32_value)
1816-
}
1817-
_ => Some(i32::MIN),
1818-
};
1819-
this.set_tab_index(value);
1820-
}
1808+
let value = match value {
1809+
Value::Undefined | Value::Null => None,
1810+
Value::Bool(_) | Value::Number(_) => {
1811+
// FIXME This coercion is not perfect, as it wraps
1812+
// instead of falling back to MIN, as FP does
1813+
let i32_value = value.coerce_to_i32(activation)?;
1814+
Some(i32_value)
1815+
}
1816+
_ => Some(i32::MIN),
1817+
};
1818+
this.set_tab_index(value);
18211819
Ok(())
18221820
}

core/src/avm1/globals/text_field.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ pub fn tab_index<'gc>(
882882
this: EditText<'gc>,
883883
_activation: &mut Activation<'_, 'gc>,
884884
) -> Result<Value<'gc>, Error<'gc>> {
885-
if let Some(index) = this.as_interactive().and_then(|this| this.tab_index()) {
885+
if let Some(index) = this.tab_index() {
886886
Ok(Value::Number(index as u32 as f64))
887887
} else {
888888
Ok(Value::Undefined)
@@ -894,19 +894,17 @@ pub fn set_tab_index<'gc>(
894894
activation: &mut Activation<'_, 'gc>,
895895
value: Value<'gc>,
896896
) -> Result<(), Error<'gc>> {
897-
if let Some(this) = this.as_interactive() {
898-
let value = match value {
899-
Value::Undefined | Value::Null => None,
900-
_ => {
901-
// `tabIndex` is u32 in TextField, compared to i32 in Button and MovieClip,
902-
// but that is only a data representation difference,
903-
// as both are interpreted as i32.
904-
let u32_value = value.coerce_to_u32(activation)?;
905-
Some(u32_value as i32)
906-
}
907-
};
908-
this.set_tab_index(value);
909-
}
897+
let value = match value {
898+
Value::Undefined | Value::Null => None,
899+
_ => {
900+
// `tabIndex` is u32 in TextField, compared to i32 in Button and MovieClip,
901+
// but that is only a data representation difference,
902+
// as both are interpreted as i32.
903+
let u32_value = value.coerce_to_u32(activation)?;
904+
Some(u32_value as i32)
905+
}
906+
};
907+
this.set_tab_index(value);
910908
Ok(())
911909
}
912910

core/src/avm1/globals/video.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::avm1::object::NativeObject;
66
use crate::avm1::property_decl::{define_properties_on, Declaration};
77
use crate::avm1::value::Value;
88
use crate::avm1::Object;
9-
use crate::display_object::{TDisplayObject, Video};
9+
use crate::display_object::Video;
1010
use crate::string::StringContext;
1111

1212
macro_rules! video_method {

core/src/avm2/globals/flash/display/bitmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::avm2::error::make_error_2008;
1313
use crate::avm2::parameters::ParametersExt;
1414
use crate::bitmap::bitmap_data::BitmapDataWrapper;
1515
use crate::character::Character;
16-
use crate::display_object::{Bitmap, TDisplayObject};
16+
use crate::display_object::Bitmap;
1717

1818
pub fn bitmap_allocator<'gc>(
1919
class: ClassObject<'gc>,

core/src/avm2/globals/flash/display/bitmap_data.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::bitmap::bitmap_data::{
2222
use crate::bitmap::bitmap_data::{BitmapDataDrawError, IBitmapDrawable};
2323
use crate::bitmap::{is_size_valid, operations};
2424
use crate::character::{Character, CompressedBitmap};
25-
use crate::display_object::TDisplayObject;
2625
use crate::ecma_conversions::round_to_even;
2726
use crate::swf::BlendMode;
2827
use gc_arena::GcCell;

core/src/avm2/globals/flash/display/interactive_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::avm2::error::make_error_2027;
55
use crate::avm2::parameters::ParametersExt;
66
use crate::avm2::value::Value;
77
use crate::avm2::Error;
8-
use crate::display_object::{TDisplayObject, TInteractiveObject};
8+
use crate::display_object::TInteractiveObject;
99

1010
/// Implements `InteractiveObject.mouseEnabled`'s getter.
1111
pub fn get_mouse_enabled<'gc>(

core/src/avm2/globals/flash/display/movie_clip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::avm2::object::ArrayObject;
77
use crate::avm2::parameters::ParametersExt;
88
use crate::avm2::value::Value;
99
use crate::avm2::Error;
10-
use crate::display_object::{MovieClip, Scene, TDisplayObject};
10+
use crate::display_object::{MovieClip, Scene};
1111
use crate::string::{AvmString, WString};
1212

1313
/// Implements `addFrameScript`, an undocumented method of `MovieClip` used to

core/src/avm2/globals/flash/media/video.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::avm2::globals::flash::display::display_object::initialize_for_allocat
33
use crate::avm2::parameters::ParametersExt;
44
use crate::avm2::{Activation, ClassObject, Object, Value};
55
use crate::avm2_stub_method;
6-
use crate::display_object::{TDisplayObject, Video};
6+
use crate::display_object::Video;
77

88
pub fn video_allocator<'gc>(
99
class: ClassObject<'gc>,

core/src/avm2/globals/flash/text/engine/text_line.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::avm2::activation::Activation;
22
use crate::avm2::error::Error;
33
use crate::avm2::value::Value;
4-
use crate::display_object::TDisplayObject;
54

65
pub fn get_text_width<'gc>(
76
activation: &mut Activation<'_, 'gc>,

0 commit comments

Comments
 (0)