From b90277d15d09f6714cb54e527fa706a3d68561d8 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Mon, 24 Nov 2025 04:57:34 -0800 Subject: [PATCH 1/3] added test for #25846 --- test/test_html5_remove_event_listener.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test_html5_remove_event_listener.c b/test/test_html5_remove_event_listener.c index 394e7afe31ee7..57d1483a98b83 100644 --- a/test/test_html5_remove_event_listener.c +++ b/test/test_html5_remove_event_listener.c @@ -45,6 +45,11 @@ bool mouse_callback_1(int eventType, const EmscriptenMouseEvent *e, void *userDa return 0; } +bool screen_callback(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData) { + printf("screen_callback: eventType=%d, userData=%s\n", eventType, (char const *) userData); + return 0; +} + void checkCount(int count) { int eventHandlersCount = EM_ASM_INT({ return JSEvents.eventHandlers.length; }); printf("Detected [%d] handlers\n", eventHandlersCount); @@ -130,5 +135,17 @@ int main() { checkCount(2); + // internally, emscripten_set_fullscreenchange_callback sets 2 event handlers ("webkitfullscreenchange" and "fullscreenchange") + ret = emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, useCapture, screen_callback); + ASSERT_RESULT(emscripten_set_fullscreenchange_callback); + + checkCount(4); + + // we make sure that the 2 event handlers get removed (#25846) + ret = emscripten_html5_remove_event_listener(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, EMSCRIPTEN_EVENT_FULLSCREENCHANGE, screen_callback); + ASSERT_RESULT(emscripten_html5_remove_event_listener); + + checkCount(2); + return 0; } From 006a5224cbfbdb5ede3a405de654974765c83115 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Mon, 24 Nov 2025 07:03:26 -0800 Subject: [PATCH 2/3] Making sure MIN_SAFARI_VERSION is defined --- test/test_browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_browser.py b/test/test_browser.py index e4e1191770d4c..a9a7c33697f65 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -2545,7 +2545,7 @@ def test_html5_core(self, opts): self.btest_exit('test_html5_core.c', cflags=opts) def test_html5_remove_event_listener(self): - self.btest_exit('test_html5_remove_event_listener.c') + self.btest_exit('test_html5_remove_event_listener.c', cflags=['-sMIN_SAFARI_VERSION=150000']) @parameterized({ '': ([],), From fa0989338fa34f97845dadf58148cab37e1ac3c1 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Tue, 25 Nov 2025 05:05:39 -0800 Subject: [PATCH 3/3] fix test to work when no safari support --- test/test_browser.py | 2 +- test/test_html5_remove_event_listener.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/test_browser.py b/test/test_browser.py index a9a7c33697f65..9ece9a00a2d76 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -2545,7 +2545,7 @@ def test_html5_core(self, opts): self.btest_exit('test_html5_core.c', cflags=opts) def test_html5_remove_event_listener(self): - self.btest_exit('test_html5_remove_event_listener.c', cflags=['-sMIN_SAFARI_VERSION=150000']) + self.btest_exit('test_html5_remove_event_listener.c', cflags=[f'-DSAFARI_SUPPORT={int(not self.is_wasm64())}']) @parameterized({ '': ([],), diff --git a/test/test_html5_remove_event_listener.c b/test/test_html5_remove_event_listener.c index 57d1483a98b83..0fde8527e762e 100644 --- a/test/test_html5_remove_event_listener.c +++ b/test/test_html5_remove_event_listener.c @@ -135,11 +135,16 @@ int main() { checkCount(2); - // internally, emscripten_set_fullscreenchange_callback sets 2 event handlers ("webkitfullscreenchange" and "fullscreenchange") + // internally, emscripten_set_fullscreenchange_callback can set 2 event handlers ("webkitfullscreenchange" and "fullscreenchange") ret = emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, useCapture, screen_callback); ASSERT_RESULT(emscripten_set_fullscreenchange_callback); +#if SAFARI_SUPPORT == 1 + // 2 events handlers are set when there is safari support checkCount(4); +#else + checkCount(3); +#endif // we make sure that the 2 event handlers get removed (#25846) ret = emscripten_html5_remove_event_listener(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, EMSCRIPTEN_EVENT_FULLSCREENCHANGE, screen_callback);