Skip to content

Commit a58305a

Browse files
authored
Fixes emscripten_html5_remove_event_listener when multiple listeners (#25847)
Fixes: #25846
1 parent fb4a23b commit a58305a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/lib/libhtml5.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,19 @@ var LibraryHTML5 = {
202202
},
203203

204204
removeSingleHandler(eventHandler) {
205-
for (var [i, handler] of JSEvents.eventHandlers.entries()) {
205+
let success = false;
206+
for (let i = 0; i < JSEvents.eventHandlers.length; ++i) {
207+
const handler = JSEvents.eventHandlers[i];
206208
if (handler.target === eventHandler.target
207209
&& handler.eventTypeId === eventHandler.eventTypeId
208210
&& handler.callbackfunc === eventHandler.callbackfunc
209211
&& handler.userData === eventHandler.userData) {
210-
JSEvents._removeHandler(i);
211-
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
212+
// in some very rare cases (ex: Safari / fullscreen events), there is more than 1 handler (eventTypeString is different)
213+
JSEvents._removeHandler(i--);
214+
success = true;
212215
}
213216
}
214-
return {{{ cDefs.EMSCRIPTEN_RESULT_INVALID_PARAM }}};
217+
return success ? {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}} : {{{ cDefs.EMSCRIPTEN_RESULT_INVALID_PARAM }}};
215218
},
216219

217220
#if PTHREADS

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 245720,
2+
"a.out.js": 245732,
33
"a.out.nodebug.wasm": 574007,
4-
"total": 819727,
4+
"total": 819739,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

0 commit comments

Comments
 (0)