From 5b6b488e4afa07020c46e360af38fa95cb73ee50 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 10 Oct 2024 16:24:07 +0200 Subject: [PATCH] [spidermonkey] check for deleted interpreters in document event handler --- src/js/spidermonkey.cpp | 5 +++++ src/js/spidermonkey.h | 4 ++++ src/js/spidermonkey/document.cpp | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/src/js/spidermonkey.cpp b/src/js/spidermonkey.cpp index 81e26c165..7df989687 100644 --- a/src/js/spidermonkey.cpp +++ b/src/js/spidermonkey.cpp @@ -84,6 +84,8 @@ static int js_module_init_ok; +std::map interps; + static void error_reporter(JSContext *ctx, JSErrorReport *report) { @@ -267,6 +269,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter) if (!ctx) { return nullptr; } + interps[(void *)interpreter] = true; interpreter->backend_data = ctx; struct view_state *vs = interpreter->vs; @@ -528,6 +531,8 @@ spidermonkey_put_interpreter(struct ecmascript_interpreter *interpreter) interpreter->ac = nullptr; interpreter->ar = nullptr; done_heartbeat(interpreter->heartbeat); + + interps.erase((void *)interpreter); } void diff --git a/src/js/spidermonkey.h b/src/js/spidermonkey.h index c2c7b121e..aa74f4fe7 100644 --- a/src/js/spidermonkey.h +++ b/src/js/spidermonkey.h @@ -2,6 +2,7 @@ #define EL__JS_SPIDERMONKEY_H #include +#include struct ecmascript_interpreter; struct form_view; @@ -22,4 +23,7 @@ int spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter, struc void spidermonkey_call_function(struct ecmascript_interpreter *interpreter, JS::HandleValue fun, struct string *ret); extern struct module spidermonkey_module; + +extern std::map interps; + #endif diff --git a/src/js/spidermonkey/document.cpp b/src/js/spidermonkey/document.cpp index 194c63592..35b00aae7 100644 --- a/src/js/spidermonkey/document.cpp +++ b/src/js/spidermonkey/document.cpp @@ -31,6 +31,7 @@ #include "js/ecmascript.h" #include "js/ecmascript-c.h" #include "js/libdom/parse.h" +#include "js/spidermonkey.h" #include "js/spidermonkey/collection.h" #include "js/spidermonkey/form.h" #include "js/spidermonkey/forms.h" @@ -1742,6 +1743,11 @@ document_event_handler(dom_event *event, void *pw) #endif struct document_private *doc_private = (struct document_private *)pw; struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)doc_private->interpreter; + + if (interps.find((void *)interpreter) == interps.end()) { + return; + } + JSContext *ctx = (JSContext *)interpreter->backend_data; JSAutoRealm ar(ctx, (JSObject *)interpreter->ac->get()); JS::RootedValue r_val(ctx);