2020-02-05 18:52:11 +00:00
|
|
|
//! AVM2 objects.
|
|
|
|
|
2020-02-06 04:15:03 +00:00
|
|
|
use crate::avm2::function::FunctionObject;
|
2020-02-11 04:28:05 +00:00
|
|
|
use crate::avm2::names::{Multiname, QName};
|
2020-02-06 04:15:03 +00:00
|
|
|
use crate::avm2::return_value::ReturnValue;
|
2020-02-05 18:52:11 +00:00
|
|
|
use crate::avm2::script_object::ScriptObject;
|
|
|
|
use crate::avm2::value::Value;
|
2020-02-06 04:15:03 +00:00
|
|
|
use crate::avm2::{Avm2, Error};
|
|
|
|
use crate::context::UpdateContext;
|
2020-02-10 19:54:55 +00:00
|
|
|
use enumset::{EnumSet, EnumSetType};
|
|
|
|
use gc_arena::{Collect, MutationContext};
|
2020-02-05 18:52:11 +00:00
|
|
|
use ruffle_macros::enum_trait_object;
|
|
|
|
use std::fmt::Debug;
|
|
|
|
|
2020-02-10 19:54:55 +00:00
|
|
|
/// Attributes of properties in the AVM runtime.
|
|
|
|
///
|
|
|
|
/// TODO: Replace with AVM2 properties for traits
|
|
|
|
#[derive(EnumSetType, Debug)]
|
|
|
|
pub enum Attribute {
|
|
|
|
DontEnum,
|
|
|
|
DontDelete,
|
|
|
|
ReadOnly,
|
|
|
|
}
|
|
|
|
|
2020-02-05 18:52:11 +00:00
|
|
|
/// Represents an object that can be directly interacted with by the AVM2
|
|
|
|
/// runtime.
|
|
|
|
#[enum_trait_object(
|
|
|
|
#[derive(Clone, Collect, Debug, Copy)]
|
|
|
|
#[collect(no_drop)]
|
|
|
|
pub enum Object<'gc> {
|
2020-02-06 04:15:03 +00:00
|
|
|
ScriptObject(ScriptObject<'gc>),
|
|
|
|
FunctionObject(FunctionObject<'gc>)
|
2020-02-05 18:52:11 +00:00
|
|
|
}
|
|
|
|
)]
|
|
|
|
pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy {
|
|
|
|
/// Retrieve a property by it's QName.
|
2020-02-06 04:15:03 +00:00
|
|
|
fn get_property(
|
|
|
|
self,
|
|
|
|
_name: &QName,
|
|
|
|
_avm: &mut Avm2<'gc>,
|
|
|
|
_context: &mut UpdateContext<'_, 'gc, '_>,
|
|
|
|
) -> Result<ReturnValue<'gc>, Error> {
|
|
|
|
Ok(Value::Undefined.into())
|
2020-02-05 18:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Set a property by it's QName.
|
2020-02-06 04:15:03 +00:00
|
|
|
fn set_property(
|
2020-02-10 19:54:55 +00:00
|
|
|
self,
|
2020-02-06 04:15:03 +00:00
|
|
|
_name: &QName,
|
|
|
|
_value: Value<'gc>,
|
|
|
|
_avm: &mut Avm2<'gc>,
|
|
|
|
_context: &mut UpdateContext<'_, 'gc, '_>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-02-11 04:28:05 +00:00
|
|
|
/// Resolve a multiname into a single QName, if any of the namespaces
|
|
|
|
/// match.
|
|
|
|
fn resolve_multiname(self, _multiname: &Multiname) -> Option<QName> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:54:55 +00:00
|
|
|
/// Indicates whether or not a property exists on an object.
|
|
|
|
fn has_property(self, _name: &QName) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Indicates whether or not a property exists on an object and is not part
|
|
|
|
/// of the prototype chain.
|
|
|
|
fn has_own_property(self, _name: &QName) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Indicates whether or not a property is overwritable.
|
|
|
|
fn is_property_overwritable(self, _name: &QName) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Delete a named property from the object.
|
|
|
|
///
|
|
|
|
/// Returns false if the property cannot be deleted.
|
2020-02-11 04:28:05 +00:00
|
|
|
fn delete(&self, gc_context: MutationContext<'gc, '_>, multiname: &QName) -> bool {
|
2020-02-10 19:54:55 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Retrieve the `__proto__` of a given object.
|
|
|
|
///
|
|
|
|
/// The proto is another object used to resolve methods across a class of
|
|
|
|
/// multiple objects. It should also be accessible as `__proto__` from
|
|
|
|
/// `get`.
|
|
|
|
fn proto(&self) -> Option<Object<'gc>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Define a value on an object.
|
|
|
|
///
|
|
|
|
/// Unlike setting a value, this function is intended to replace any
|
|
|
|
/// existing virtual or built-in properties already installed on a given
|
|
|
|
/// object. As such, this should not run any setters; the resulting name
|
|
|
|
/// slot should either be completely replaced with the value or completely
|
|
|
|
/// untouched.
|
|
|
|
///
|
|
|
|
/// It is not guaranteed that all objects accept value definitions,
|
|
|
|
/// especially if a property name conflicts with a built-in property, such
|
|
|
|
/// as `__proto__`.
|
|
|
|
fn define_value(
|
|
|
|
&self,
|
|
|
|
gc_context: MutationContext<'gc, '_>,
|
|
|
|
name: &QName,
|
|
|
|
value: Value<'gc>,
|
|
|
|
attributes: EnumSet<Attribute>,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2020-02-08 03:42:04 +00:00
|
|
|
/// Call the object.
|
|
|
|
fn call(
|
|
|
|
self,
|
|
|
|
_reciever: Object<'gc>,
|
|
|
|
_arguments: &[Value<'gc>],
|
|
|
|
_avm: &mut Avm2<'gc>,
|
|
|
|
_context: &mut UpdateContext<'_, 'gc, '_>,
|
|
|
|
) -> Result<ReturnValue<'gc>, Error> {
|
|
|
|
Err("Object is not callable".into())
|
|
|
|
}
|
|
|
|
|
2020-02-06 04:15:03 +00:00
|
|
|
/// Get a raw pointer value for this object.
|
|
|
|
fn as_ptr(&self) -> *const ObjectPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum ObjectPtr {}
|
|
|
|
|
|
|
|
impl<'gc> Object<'gc> {
|
|
|
|
pub fn ptr_eq(a: Object<'gc>, b: Object<'gc>) -> bool {
|
|
|
|
a.as_ptr() == b.as_ptr()
|
|
|
|
}
|
2020-02-05 18:52:11 +00:00
|
|
|
}
|