avm2: Split native and script instance initializers for non-constructable classes.
This also includes new errors for attempting to construct non-constructables like `System`.
This commit is contained in:
parent
dcbb5e4284
commit
c8cd6e0322
|
@ -16,6 +16,15 @@ use swf::Twips;
|
|||
|
||||
/// Implements `flash.display.DisplayObject`'s instance constructor.
|
||||
pub fn instance_init<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc, '_>,
|
||||
_this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
Err("You cannot construct DisplayObject directly.".into())
|
||||
}
|
||||
|
||||
/// Implements `flash.display.DisplayObject`'s native instance constructor.
|
||||
pub fn native_instance_init<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
|
@ -603,6 +612,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
|
|||
let mut write = class.write(mc);
|
||||
|
||||
write.set_instance_deriver(stage_deriver);
|
||||
write.set_native_instance_init(Method::from_builtin(native_instance_init));
|
||||
|
||||
const PUBLIC_INSTANCE_PROPERTIES: &[(&str, Option<NativeMethod>, Option<NativeMethod>)] = &[
|
||||
("alpha", Some(alpha), Some(set_alpha)),
|
||||
|
|
|
@ -14,6 +14,15 @@ use std::cmp::min;
|
|||
|
||||
/// Implements `flash.display.DisplayObjectContainer`'s instance constructor.
|
||||
pub fn instance_init<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc, '_>,
|
||||
_this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
Err("You cannot construct DisplayObjectContainer directly.".into())
|
||||
}
|
||||
|
||||
/// Implements `flash.display.DisplayObjectContainer`'s native instance constructor.
|
||||
pub fn native_instance_init<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
|
@ -585,6 +594,8 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
|
|||
|
||||
let mut write = class.write(mc);
|
||||
|
||||
write.set_native_instance_init(Method::from_builtin(native_instance_init));
|
||||
|
||||
const PUBLIC_INSTANCE_PROPERTIES: &[(&str, Option<NativeMethod>, Option<NativeMethod>)] =
|
||||
&[("numChildren", Some(num_children), None)];
|
||||
write.define_public_builtin_instance_properties(PUBLIC_INSTANCE_PROPERTIES);
|
||||
|
|
|
@ -21,6 +21,19 @@ pub fn instance_init<'gc>(
|
|||
Err("Graphics cannot be constructed directly.".into())
|
||||
}
|
||||
|
||||
/// Implements `flash.display.Graphics`'s native instance constructor.
|
||||
pub fn native_instance_init<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
if let Some(this) = this {
|
||||
activation.super_init(this, &[])?;
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
/// Implements `flash.display.Graphics`'s class constructor.
|
||||
pub fn class_init<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc, '_>,
|
||||
|
@ -365,6 +378,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
|
|||
|
||||
write.set_attributes(ClassAttributes::SEALED);
|
||||
write.set_instance_deriver(stage_deriver);
|
||||
write.set_native_instance_init(Method::from_builtin(native_instance_init));
|
||||
|
||||
const PUBLIC_INSTANCE_METHODS: &[(&str, NativeMethod)] = &[
|
||||
("beginFill", begin_fill),
|
||||
|
|
|
@ -11,6 +11,15 @@ use gc_arena::{GcCell, MutationContext};
|
|||
|
||||
/// Implements `flash.display.InteractiveObject`'s instance constructor.
|
||||
pub fn instance_init<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc, '_>,
|
||||
_this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
Err("You cannot directly construct InteractiveObject.".into())
|
||||
}
|
||||
|
||||
/// Implements `flash.display.InteractiveObject`'s native instance constructor.
|
||||
pub fn native_instance_init<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
|
@ -33,11 +42,17 @@ pub fn class_init<'gc>(
|
|||
|
||||
/// Construct `InteractiveObject`'s class.
|
||||
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
|
||||
Class::new(
|
||||
let class = Class::new(
|
||||
QName::new(Namespace::package("flash.display"), "InteractiveObject"),
|
||||
Some(QName::new(Namespace::package("flash.display"), "DisplayObject").into()),
|
||||
Method::from_builtin(instance_init),
|
||||
Method::from_builtin(class_init),
|
||||
mc,
|
||||
)
|
||||
);
|
||||
|
||||
let mut write = class.write(mc);
|
||||
|
||||
write.set_native_instance_init(Method::from_builtin(native_instance_init));
|
||||
|
||||
class
|
||||
}
|
||||
|
|
|
@ -23,6 +23,19 @@ pub fn instance_init<'gc>(
|
|||
Err("LoaderInfo cannot be constructed".into())
|
||||
}
|
||||
|
||||
/// Implements `flash.display.LoaderInfo`'s native instance constructor.
|
||||
pub fn native_instance_init<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
if let Some(this) = this {
|
||||
activation.super_init(this, &[])?;
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
/// Implements `flash.display.LoaderInfo`'s class constructor.
|
||||
pub fn class_init<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc, '_>,
|
||||
|
@ -419,6 +432,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
|
|||
|
||||
write.set_attributes(ClassAttributes::SEALED);
|
||||
write.set_instance_deriver(loaderinfo_deriver);
|
||||
write.set_native_instance_init(Method::from_builtin(native_instance_init));
|
||||
|
||||
const PUBLIC_INSTANCE_PROPERTIES: &[(&str, Option<NativeMethod>, Option<NativeMethod>)] = &[
|
||||
("actionScriptVersion", Some(action_script_version), None),
|
||||
|
|
|
@ -15,12 +15,21 @@ use swf::Color;
|
|||
|
||||
/// Implements `flash.display.Stage`'s instance constructor.
|
||||
pub fn instance_init<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
_activation: &mut Activation<'_, 'gc, '_>,
|
||||
_this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
Err("You cannot construct new instances of the Stage.".into())
|
||||
}
|
||||
|
||||
/// Implements `flash.display.Stage`'s native instance constructor.
|
||||
pub fn native_instance_init<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
if let Some(this) = this {
|
||||
activation.super_init(this, &[])?;
|
||||
activation.super_init(this, args)?;
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
|
@ -630,6 +639,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
|
|||
let mut write = class.write(mc);
|
||||
|
||||
write.set_attributes(ClassAttributes::SEALED);
|
||||
write.set_native_instance_init(Method::from_builtin(native_instance_init));
|
||||
|
||||
const PUBLIC_OVERRIDE_INSTANCE_PROPERTIES: &[(
|
||||
&str,
|
||||
|
|
|
@ -11,15 +11,11 @@ use gc_arena::{GcCell, MutationContext};
|
|||
|
||||
/// Implements `flash.system.System`'s instance constructor.
|
||||
pub fn instance_init<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
_activation: &mut Activation<'_, 'gc, '_>,
|
||||
_this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
if let Some(this) = this {
|
||||
activation.super_init(this, &[])?;
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
Err("The System class cannot be constructed.".into())
|
||||
}
|
||||
|
||||
/// Implements `flash.system.System`'s class constructor.
|
||||
|
|
|
@ -531,7 +531,7 @@ impl<'gc> TDisplayObject<'gc> for Stage<'gc> {
|
|||
// TODO: We should only do this if the movie is actually an AVM2 movie.
|
||||
// This is necessary for EventDispatcher super-constructor to run.
|
||||
let mut activation = Avm2Activation::from_nothing(context.reborrow());
|
||||
if let Err(e) = stage_constr.call(
|
||||
if let Err(e) = stage_constr.call_native_initializer(
|
||||
Some(avm2_stage.into()),
|
||||
&[],
|
||||
&mut activation,
|
||||
|
|
Loading…
Reference in New Issue