Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avm2: Stub DisplayObject.metaData #15826

Merged
merged 2 commits into from Apr 1, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/avm2/globals/flash/display/DisplayObject.as
Expand Up @@ -88,6 +88,9 @@ package flash.display {
public native function get visible():Boolean;
public native function set visible(value:Boolean):void;

public native function get metaData():Object;
public native function set metaData(value:Object):void;

public native function get mouseX():Number;

public native function get mouseY():Number;
Expand Down
28 changes: 28 additions & 0 deletions core/src/avm2/globals/flash/display/display_object.rs
Expand Up @@ -621,6 +621,34 @@ pub fn set_visible<'gc>(
Ok(Value::Undefined)
}

/// Implements `metaData`'s getter.
pub fn get_meta_data<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
avm2_stub_getter!(activation, "flash.display.DisplayObject", "metaData");
if let Some(dobj) = this.as_display_object() {
return Ok(dobj.meta_data().map_or(Value::Null, Value::Object));
}

Ok(Value::Undefined)
}

/// Implements `metaData`'s setter.
pub fn set_meta_data<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(dobj) = this.as_display_object() {
let obj = args.get_object(activation, 0, "metaData")?;
dobj.set_meta_data(activation.gc(), obj);
}

Ok(Value::Undefined)
}

/// Implements `mouseX`.
pub fn get_mouse_x<'gc>(
activation: &mut Activation<'_, 'gc>,
Expand Down
19 changes: 19 additions & 0 deletions core/src/display_object.rs
Expand Up @@ -225,6 +225,8 @@ pub struct DisplayObjectBase<'gc> {
/// The display object we are currently masking.
maskee: Option<DisplayObject<'gc>>,

meta_data: Option<Avm2Object<'gc>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future, are we sure that this isn't Avm2Value and not Avm2Object?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. Probably unlikely, but it obviously depends on how Flash treats the AMF data in PlaceObject4.


/// The blend mode used when rendering this display object.
/// Values other than the default `BlendMode::Normal` implicitly cause cache-as-bitmap behavior.
#[collect(require_static)]
Expand Down Expand Up @@ -282,6 +284,7 @@ impl<'gc> Default for DisplayObjectBase<'gc> {
next_avm1_clip: None,
masker: None,
maskee: None,
meta_data: None,
sound_transform: Default::default(),
blend_mode: Default::default(),
blend_shader: None,
Expand Down Expand Up @@ -769,6 +772,14 @@ impl<'gc> DisplayObjectBase<'gc> {
fn set_maskee(&mut self, node: Option<DisplayObject<'gc>>) {
self.maskee = node;
}

fn meta_data(&self) -> Option<Avm2Object<'gc>> {
self.meta_data
}

fn set_meta_data(&mut self, value: Avm2Object<'gc>) {
self.meta_data = Some(value);
}
}

struct DrawCacheInfo {
Expand Down Expand Up @@ -1707,6 +1718,14 @@ pub trait TDisplayObject<'gc>:
}
}

fn meta_data(&self) -> Option<Avm2Object<'gc>> {
self.base().meta_data()
}

fn set_meta_data(&self, gc_context: &Mutation<'gc>, value: Avm2Object<'gc>) {
self.base_mut(gc_context).set_meta_data(value);
}

/// The blend mode used when rendering this display object.
/// Values other than the default `BlendMode::Normal` implicitly cause cache-as-bitmap behavior.
fn blend_mode(&self) -> ExtendedBlendMode {
Expand Down
12 changes: 12 additions & 0 deletions tests/tests/swfs/avm2/displayobject_metaData/Test.as
@@ -0,0 +1,12 @@
package {
import flash.display.Sprite;
public class Test extends Sprite {
public function Test() {
trace("this.metaData: " + this.metaData);
var obj = {hello: "World"}
this.metaData = obj;
trace("this.metaData: " + this.metaData);
trace("this.metaData === obj: " + (this.metaData === obj));
}
}
}
3 changes: 3 additions & 0 deletions tests/tests/swfs/avm2/displayobject_metaData/output.txt
@@ -0,0 +1,3 @@
this.metaData: null
this.metaData: [object Object]
this.metaData === obj: true
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm2/displayobject_metaData/test.toml
@@ -0,0 +1 @@
num_ticks = 1