mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
[quickjs] Check whether interpreter is existing in document event handler
This commit is contained in:
parent
791b0ca9e6
commit
2f4829947b
@ -73,6 +73,7 @@
|
|||||||
|
|
||||||
static JSRuntime *quickjs_runtime;
|
static JSRuntime *quickjs_runtime;
|
||||||
|
|
||||||
|
void *map_interp;
|
||||||
/*** Global methods */
|
/*** Global methods */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -181,6 +182,7 @@ quickjs_init(struct module *module)
|
|||||||
#else
|
#else
|
||||||
quickjs_runtime = JS_NewRuntime();
|
quickjs_runtime = JS_NewRuntime();
|
||||||
#endif
|
#endif
|
||||||
|
map_interp = interp_new_map();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -212,6 +214,7 @@ quickjs_done(struct module *xxx)
|
|||||||
|
|
||||||
attr_delete_map(map_csses);
|
attr_delete_map(map_csses);
|
||||||
attr_delete_map_rev(map_rev_csses);
|
attr_delete_map_rev(map_rev_csses);
|
||||||
|
interp_delete_map(map_interp);
|
||||||
|
|
||||||
if (quickjs_runtime) {
|
if (quickjs_runtime) {
|
||||||
JS_FreeRuntime(quickjs_runtime);
|
JS_FreeRuntime(quickjs_runtime);
|
||||||
@ -333,6 +336,7 @@ quickjs_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
interp_save_in_map(map_interp, interpreter);
|
||||||
|
|
||||||
interpreter->backend_data = ctx;
|
interpreter->backend_data = ctx;
|
||||||
JS_SetContextOpaque(ctx, interpreter);
|
JS_SetContextOpaque(ctx, interpreter);
|
||||||
@ -392,6 +396,7 @@ fprintf(stderr, "Before JS_FreeContext: %s:%d\n", __FUNCTION__, __LINE__);
|
|||||||
#endif
|
#endif
|
||||||
JS_FreeContext(ctx);
|
JS_FreeContext(ctx);
|
||||||
interpreter->backend_data = NULL;
|
interpreter->backend_data = NULL;
|
||||||
|
interp_erase_from_map(map_interp, interpreter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -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);
|
void quickjs_call_function(struct ecmascript_interpreter *interpreter, JSValueConst fun, struct string *ret);
|
||||||
|
|
||||||
|
extern void *interps;
|
||||||
extern struct module quickjs_module;
|
extern struct module quickjs_module;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -2082,6 +2082,10 @@ document_event_handler(dom_event *event, void *pw)
|
|||||||
#endif
|
#endif
|
||||||
struct js_document_private *doc_private = (struct js_document_private *)pw;
|
struct js_document_private *doc_private = (struct js_document_private *)pw;
|
||||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)doc_private->interpreter;
|
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;
|
JSContext *ctx = (JSContext *)interpreter->backend_data;
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
|
@ -156,6 +156,84 @@ attr_create_new_csses_map_rev(void)
|
|||||||
return (void *)init_hash8();
|
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
|
#if 0
|
||||||
struct classcomp {
|
struct classcomp {
|
||||||
|
@ -30,9 +30,17 @@ extern void *map_form_elements_rev;
|
|||||||
extern void *map_csses;
|
extern void *map_csses;
|
||||||
extern void *map_rev_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 *m, void *node, JSValueConst value);
|
||||||
void attr_save_in_map_void(void *m, void *node, void *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_attrs_map(void);
|
||||||
void *attr_create_new_attributes_map(void);
|
void *attr_create_new_attributes_map(void);
|
||||||
void *attr_create_new_attributes_map_rev(void);
|
void *attr_create_new_attributes_map_rev(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user