1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[spidermonkey] check for deleted interpreters in document event handler

This commit is contained in:
Witold Filipczyk 2024-10-10 16:24:07 +02:00
parent bb2124bef6
commit 5b6b488e4a
3 changed files with 15 additions and 0 deletions

View File

@ -84,6 +84,8 @@
static int js_module_init_ok; static int js_module_init_ok;
std::map<void *, bool> interps;
static void static void
error_reporter(JSContext *ctx, JSErrorReport *report) error_reporter(JSContext *ctx, JSErrorReport *report)
{ {
@ -267,6 +269,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
if (!ctx) { if (!ctx) {
return nullptr; return nullptr;
} }
interps[(void *)interpreter] = true;
interpreter->backend_data = ctx; interpreter->backend_data = ctx;
struct view_state *vs = interpreter->vs; struct view_state *vs = interpreter->vs;
@ -528,6 +531,8 @@ spidermonkey_put_interpreter(struct ecmascript_interpreter *interpreter)
interpreter->ac = nullptr; interpreter->ac = nullptr;
interpreter->ar = nullptr; interpreter->ar = nullptr;
done_heartbeat(interpreter->heartbeat); done_heartbeat(interpreter->heartbeat);
interps.erase((void *)interpreter);
} }
void void

View File

@ -2,6 +2,7 @@
#define EL__JS_SPIDERMONKEY_H #define EL__JS_SPIDERMONKEY_H
#include <jsapi.h> #include <jsapi.h>
#include <map>
struct ecmascript_interpreter; struct ecmascript_interpreter;
struct form_view; 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); void spidermonkey_call_function(struct ecmascript_interpreter *interpreter, JS::HandleValue fun, struct string *ret);
extern struct module spidermonkey_module; extern struct module spidermonkey_module;
extern std::map<void *, bool> interps;
#endif #endif

View File

@ -31,6 +31,7 @@
#include "js/ecmascript.h" #include "js/ecmascript.h"
#include "js/ecmascript-c.h" #include "js/ecmascript-c.h"
#include "js/libdom/parse.h" #include "js/libdom/parse.h"
#include "js/spidermonkey.h"
#include "js/spidermonkey/collection.h" #include "js/spidermonkey/collection.h"
#include "js/spidermonkey/form.h" #include "js/spidermonkey/form.h"
#include "js/spidermonkey/forms.h" #include "js/spidermonkey/forms.h"
@ -1742,6 +1743,11 @@ document_event_handler(dom_event *event, void *pw)
#endif #endif
struct document_private *doc_private = (struct document_private *)pw; struct document_private *doc_private = (struct document_private *)pw;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)doc_private->interpreter; struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)doc_private->interpreter;
if (interps.find((void *)interpreter) == interps.end()) {
return;
}
JSContext *ctx = (JSContext *)interpreter->backend_data; JSContext *ctx = (JSContext *)interpreter->backend_data;
JSAutoRealm ar(ctx, (JSObject *)interpreter->ac->get()); JSAutoRealm ar(ctx, (JSObject *)interpreter->ac->get());
JS::RootedValue r_val(ctx); JS::RootedValue r_val(ctx);