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: Use direct slot access in more native code #18911

Merged
merged 35 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1e8571c
avm2: Remove two more uses of `coerce_to_object` in `Activation`
Dec 8, 2024
23787cc
avm2: Make internal Timer.onUpdate a closure stored in a slot
Dec 8, 2024
d4714a9
avm2: Use slot access when natively accessing fields of Point
Dec 8, 2024
3124364
chore: Format Point with spaces instead of tabs
Dec 8, 2024
f730365
avm2: Use slot access when natively accessing fields of Rectangle and…
Dec 8, 2024
52979db
avm2: Use slot access when natively accessing fields of URLRequest
Dec 8, 2024
c881ff1
chore: Reformat URLRequest with spaces instead of tabs
Dec 8, 2024
f5c39eb
avm2: Replace many uses of `set_public_property` with `set_string_pro…
Dec 9, 2024
4c78c19
avm2: Simplify Vector.prototype access in class initializer
Dec 9, 2024
761d5b0
avm2: Make SoundTransform an Object variant
Dec 9, 2024
68c6def
avm2: Use slot access in `mouse_event::local_to_stage_x/y`
Dec 9, 2024
82c1357
avm2: Use `set_string_property_local` instead of `set_public_property…
Dec 9, 2024
ae2ea00
avm2: Simplify some BitmapData code
Dec 9, 2024
1e47acb
avm2: Use slot access when natively accessing fields of URLLoader
Dec 9, 2024
2692c26
chore: Format URLLoader with spaces instead of tabs
Dec 9, 2024
8785897
core/avm2: Simplify AVM2 loading code
Dec 9, 2024
fe77b81
avm2: Use slot access to access `XML.prettyPrinting` and `XML.prettyI…
Dec 9, 2024
8b74930
avm2: Use slot access in native implementation of `navigateToURL`
Dec 9, 2024
0a1292f
avm2: Use slot access in native Transform methods
Dec 9, 2024
9ebfee8
chore: Reformat Matrix with spaces instead of tabs
Dec 9, 2024
7dd69b9
chore: Reformat Transform with spaces instead of tabs
Dec 9, 2024
e0e3680
avm2: Remove `Activation` parameter on `transform::get_display_object`
Dec 9, 2024
6b488a1
avm2: Use slot access when setting fields on ID3Info
Dec 9, 2024
9378a82
avm2: Remove a few more uses of `get_public_property`
Dec 9, 2024
297340b
avm2: Use slot access in ContextMenu code
Dec 9, 2024
b4018a5
avm2: Remove a few `set_public_property` calls in Shader code
Dec 10, 2024
1bdee4e
avm2: Use slot access in native code for ShaderJob
Dec 10, 2024
cba0a6b
avm2: Use slot access in native code for DisplayObject
Dec 10, 2024
a73f46e
avm2: Use slot access in native FileReference code
Dec 10, 2024
fd87517
avm2: Remove uses of internal flash.text.engine namespace
Dec 10, 2024
e5d7993
avm2: Use slot access in remaining TextBlock code
Dec 10, 2024
8995df4
avm2: Use slot access in native code for Graphics
Dec 10, 2024
70355c1
avm2: Mark more TObject functions `#[no_dynamic]`
Dec 11, 2024
6adf40e
avm2: Add infallible `ScriptObject::new_object` and use it to constru…
Dec 11, 2024
269afce
tests: Add test for `3 instanceof int` and `uint.prototype.toString.p…
Dec 10, 2024
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
38 changes: 19 additions & 19 deletions core/src/avm2/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
ScriptObject::catch_scope(self, &vname)
} else {
// for `finally` scopes, FP just creates a normal object.
self.avm2().classes().object.construct(self, &[])?
ScriptObject::new_object(self)
};

self.push_stack(so);
Expand Down Expand Up @@ -1813,13 +1813,13 @@ impl<'a, 'gc> Activation<'a, 'gc> {
}

fn op_new_object(&mut self, num_args: u32) -> Result<FrameControl<'gc>, Error<'gc>> {
let object = self.context.avm2.classes().object.construct(self, &[])?;
let object = ScriptObject::new_object(self);

for _ in 0..num_args {
let value = self.pop_stack();
let name = self.pop_stack();

object.set_public_property(name.coerce_to_string(self)?, value, self)?;
object.set_string_property_local(name.coerce_to_string(self)?, value, self)?;
}

self.push_stack(object);
Expand All @@ -1835,7 +1835,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let method_entry = self.table_method(method, index, true)?;
let scope = self.create_scopechain();

let new_fn = FunctionObject::from_function(self, method_entry, scope)?;
let new_fn = FunctionObject::from_method(self, method_entry, scope, None, None, None);

self.push_stack(new_fn);

Expand Down Expand Up @@ -2527,13 +2527,15 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let object = self.pop_stack();
if matches!(object, Value::Undefined | Value::Null) {
self.push_raw(0.0);
} else if let Some(next_index) = object
.as_object()
.map(|o| o.get_next_enumerant(cur_index, self))
.transpose()?
.flatten()
{
self.push_raw(next_index);
} else {
let object = object.coerce_to_object(self)?;
if let Some(next_index) = object.get_next_enumerant(cur_index, self)? {
self.push_raw(next_index);
} else {
self.push_raw(0.0);
}
self.push_raw(0.0);
}

Ok(FrameControl::Continue)
Expand Down Expand Up @@ -2689,16 +2691,14 @@ impl<'a, 'gc> Activation<'a, 'gc> {

let value = self.pop_stack();

if let Ok(value) = value.coerce_to_object(self) {
let is_instance_of = value.is_instance_of(self, type_object)?;
match value {
Value::Undefined => return Err(make_null_or_undefined_error(self, value, None)),
Value::Null => self.push_raw(false),
value => {
let is_instance_of = value.is_instance_of(self, type_object);

self.push_raw(is_instance_of);
} else if matches!(value, Value::Undefined) {
// undefined
return Err(make_null_or_undefined_error(self, value, None));
} else {
// null
self.push_raw(false);
self.push_raw(is_instance_of);
}
}

Ok(FrameControl::Continue)
Expand Down
14 changes: 5 additions & 9 deletions core/src/avm2/amf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::rc::Rc;
use super::property::Property;
use crate::avm2::bytearray::ByteArrayStorage;
use crate::avm2::class::Class;
use crate::avm2::object::{ByteArrayObject, ClassObject, TObject, VectorObject};
use crate::avm2::object::{ByteArrayObject, ClassObject, ScriptObject, TObject, VectorObject};
use crate::avm2::vector::VectorStorage;
use crate::avm2::ArrayObject;
use crate::avm2::ArrayStorage;
Expand Down Expand Up @@ -315,7 +315,7 @@ pub fn deserialize_value_impl<'gc>(

// Now let's add each element as a property
for element in elements {
array.set_public_property(
array.set_string_property_local(
AvmString::new_utf8(activation.context.gc_context, element.name()),
deserialize_value_impl(activation, element.value(), object_map)?,
activation,
Expand Down Expand Up @@ -473,7 +473,7 @@ pub fn deserialize_value_impl<'gc>(
dict_obj.set_property_by_object(key, value, activation.context.gc_context);
} else {
let key_string = key.coerce_to_string(activation)?;
dict_obj.set_public_property(key_string, value, activation)?;
dict_obj.set_string_property_local(key_string, value, activation)?;
}
}
dict_obj.into()
Expand Down Expand Up @@ -507,14 +507,10 @@ pub fn deserialize_lso<'gc>(
activation: &mut Activation<'_, 'gc>,
lso: &Lso,
) -> Result<Object<'gc>, Error<'gc>> {
let obj = activation
.avm2()
.classes()
.object
.construct(activation, &[])?;
let obj = ScriptObject::new_object(activation);

for child in &lso.body {
obj.set_public_property(
obj.set_string_property_local(
AvmString::new_utf8(activation.context.gc_context, &child.name),
deserialize_value(activation, child.value())?,
activation,
Expand Down
29 changes: 12 additions & 17 deletions core/src/avm2/e4x.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
use std::{
cell::{Ref, RefMut},
fmt::{self, Debug},
};
use crate::avm2::error::{make_error_1010, make_error_1085, make_error_1118, type_error};
use crate::avm2::globals::slots::xml as xml_class_slots;
use crate::avm2::object::{E4XOrXml, FunctionObject, NamespaceObject};
use crate::avm2::{Activation, Error, Multiname, TObject, Value};
use crate::string::{AvmString, WStr, WString};
use crate::xml::custom_unescape;

use gc_arena::{Collect, GcCell, Mutation};

use quick_xml::{
errors::{IllFormedError, SyntaxError as XmlSyntaxError},
events::{attributes::AttrError as XmlAttrError, BytesStart, Event},
name::ResolveResult,
Error as XmlError, NsReader,
};

use crate::{avm2::TObject, xml::custom_unescape};

use super::{
error::{make_error_1010, make_error_1085, make_error_1118, type_error},
object::{E4XOrXml, FunctionObject, NamespaceObject},
string::AvmString,
Activation, Error, Multiname, Value,
};
use crate::string::{WStr, WString};
use std::cell::{Ref, RefMut};
use std::fmt::{self, Debug};

mod is_xml_name;
mod iterators;
Expand Down Expand Up @@ -1664,16 +1660,15 @@ pub fn to_xml_string<'gc>(
.avm2()
.classes()
.xml
.get_public_property("prettyPrinting", activation)
.expect("prettyPrinting should be set")
.get_slot(xml_class_slots::PRETTY_PRINTING)
.coerce_to_boolean();

let pretty = if pretty_printing {
let pretty_indent = activation
.avm2()
.classes()
.xml
.get_public_property("prettyIndent", activation)
.expect("prettyIndent should be set")
.get_slot(xml_class_slots::PRETTY_INDENT)
.coerce_to_i32(activation)
.expect("shouldn't error");

Expand Down
9 changes: 3 additions & 6 deletions core/src/avm2/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use swf::{
};

use crate::avm2::error::{make_error_2008, type_error};
use crate::avm2::globals::slots::flash_geom_point as point_slots;
use crate::avm2::{Activation, ArrayObject, ClassObject, Error, Object, TObject, Value};

use super::globals::flash::display::shader_job::get_shader_args;
Expand Down Expand Up @@ -458,12 +459,8 @@ fn avm2_to_displacement_map_filter<'gc>(
let map_point =
if let Value::Object(point) = object.get_public_property("mapPoint", activation)? {
(
point
.get_public_property("x", activation)?
.coerce_to_i32(activation)?,
point
.get_public_property("y", activation)?
.coerce_to_i32(activation)?,
point.get_slot(point_slots::X).coerce_to_i32(activation)?,
point.get_slot(point_slots::Y).coerce_to_i32(activation)?,
)
} else {
(0, 0)
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm2/flv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn avm2_object_from_flv_variables<'gc>(
let property_name = value.name;

info_object
.set_public_property(
.set_string_property_local(
AvmString::new_utf8_bytes(activation.context.gc_context, property_name),
value.data.to_avm2_value(activation),
activation,
Expand Down
3 changes: 3 additions & 0 deletions core/src/avm2/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ pub struct SystemClassDefs<'gc> {
pub rectangletexture: Class<'gc>,
pub display_object: Class<'gc>,
pub sprite: Class<'gc>,
pub contextmenuitem: Class<'gc>,
}

impl<'gc> SystemClasses<'gc> {
Expand Down Expand Up @@ -380,6 +381,7 @@ impl<'gc> SystemClassDefs<'gc> {
rectangletexture: object,
display_object: object,
sprite: object,
contextmenuitem: object,
}
}
}
Expand Down Expand Up @@ -1004,6 +1006,7 @@ pub fn init_native_system_classes(activation: &mut Activation<'_, '_>) {
"RectangleTexture",
rectangletexture
),
("flash.ui", "ContextMenuItem", contextmenuitem),
]
);
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/avm2/globals/XML.as
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ package {
public static var ignoreComments:Boolean = true;
public static var ignoreProcessingInstructions:Boolean = true;
public static var ignoreWhitespace:Boolean = true;

[Ruffle(InternalSlot)]
public static var prettyPrinting:Boolean = true;

[Ruffle(InternalSlot)]
public static var prettyIndent:int = 2;

prototype.hasComplexContent = function():Boolean {
Expand Down
Loading