avm22: Stub Namespace.prefix and Namespace.uri
This commit is contained in:
parent
d2754bc599
commit
28b5c9051c
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
use crate::avm2::activation::Activation;
|
use crate::avm2::activation::Activation;
|
||||||
use crate::avm2::class::Class;
|
use crate::avm2::class::Class;
|
||||||
use crate::avm2::method::Method;
|
use crate::avm2::method::{Method, NativeMethodImpl};
|
||||||
use crate::avm2::object::{namespace_allocator, Object, TObject};
|
use crate::avm2::object::{namespace_allocator, Object, TObject};
|
||||||
use crate::avm2::value::Value;
|
use crate::avm2::value::Value;
|
||||||
use crate::avm2::Error;
|
use crate::avm2::Error;
|
||||||
use crate::avm2::Multiname;
|
use crate::avm2::Multiname;
|
||||||
use crate::avm2::Namespace;
|
use crate::avm2::Namespace;
|
||||||
use crate::avm2::QName;
|
use crate::avm2::QName;
|
||||||
use crate::avm2_stub_constructor;
|
use crate::{avm2_stub_constructor, avm2_stub_getter};
|
||||||
use gc_arena::GcCell;
|
use gc_arena::GcCell;
|
||||||
|
|
||||||
/// Implements `Namespace`'s instance initializer.
|
/// Implements `Namespace`'s instance initializer.
|
||||||
|
@ -76,6 +76,33 @@ pub fn class_init<'gc>(
|
||||||
Ok(Value::Undefined)
|
Ok(Value::Undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements `Namespace.prefix`'s getter
|
||||||
|
pub fn prefix<'gc>(
|
||||||
|
activation: &mut Activation<'_, 'gc>,
|
||||||
|
this: Option<Object<'gc>>,
|
||||||
|
_args: &[Value<'gc>],
|
||||||
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
|
if this.and_then(|t| t.as_namespace_object()).is_some() {
|
||||||
|
avm2_stub_getter!(activation, "Namespace", "prefix");
|
||||||
|
return Ok("".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Undefined)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implements `Namespace.uri`'s getter
|
||||||
|
pub fn uri<'gc>(
|
||||||
|
_activation: &mut Activation<'_, 'gc>,
|
||||||
|
this: Option<Object<'gc>>,
|
||||||
|
_args: &[Value<'gc>],
|
||||||
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
|
if let Some(o) = this.and_then(|t| t.as_namespace_object()) {
|
||||||
|
return Ok(o.namespace().as_uri().into());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Undefined)
|
||||||
|
}
|
||||||
|
|
||||||
/// Construct `Namespace`'s class.
|
/// Construct `Namespace`'s class.
|
||||||
pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Class<'gc>> {
|
pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Class<'gc>> {
|
||||||
let mc = activation.context.gc_context;
|
let mc = activation.context.gc_context;
|
||||||
|
@ -100,5 +127,16 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Cl
|
||||||
mc,
|
mc,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
const PUBLIC_INSTANCE_PROPERTIES: &[(
|
||||||
|
&str,
|
||||||
|
Option<NativeMethodImpl>,
|
||||||
|
Option<NativeMethodImpl>,
|
||||||
|
)] = &[("prefix", Some(prefix), None), ("uri", Some(uri), None)];
|
||||||
|
write.define_builtin_instance_properties(
|
||||||
|
mc,
|
||||||
|
activation.avm2().public_namespace,
|
||||||
|
PUBLIC_INSTANCE_PROPERTIES,
|
||||||
|
);
|
||||||
|
|
||||||
class
|
class
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,10 @@ impl<'gc> NamespaceObject<'gc> {
|
||||||
pub fn init_namespace(&self, mc: MutationContext<'gc, '_>, namespace: Namespace<'gc>) {
|
pub fn init_namespace(&self, mc: MutationContext<'gc, '_>, namespace: Namespace<'gc>) {
|
||||||
self.0.write(mc).namespace = namespace;
|
self.0.write(mc).namespace = namespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn namespace(self) -> Namespace<'gc> {
|
||||||
|
return self.0.read().namespace;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'gc> TObject<'gc> for NamespaceObject<'gc> {
|
impl<'gc> TObject<'gc> for NamespaceObject<'gc> {
|
||||||
|
|
|
@ -5,3 +5,7 @@ package {
|
||||||
|
|
||||||
var xml = <foo>bar</foo>;
|
var xml = <foo>bar</foo>;
|
||||||
trace("xml.namespace(): " + xml.namespace());
|
trace("xml.namespace(): " + xml.namespace());
|
||||||
|
|
||||||
|
var ns = xml.namespace();
|
||||||
|
trace("ns.prefix: " + ns.prefix);
|
||||||
|
trace("ns.uri: " + ns.uri);
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
xml.namespace():
|
xml.namespace():
|
||||||
|
ns.prefix:
|
||||||
|
ns.uri:
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue