Move `_global` and `_root` to the MovieClip object, and implement `_parent` while we're in here.

This commit is contained in:
David Wendt 2019-10-09 20:37:24 -04:00
parent d35e36def5
commit 0f04d97002
2 changed files with 29 additions and 9 deletions

View File

@ -1017,15 +1017,6 @@ impl<'gc> Avm1<'gc> {
let var_path = self.pop()?; let var_path = self.pop()?;
let path = var_path.as_string()?; let path = var_path.as_string()?;
// Special hardcoded variables
if path == "_root" {
self.push(self.root_object(context));
return Ok(());
} else if path == "_global" {
self.push(self.global_object(context));
return Ok(());
}
let is_slashpath = Self::variable_name_is_slash_path(path); let is_slashpath = Self::variable_name_is_slash_path(path);
let mut result = None; let mut result = None;
if is_slashpath { if is_slashpath {

View File

@ -1,6 +1,7 @@
use crate::avm1::object::{Attribute::*, Object}; use crate::avm1::object::{Attribute::*, Object};
use crate::avm1::Value; use crate::avm1::Value;
use crate::movie_clip::MovieClip; use crate::movie_clip::MovieClip;
use enumset::EnumSet;
use gc_arena::MutationContext; use gc_arena::MutationContext;
macro_rules! with_movie_clip { macro_rules! with_movie_clip {
@ -80,5 +81,33 @@ pub fn create_movie_object<'gc>(gc_context: MutationContext<'gc, '_>) -> Object<
} }
); );
object.force_set_virtual(
"_global",
|avm, context, _this, _args| avm.global_object(context),
None,
EnumSet::new(),
);
object.force_set_virtual(
"_root",
|avm, context, _this, _args| avm.root_object(context),
None,
EnumSet::new(),
);
object.force_set_virtual(
"_parent",
|_avm, _context, this, _args| {
this.read()
.display_node()
.and_then(|mc| mc.read().parent())
.and_then(|dn| dn.read().object().as_object().ok())
.map(|o| Value::Object(o.to_owned()))
.unwrap_or(Value::Undefined)
},
None,
EnumSet::new(),
);
object object
} }