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).
|
||||
///
|
||||
/// Attempts to dispatch a non-event object will panic.
|
||||
///
|
||||
/// Returns `true` if the event has been handled.
|
||||
pub fn dispatch_event(
|
||||
context: &mut UpdateContext<'_, 'gc>,
|
||||
event: Object<'gc>,
|
||||
target: Object<'gc>,
|
||||
) {
|
||||
) -> bool {
|
||||
Self::dispatch_event_internal(context, event, target, false)
|
||||
}
|
||||
|
||||
|
@ -452,7 +454,7 @@ impl<'gc> Avm2<'gc> {
|
|||
context: &mut UpdateContext<'_, 'gc>,
|
||||
event: Object<'gc>,
|
||||
target: Object<'gc>,
|
||||
) {
|
||||
) -> bool {
|
||||
Self::dispatch_event_internal(context, event, target, true)
|
||||
}
|
||||
|
||||
|
@ -461,21 +463,24 @@ impl<'gc> Avm2<'gc> {
|
|||
event: Object<'gc>,
|
||||
target: Object<'gc>,
|
||||
simulate_dispatch: bool,
|
||||
) {
|
||||
) -> bool {
|
||||
let event_name = event
|
||||
.as_event()
|
||||
.map(|e| e.event_type())
|
||||
.unwrap_or_else(|| panic!("cannot dispatch non-event object: {:?}", event));
|
||||
|
||||
let mut activation = Activation::from_nothing(context.reborrow());
|
||||
if let Err(err) = events::dispatch_event(&mut activation, target, event, simulate_dispatch)
|
||||
{
|
||||
tracing::error!(
|
||||
"Encountered AVM2 error when dispatching `{}` event: {:?}",
|
||||
event_name,
|
||||
err,
|
||||
);
|
||||
// TODO: push the error onto `loaderInfo.uncaughtErrorEvents`
|
||||
match events::dispatch_event(&mut activation, target, event, simulate_dispatch) {
|
||||
Err(err) => {
|
||||
tracing::error!(
|
||||
"Encountered AVM2 error when dispatching `{}` event: {:?}",
|
||||
event_name,
|
||||
err,
|
||||
);
|
||||
// TODO: push the error onto `loaderInfo.uncaughtErrorEvents`
|
||||
false
|
||||
}
|
||||
Ok(handled) => handled,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,22 +46,22 @@ pub enum PropagationMode {
|
|||
#[derive(Clone, Collect)]
|
||||
#[collect(no_drop)]
|
||||
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.
|
||||
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.
|
||||
cancelable: bool,
|
||||
|
||||
/// Whether or not the event's default response has been cancelled.
|
||||
/// Whether the event's default response has been cancelled.
|
||||
cancelled: bool,
|
||||
|
||||
/// Whether or not event propagation has stopped.
|
||||
/// Whether event propagation has stopped.
|
||||
#[collect(require_static)]
|
||||
propagation: PropagationMode,
|
||||
|
||||
/// The object currently having it's event handlers invoked.
|
||||
/// The object currently having its event handlers invoked.
|
||||
current_target: Option<Object<'gc>>,
|
||||
|
||||
/// The current event phase.
|
||||
|
@ -519,7 +519,6 @@ pub fn dispatch_event<'gc>(
|
|||
}
|
||||
}
|
||||
|
||||
let was_not_cancelled = !event.as_event().unwrap().is_cancelled();
|
||||
|
||||
Ok(was_not_cancelled)
|
||||
let handled = event.as_event().unwrap().dispatched;
|
||||
Ok(handled)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue