Skip to content

Commit 2383e68

Browse files
Aaron1011relrelb
authored andcommitted
avm2: Continue to process event when a handler produces an error
An exception thrown by one event handler shoud not prevent other event handlers from running on this same event. Some SWFs like Wonderputt depend on this behavior, as they have buggy event handlers that throw errors.
1 parent ad19c29 commit 2383e68

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

core/src/avm2/events.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,14 @@ pub fn dispatch_event_to_target<'gc>(
417417

418418
let object = activation.global_scope();
419419

420-
handler.call(object, &[event.into()], activation)?;
420+
if let Err(err) = handler.call(object, &[event.into()], activation) {
421+
log::error!(
422+
"Error dispatching event {:?} to handler {:?} : {:?}",
423+
event,
424+
handler,
425+
err
426+
);
427+
}
421428
}
422429

423430
Ok(())

tests/tests/regression_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ swf_tests! {
260260
(as3_event_cancelable, "avm2/event_cancelable", 1),
261261
(as3_event_clone, "avm2/event_clone", 1),
262262
(as3_event_formattostring, "avm2/event_formattostring", 1),
263+
(as3_event_handler_exception, "avm2/event_handler_exception", 2),
263264
(as3_event_isdefaultprevented, "avm2/event_isdefaultprevented", 1),
264265
(as3_event_type, "avm2/event_type", 1),
265266
(as3_event_valueof_tostring, "avm2/event_valueof_tostring", 1),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package {
2+
import flash.events.Event;
3+
import flash.display.Sprite;
4+
import flash.display.Stage;
5+
6+
public class Test {
7+
public function Test(stage: Stage) {
8+
stage.addEventListener(Event.ENTER_FRAME, function() {
9+
trace("First listener!");
10+
throw new Error("Exception in first listener");
11+
});
12+
13+
stage.addEventListener(Event.ENTER_FRAME, function() {
14+
trace("Second listener!");
15+
16+
var sprite = new Sprite();
17+
sprite.addEventListener("customEvent", function() {
18+
trace("First custom event listener!");
19+
throw new Error("Exception in custom event handler");
20+
});
21+
22+
sprite.addEventListener("customEvent", function() {
23+
trace("Second custom event listener!");
24+
});
25+
26+
sprite.dispatchEvent(new Event("customEvent"));
27+
});
28+
}
29+
}
30+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
First listener!
2+
Second listener!
3+
First custom event listener!
4+
Second custom event listener!
3.81 KB
Binary file not shown.
919 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)