ruffle/core/src/avm2/script_object.rs

39 lines
1014 B
Rust
Raw Normal View History

//! Default AVM2 object impl
use crate::avm2::names::QName;
2020-02-10 19:54:55 +00:00
use crate::avm2::object::{Object, ObjectPtr, TObject};
use crate::avm2::value::Value;
2020-02-10 19:54:55 +00:00
use gc_arena::{Collect, GcCell, MutationContext};
use std::collections::HashMap;
use std::fmt::Debug;
/// Default implementation of `avm2::Object`.
#[derive(Clone, Collect, Debug, Copy)]
#[collect(no_drop)]
pub struct ScriptObject<'gc>(GcCell<'gc, ScriptObjectData<'gc>>);
#[derive(Clone, Collect, Debug)]
#[collect(no_drop)]
pub struct ScriptObjectData<'gc> {
/// Properties stored on this object.
values: HashMap<QName, Value<'gc>>,
}
impl<'gc> TObject<'gc> for ScriptObject<'gc> {
fn as_ptr(&self) -> *const ObjectPtr {
self.0.as_ptr() as *const ObjectPtr
}
}
2020-02-10 19:54:55 +00:00
impl<'gc> ScriptObject<'gc> {
pub fn bare_object(mc: MutationContext<'gc, '_>) -> Object<'gc> {
ScriptObject(GcCell::allocate(
mc,
ScriptObjectData {
values: HashMap::new(),
},
))
.into()
}
}