diff --git a/src/lib/libhtml5.js b/src/lib/libhtml5.js
index 7bdfd4d42c1c2..132335855ec9e 100644
--- a/src/lib/libhtml5.js
+++ b/src/lib/libhtml5.js
@@ -202,16 +202,19 @@ var LibraryHTML5 = {
},
removeSingleHandler(eventHandler) {
- for (var [i, handler] of JSEvents.eventHandlers.entries()) {
+ let success = false;
+ for (let i = 0; i < JSEvents.eventHandlers.length; ++i) {
+ const handler = JSEvents.eventHandlers[i];
if (handler.target === eventHandler.target
&& handler.eventTypeId === eventHandler.eventTypeId
&& handler.callbackfunc === eventHandler.callbackfunc
&& handler.userData === eventHandler.userData) {
- JSEvents._removeHandler(i);
- return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
+ // in some very rare cases (ex: Safari / fullscreen events), there is more than 1 handler (eventTypeString is different)
+ JSEvents._removeHandler(i--);
+ success = true;
}
}
- return {{{ cDefs.EMSCRIPTEN_RESULT_INVALID_PARAM }}};
+ return success ? {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}} : {{{ cDefs.EMSCRIPTEN_RESULT_INVALID_PARAM }}};
},
#if PTHREADS
diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json
index 139779b4e2dfc..c7d6d21042b53 100644
--- a/test/codesize/test_codesize_hello_dylink_all.json
+++ b/test/codesize/test_codesize_hello_dylink_all.json
@@ -1,7 +1,7 @@
{
- "a.out.js": 245720,
+ "a.out.js": 245732,
"a.out.nodebug.wasm": 574007,
- "total": 819727,
+ "total": 819739,
"sent": [
"IMG_Init",
"IMG_Load",