Skip to content

EventTarget:removeEventListener() does not work #66

@oezingle

Description

@oezingle

Hi all,

Fengari seems like an awesome project. I'm working on integrating a UI library I wrote with it for web support, but I've run into a small issue - it looks like events can't be removed from Elements on-the-fly. I assumed this was a JavaScript limitation, but it appears to work fine in JavaScript in Firefox ("Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0" ) and Chromium ('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36')

Here's a demo HTML file:

<html>

<head>
    <title>Fengari bug demo</title>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/fengari-web.min.js"></script>
</head>

<body>
    <button id="btn-lua">Lua button</button>
    <button id="btn-js">JS button</button>

    <script type="application/lua" async>
        local document = require("js").global.document

        local btn = document:querySelector("#btn-lua")
        local handler
        handler = function ()
            print("Button click lua")

            btn:removeEventListener("click", handler)                
        end
        btn:addEventListener("click", handler)
    </script>

    <script>
        const btn = document.querySelector("#btn-js")

        let handler
        handler = function () {
            console.log("Button click js")

            btn.removeEventListener("click", handler)
        }
        btn.addEventListener("click", handler)
    </script>
</body>

</html>

In the lua script, btn:removeEventListener fails to work, which can be checked by clicking the "Lua button" multiple times. I tried to get around this with setTimeout to no avail.

Removing the event listener right after adding it does not work ether:

btn:addEventListener("click", handler)
btn:removeEventListener("click", handler)                

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions