avm2: Return whether the event has been handled from dispatch_event
Before that, dispatch_event returned whether the event has been canceled, but the value has never been used. It's possible to check whether the event has been canceled by invoking is_cancelled() on the event.
This commit is contained in:
parent
57e90d947b
commit
250bf64a92
|
@ -434,11 +434,13 @@ impl<'gc> Avm2<'gc> {
|
||||||
/// any resulting error (after logging).
|
/// any resulting error (after logging).
|
||||||
///
|
///
|
||||||
/// Attempts to dispatch a non-event object will panic.
|
/// Attempts to dispatch a non-event object will panic.
|
||||||
|
///
|
||||||
|
/// Returns `true` if the event has been handled.
|
||||||
pub fn dispatch_event(
|
pub fn dispatch_event(
|
||||||
context: &mut UpdateContext<'_, 'gc>,
|
context: &mut UpdateContext<'_, 'gc>,
|
||||||
event: Object<'gc>,
|
event: Object<'gc>,
|
||||||
target: Object<'gc>,
|
target: Object<'gc>,
|
||||||
) {
|
) -> bool {
|
||||||
Self::dispatch_event_internal(context, event, target, false)
|
Self::dispatch_event_internal(context, event, target, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,7 +454,7 @@ impl<'gc> Avm2<'gc> {
|
||||||
context: &mut UpdateContext<'_, 'gc>,
|
context: &mut UpdateContext<'_, 'gc>,
|
||||||
event: Object<'gc>,
|
event: Object<'gc>,
|
||||||
target: Object<'gc>,
|
target: Object<'gc>,
|
||||||
) {
|
) -> bool {
|
||||||
Self::dispatch_event_internal(context, event, target, true)
|
Self::dispatch_event_internal(context, event, target, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,21 +463,24 @@ impl<'gc> Avm2<'gc> {
|
||||||
event: Object<'gc>,
|
event: Object<'gc>,
|
||||||
target: Object<'gc>,
|
target: Object<'gc>,
|
||||||
simulate_dispatch: bool,
|
simulate_dispatch: bool,
|
||||||
) {
|
) -> bool {
|
||||||
let event_name = event
|
let event_name = event
|
||||||
.as_event()
|
.as_event()
|
||||||
.map(|e| e.event_type())
|
.map(|e| e.event_type())
|
||||||
.unwrap_or_else(|| panic!("cannot dispatch non-event object: {:?}", event));
|
.unwrap_or_else(|| panic!("cannot dispatch non-event object: {:?}", event));
|
||||||
|
|
||||||
let mut activation = Activation::from_nothing(context.reborrow());
|
let mut activation = Activation::from_nothing(context.reborrow());
|
||||||
if let Err(err) = events::dispatch_event(&mut activation, target, event, simulate_dispatch)
|
match events::dispatch_event(&mut activation, target, event, simulate_dispatch) {
|
||||||
{
|
Err(err) => {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
"Encountered AVM2 error when dispatching `{}` event: {:?}",
|
"Encountered AVM2 error when dispatching `{}` event: {:?}",
|
||||||
event_name,
|
event_name,
|
||||||
err,
|
err,
|
||||||
);
|
);
|
||||||
// TODO: push the error onto `loaderInfo.uncaughtErrorEvents`
|
// TODO: push the error onto `loaderInfo.uncaughtErrorEvents`
|
||||||
|
false
|
||||||
|
}
|
||||||
|
Ok(handled) => handled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,22 +46,22 @@ pub enum PropagationMode {
|
||||||
#[derive(Clone, Collect)]
|
#[derive(Clone, Collect)]
|
||||||
#[collect(no_drop)]
|
#[collect(no_drop)]
|
||||||
pub struct Event<'gc> {
|
pub struct Event<'gc> {
|
||||||
/// Whether or not the event "bubbles" - fires on it's parents after it
|
/// Whether the event "bubbles" - fires on its parents after it
|
||||||
/// fires on the child.
|
/// fires on the child.
|
||||||
bubbles: bool,
|
bubbles: bool,
|
||||||
|
|
||||||
/// Whether or not the event has a default response that an event handler
|
/// Whether the event has a default response that an event handler
|
||||||
/// can request to not occur.
|
/// can request to not occur.
|
||||||
cancelable: bool,
|
cancelable: bool,
|
||||||
|
|
||||||
/// Whether or not the event's default response has been cancelled.
|
/// Whether the event's default response has been cancelled.
|
||||||
cancelled: bool,
|
cancelled: bool,
|
||||||
|
|
||||||
/// Whether or not event propagation has stopped.
|
/// Whether event propagation has stopped.
|
||||||
#[collect(require_static)]
|
#[collect(require_static)]
|
||||||
propagation: PropagationMode,
|
propagation: PropagationMode,
|
||||||
|
|
||||||
/// The object currently having it's event handlers invoked.
|
/// The object currently having its event handlers invoked.
|
||||||
current_target: Option<Object<'gc>>,
|
current_target: Option<Object<'gc>>,
|
||||||
|
|
||||||
/// The current event phase.
|
/// The current event phase.
|
||||||
|
@ -519,7 +519,6 @@ pub fn dispatch_event<'gc>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let was_not_cancelled = !event.as_event().unwrap().is_cancelled();
|
let handled = event.as_event().unwrap().dispatched;
|
||||||
|
Ok(handled)
|
||||||
Ok(was_not_cancelled)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue