From f7e3626a7de6da16490491be5069c2d65e69cc4b Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 30 May 2024 20:17:13 +0200 Subject: [PATCH] [spidermonkey] element.addEventListener fixes --- src/ecmascript/spidermonkey/element.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ecmascript/spidermonkey/element.cpp b/src/ecmascript/spidermonkey/element.cpp index b57fa9cc..334afa89 100644 --- a/src/ecmascript/spidermonkey/element.cpp +++ b/src/ecmascript/spidermonkey/element.cpp @@ -3873,7 +3873,18 @@ element_addEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval) } char *method = jsval_to_string(ctx, args[0]); JS::RootedValue fun(ctx, args[1]); + struct ele_listener *l; + foreach(l, el_private->listeners) { + if (strcmp(l->typ, method)) { + continue; + } + if (l->fun == fun) { + mem_free(method); + args.rval().setUndefined(); + return true; + } + } struct ele_listener *n = (struct ele_listener *)mem_calloc(1, sizeof(*n)); if (!n) { @@ -5407,9 +5418,9 @@ element_event_handler(dom_event *event, void *pw) JSObject *obj_ev = getEvent(ctx, event); interpreter->heartbeat = add_heartbeat(interpreter); - struct ele_listener *l; + struct ele_listener *l, *next; - foreach(l, el_private->listeners) { + foreachsafe(l, next, el_private->listeners) { if (strcmp(l->typ, dom_string_data(typ))) { continue; }