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

[quickjs] Check whether interpreter is existing in document event handler

This commit is contained in:
Witold Filipczyk 2024-10-10 17:15:27 +02:00
parent 791b0ca9e6
commit 2f4829947b
5 changed files with 96 additions and 0 deletions

View File

@ -73,6 +73,7 @@
static JSRuntime *quickjs_runtime;
void *map_interp;
/*** Global methods */
static void
@ -181,6 +182,7 @@ quickjs_init(struct module *module)
#else
quickjs_runtime = JS_NewRuntime();
#endif
map_interp = interp_new_map();
}
static void
@ -212,6 +214,7 @@ quickjs_done(struct module *xxx)
attr_delete_map(map_csses);
attr_delete_map_rev(map_rev_csses);
interp_delete_map(map_interp);
if (quickjs_runtime) {
JS_FreeRuntime(quickjs_runtime);
@ -333,6 +336,7 @@ quickjs_get_interpreter(struct ecmascript_interpreter *interpreter)
if (!ctx) {
return NULL;
}
interp_save_in_map(map_interp, interpreter);
interpreter->backend_data = ctx;
JS_SetContextOpaque(ctx, interpreter);
@ -392,6 +396,7 @@ fprintf(stderr, "Before JS_FreeContext: %s:%d\n", __FUNCTION__, __LINE__);
#endif
JS_FreeContext(ctx);
interpreter->backend_data = NULL;
interp_erase_from_map(map_interp, interpreter);
}
static void

View File

@ -56,6 +56,7 @@ int quickjs_eval_boolback(struct ecmascript_interpreter *interpreter, struct str
void quickjs_call_function(struct ecmascript_interpreter *interpreter, JSValueConst fun, struct string *ret);
extern void *interps;
extern struct module quickjs_module;
#ifdef __cplusplus

View File

@ -2082,6 +2082,10 @@ document_event_handler(dom_event *event, void *pw)
#endif
struct js_document_private *doc_private = (struct js_document_private *)pw;
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)doc_private->interpreter;
if (!interp_find_in_map(map_interp, interpreter)) {
return;
}
JSContext *ctx = (JSContext *)interpreter->backend_data;
if (!event) {

View File

@ -156,6 +156,84 @@ attr_create_new_csses_map_rev(void)
return (void *)init_hash8();
}
void *
interp_new_map(void)
{
return (void *)init_hash8();
}
bool
interp_find_in_map(void *m, void *interpreter)
{
struct hash *hash = (struct hash *)m;
if (hash) {
char *key = memacpy((const char *)&interpreter, sizeof(interpreter));
if (key) {
struct hash_item *item = get_hash_item(hash, key, sizeof(interpreter));
mem_free(key);
if (item) {
return true;
}
}
}
return false;
}
void
interp_save_in_map(void *m, void *interpreter)
{
struct hash *hash = (struct hash *)m;
void *value = (void *)1;
char *key = memacpy((const char *)&interpreter, sizeof(interpreter));
if (key) {
add_hash_item(hash, key, sizeof(value), value);
}
}
void
interp_erase_from_map(void *m, void *interpreter)
{
struct hash *hash = (struct hash *)m;
if (hash) {
char *key = memacpy((const char *)&interpreter, sizeof(interpreter));
if (key) {
struct hash_item *item = get_hash_item(hash, key, sizeof(interpreter));
if (item) {
mem_free_set(&item->key, NULL);
//mem_free_set(&item->value, NULL);
del_hash_item(hash, item);
}
mem_free(key);
}
}
}
void
interp_delete_map(void *m)
{
struct hash *hash = (struct hash *)m;
if (hash) {
struct hash_item *item;
int i;
foreach_hash_item (item, *hash, i) {
mem_free_set(&item->key, NULL);
//mem_free_set(&item->value, NULL);
}
free_hash(&hash);
}
}
#if 0
struct classcomp {

View File

@ -30,9 +30,17 @@ extern void *map_form_elements_rev;
extern void *map_csses;
extern void *map_rev_csses;
extern void *map_interp;
void attr_save_in_map(void *m, void *node, JSValueConst value);
void attr_save_in_map_void(void *m, void *node, void *value);
void *interp_new_map(void);
bool interp_find_in_map(void *m, void *interpreter);
void interp_save_in_map(void *m, void *interpreter);
void interp_erase_from_map(void *m, void *interpreter);
void interp_delete_map(void *m);
void *attr_create_new_attrs_map(void);
void *attr_create_new_attributes_map(void);
void *attr_create_new_attributes_map_rev(void);