Skip to content

Event handlers never consume events in Asyncify #13320

Open
@devappd

Description

@devappd

Per html5.h, event handlers can return TRUE to consume the event, i.e., event.preventDefault() is called. This does not work in Asyncify.

Here's a simple test case for mouse events:

The expected result is that the default handler is never invoked on the canvas, e.g., mouse clicks do not cause the canvas to gain focus.

I saw that the event handlers check the result of dynCall_iiii() to determine whether to call e.preventDefault(). This result is never passed in Asyncify.

Therefore, I get the desired result if I modify the compiled Module as below:

function registerMouseEventCallback(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) {
  /* ... */
  
  var mouseEventHandlerFunc = function(ev) {
    var e = ev || event;

    // TODO: Make this access thread safe, or this could update live while app is reading it.
    fillMouseEventData(JSEvents.mouseEvent, e, target);

-    if ((function(a1, a2, a3) { dynCall_iiii.apply(null, [callbackfunc, a1, a2, a3]); })(eventTypeId, JSEvents.mouseEvent, userData)) e.preventDefault();
+    if ((function(a1, a2, a3) { return dynCall_iiii.apply(null, [callbackfunc, a1, a2, a3]); })(eventTypeId, JSEvents.mouseEvent, userData)) e.preventDefault();
  };

  /* ... */
}

See Asyncify build with the fix applied, which passes the test.

Is this fix appropriate? If so, I can use guidance on patching the codebase as I'm unfamiliar with Asyncify modifications.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions