Skip to content

Commit

Permalink
avm2: Prefix NativeCallable disp-ids for getters and setters with GET…
Browse files Browse the repository at this point in the history
…_ and SET_

Also use NativeCallable for accessing ContentElement text
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Jan 25, 2025
1 parent 4bf56ad commit 2e75979
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion core/build_playerglobal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,13 @@ fn write_native_table(data: &[u8], out_dir: &Path) -> Result<Vec<u8>, Box<dyn st

let (trait_name, const_name) =
rust_path_and_trait_name(&abc, trait_, parent);
let const_name = quote::format_ident!("{}", const_name);

// Make getters prefixed with GET_ and setters prefixed with SET_
let const_name = match trait_.kind {
TraitKind::Getter { .. } => quote::format_ident!("GET_{}", const_name),
TraitKind::Setter { .. } => quote::format_ident!("SET_{}", const_name),
_ => quote::format_ident!("{}", const_name),
};

// Declare a const with the method name set to the disp id.
rust_accessible_methods
Expand Down
1 change: 1 addition & 0 deletions core/src/avm2/globals/flash/text/engine/ContentElement.as
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package flash.text.engine {
this._elementFormat = elementFormat;
}

[Ruffle(NativeCallable)]
public function get text():String {
return this._text;
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/avm2/globals/flash/text/engine/text_block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::avm2::activation::Activation;
use crate::avm2::error::Error;
use crate::avm2::globals::flash::display::display_object::initialize_for_allocator;
use crate::avm2::globals::methods::flash_text_engine_content_element as element_methods;
use crate::avm2::globals::slots::flash_text_engine_content_element as element_slots;
use crate::avm2::globals::slots::flash_text_engine_element_format as format_slots;
use crate::avm2::globals::slots::flash_text_engine_font_description as font_desc_slots;
Expand Down Expand Up @@ -45,11 +46,11 @@ pub fn create_text_line<'gc>(
)?;
return Ok(Value::Null);
}
// Get the content element's text property.
// Get the content element's text property (it's a getter).
// TODO: GraphicElement?
None => {
let txt = content
.get_public_property("text", activation)
.call_method(element_methods::GET_TEXT, &[], activation)
.unwrap_or_else(|_| activation.strings().empty().into());

if matches!(txt, Value::Null) {
Expand Down

0 comments on commit 2e75979

Please sign in to comment.