diff --git a/core/src/avm2.rs b/core/src/avm2.rs index 98e6f59c1..03d3a65f6 100644 --- a/core/src/avm2.rs +++ b/core/src/avm2.rs @@ -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, } } diff --git a/core/src/avm2/events.rs b/core/src/avm2/events.rs index 0b55c24cd..6a36e6688 100644 --- a/core/src/avm2/events.rs +++ b/core/src/avm2/events.rs @@ -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>, /// 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) }