avm2: Implement `Event.toString` (which matches it's valueof behavior)
This commit is contained in:
parent
dc32d7894c
commit
8a787e6153
|
@ -243,6 +243,19 @@ pub fn stop_immediate_propagation<'gc>(
|
|||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
/// Implements `toString`
|
||||
pub fn to_string<'gc>(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
if let Some(this) = this {
|
||||
return this.value_of(activation.context.gc_context);
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
/// Construct `Event`'s class.
|
||||
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
|
||||
let class = Class::new(
|
||||
|
@ -303,6 +316,10 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
|
|||
QName::new(Namespace::public_namespace(), "stopImmediatePropagation"),
|
||||
Method::from_builtin(stop_immediate_propagation),
|
||||
));
|
||||
write.define_instance_trait(Trait::from_method(
|
||||
QName::new(Namespace::public_namespace(), "toString"),
|
||||
Method::from_builtin(to_string),
|
||||
));
|
||||
|
||||
class
|
||||
}
|
||||
|
|
|
@ -5,12 +5,26 @@
|
|||
|
||||
import flash.events.Event;
|
||||
|
||||
trace("//e = new Event(\"test_event\");");
|
||||
var e = new Event("test_event");
|
||||
|
||||
trace("//e.toString()");
|
||||
trace(e.toString());
|
||||
|
||||
trace("//Object.prototype.valueOf.call(e)");
|
||||
trace(Object.prototype.valueOf.call(e));
|
||||
|
||||
trace("//Object.prototype.toString.call(e)");
|
||||
trace(Object.prototype.toString.call(e));
|
||||
|
||||
trace("//e = new Event(\"test_event\", true, true);");
|
||||
e = new Event("test_event", true, true);
|
||||
|
||||
trace("//e.toString()");
|
||||
trace(e.toString());
|
||||
|
||||
trace("//Object.prototype.valueOf.call(e)");
|
||||
trace(Object.prototype.valueOf.call(e));
|
||||
|
||||
trace("//Object.prototype.toString.call(e)");
|
||||
trace(Object.prototype.toString.call(e));
|
|
@ -1,4 +1,14 @@
|
|||
//e = new Event("test_event");
|
||||
//e.toString()
|
||||
[Event type="test_event" bubbles=false cancelable=false eventPhase=2]
|
||||
//Object.prototype.valueOf.call(e)
|
||||
[Event type="test_event" bubbles=false cancelable=false eventPhase=2]
|
||||
//Object.prototype.toString.call(e)
|
||||
[object Event]
|
||||
//e = new Event("test_event", true, true);
|
||||
//e.toString()
|
||||
[Event type="test_event" bubbles=true cancelable=true eventPhase=2]
|
||||
//Object.prototype.valueOf.call(e)
|
||||
[Event type="test_event" bubbles=true cancelable=true eventPhase=2]
|
||||
//Object.prototype.toString.call(e)
|
||||
[object Event]
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue