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

[ecmascript] Moved list of timeouts to ecmascript_interpreter from document

This commit is contained in:
Witold Filipczyk 2024-06-30 13:55:18 +02:00
parent 348725ee3a
commit 298588ad18
7 changed files with 14 additions and 41 deletions

View File

@ -213,7 +213,6 @@ init_document(struct cache_entry *cached, struct document_options *options)
#ifdef CONFIG_ECMASCRIPT #ifdef CONFIG_ECMASCRIPT
init_list(document->onload_snippets); init_list(document->onload_snippets);
init_list(document->timeouts);
#endif #endif
#ifdef CONFIG_LIBSIXEL #ifdef CONFIG_LIBSIXEL
@ -357,8 +356,6 @@ reset_document(struct document *document)
free_ecmascript_string_list(&document->onload_snippets); free_ecmascript_string_list(&document->onload_snippets);
free_uri_list(&document->ecmascript_imports); free_uri_list(&document->ecmascript_imports);
mem_free_set(&document->body_onkeypress, NULL); mem_free_set(&document->body_onkeypress, NULL);
/// kill_timer(&document->timeout);
/// free_document(document->dom);
#endif #endif
free_list(document->tags); free_list(document->tags);
@ -432,8 +429,6 @@ done_document(struct document *document)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS) #if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
free_ecmascript_string_list(&document->onload_snippets); free_ecmascript_string_list(&document->onload_snippets);
free_uri_list(&document->ecmascript_imports); free_uri_list(&document->ecmascript_imports);
kill_ecmascript_timeouts(document);
free_list(document->timeouts);
mem_free_if(document->body_onkeypress); mem_free_if(document->body_onkeypress);
#endif #endif
@ -474,10 +469,6 @@ release_document(struct document *document)
if (document->refresh) { if (document->refresh) {
kill_document_refresh(document->refresh); kill_document_refresh(document->refresh);
} }
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
// kill_ecmascript_timeouts(document);
// free_list(document->timeouts);
#endif
object_unlock(document); object_unlock(document);
move_document_to_top_of_format_cache(document); move_document_to_top_of_format_cache(document);
} }

View File

@ -231,8 +231,6 @@ struct document {
* dependencies between the various entries so nothing gets removed * dependencies between the various entries so nothing gets removed
* unneeded. */ * unneeded. */
struct uri_list ecmascript_imports; struct uri_list ecmascript_imports;
/** used by setTimeout */
LIST_OF(struct ecmascript_timeout) timeouts;
int ecmascript_counter; int ecmascript_counter;
char *body_onkeypress; char *body_onkeypress;
#endif #endif

View File

@ -309,22 +309,6 @@ check_for_snippets(struct view_state *vs, struct document_options *options, stru
} }
} }
void
kill_ecmascript_timeouts(struct document *document)
{
struct ecmascript_timeout *t;
foreach(t, document->timeouts) {
kill_timer(&t->tid);
done_string(&t->code);
#ifdef CONFIG_QUICKJS
if (!JS_IsNull(t->fun)) {
JS_FreeValue(t->ctx, t->fun);
}
#endif
}
}
void void
ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter) ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
{ {
@ -344,10 +328,10 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
done_string(&interpreter->code); done_string(&interpreter->code);
free_ecmascript_string_list(&interpreter->writecode); free_ecmascript_string_list(&interpreter->writecode);
/* Is it superfluous? */ /* Is it superfluous? */
if (interpreter->vs->doc_view) { if (1) {
struct ecmascript_timeout *t; struct ecmascript_timeout *t;
foreach (t, interpreter->vs->doc_view->document->timeouts) { foreach (t, interpreter->timeouts) {
kill_timer(&t->tid); kill_timer(&t->tid);
done_string(&t->code); done_string(&t->code);
#ifdef CONFIG_QUICKJS #ifdef CONFIG_QUICKJS
@ -356,7 +340,7 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
} }
#endif #endif
} }
free_list(interpreter->vs->doc_view->document->timeouts); free_list(interpreter->timeouts);
} }
interpreter->vs->ecmascript = NULL; interpreter->vs->ecmascript = NULL;
interpreter->vs->ecmascript_fragile = 1; interpreter->vs->ecmascript_fragile = 1;

View File

@ -43,7 +43,6 @@ void toggle_ecmascript(struct session *ses);
* follows a link with this synstax. */ * follows a link with this synstax. */
void ecmascript_protocol_handler(struct session *ses, struct uri *uri); void ecmascript_protocol_handler(struct session *ses, struct uri *uri);
void check_for_snippets(struct view_state *vs, struct document_options *options, struct document *document); void check_for_snippets(struct view_state *vs, struct document_options *options, struct document *document);
void kill_ecmascript_timeouts(struct document *document);
void check_events_for_element(struct ecmascript_interpreter *interpreter, dom_node *element, struct term_event *ev); void check_events_for_element(struct ecmascript_interpreter *interpreter, dom_node *element, struct term_event *ev);
void ecmascript_reset_state(struct view_state *vs); void ecmascript_reset_state(struct view_state *vs);

View File

@ -254,6 +254,7 @@ ecmascript_get_interpreter(struct view_state *vs)
(void)init_string(&interpreter->code); (void)init_string(&interpreter->code);
init_list(interpreter->writecode); init_list(interpreter->writecode);
interpreter->current_writecode = (struct ecmascript_string_list_item *)interpreter->writecode.next; interpreter->current_writecode = (struct ecmascript_string_list_item *)interpreter->writecode.next;
init_list(interpreter->timeouts);
return interpreter; return interpreter;
} }
@ -549,7 +550,7 @@ ecmascript_set_timeout(void *c, char *code, int timeout, int timeout_next)
#ifdef CONFIG_QUICKJS #ifdef CONFIG_QUICKJS
t->fun = JS_NULL; t->fun = JS_NULL;
#endif #endif
add_to_list(interpreter->vs->doc_view->document->timeouts, t); add_to_list(interpreter->timeouts, t);
install_timer(&t->tid, timeout, ecmascript_timeout_handler, t); install_timer(&t->tid, timeout, ecmascript_timeout_handler, t);
return t; return t;
@ -578,7 +579,7 @@ ecmascript_set_timeout2(void *c, JS::HandleValue f, int timeout, int timeout_nex
t->timeout_next = timeout_next; t->timeout_next = timeout_next;
JS::RootedValue fun((JSContext *)interpreter->backend_data, f); JS::RootedValue fun((JSContext *)interpreter->backend_data, f);
t->fun = fun; t->fun = fun;
add_to_list(interpreter->vs->doc_view->document->timeouts, t); add_to_list(interpreter->timeouts, t);
install_timer(&t->tid, timeout, ecmascript_timeout_handler2, t); install_timer(&t->tid, timeout, ecmascript_timeout_handler2, t);
return t; return t;
@ -605,7 +606,7 @@ ecmascript_set_timeout2q(void *c, JSValueConst fun, int timeout, int timeout_nex
t->ctx = ctx; t->ctx = ctx;
t->timeout_next = timeout_next; t->timeout_next = timeout_next;
t->fun = fun; t->fun = fun;
add_to_list(interpreter->vs->doc_view->document->timeouts, t); add_to_list(interpreter->timeouts, t);
install_timer(&t->tid, timeout, ecmascript_timeout_handler2, t); install_timer(&t->tid, timeout, ecmascript_timeout_handler2, t);
return t; return t;
@ -633,7 +634,7 @@ ecmascript_set_timeout2m(js_State *J, const char *handle, int timeout, int timeo
t->fun = handle; t->fun = handle;
t->timeout_next = timeout_next; t->timeout_next = timeout_next;
add_to_list(interpreter->vs->doc_view->document->timeouts, t); add_to_list(interpreter->timeouts, t);
install_timer(&t->tid, timeout, ecmascript_timeout_handler2, t); install_timer(&t->tid, timeout, ecmascript_timeout_handler2, t);
return t; return t;

View File

@ -40,6 +40,7 @@ extern "C" {
struct document; struct document;
struct document_view; struct document_view;
struct ecmascript_timeout;
struct form_state; struct form_state;
struct form_view; struct form_view;
struct string; struct string;
@ -87,6 +88,9 @@ struct ecmascript_interpreter {
* is reloaded in another tab and then you just cause the current tab * is reloaded in another tab and then you just cause the current tab
* to redraw. */ * to redraw. */
unsigned int onload_snippets_cache_id; unsigned int onload_snippets_cache_id;
/** used by setTimeout */
LIST_OF(struct ecmascript_timeout) timeouts;
#ifdef CONFIG_ECMASCRIPT_SMJS #ifdef CONFIG_ECMASCRIPT_SMJS
JSAutoRealm *ar; JSAutoRealm *ar;
JS::Heap<JSObject*> *ac; JS::Heap<JSObject*> *ac;
@ -133,7 +137,6 @@ struct ecmascript_timeout {
int timeout_next; int timeout_next;
}; };
struct delayed_goto { struct delayed_goto {
/* It might look more convenient to pass doc_view around but it could /* It might look more convenient to pass doc_view around but it could
* disappear during wild dances inside of frames or so. */ * disappear during wild dances inside of frames or so. */

View File

@ -98,13 +98,10 @@ js_window_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
JS_MarkValue(rt, elwin->thisval, mark_func); JS_MarkValue(rt, elwin->thisval, mark_func);
JS_MarkValue(rt, elwin->onmessage, mark_func); JS_MarkValue(rt, elwin->onmessage, mark_func);
if (elwin->interpreter->vs && elwin->interpreter->vs->doc_view) { if (elwin->interpreter) {
struct document *doc = elwin->interpreter->vs->doc_view->document;
struct ecmascript_timeout *et; struct ecmascript_timeout *et;
foreach (et, doc->timeouts) { foreach (et, elwin->interpreter->timeouts) {
JS_MarkValue(rt, et->fun, mark_func); JS_MarkValue(rt, et->fun, mark_func);
} }
} }