diff --git a/src/document/document.c b/src/document/document.c index 592aadb59..e44bf1508 100644 --- a/src/document/document.c +++ b/src/document/document.c @@ -213,7 +213,6 @@ init_document(struct cache_entry *cached, struct document_options *options) #ifdef CONFIG_ECMASCRIPT init_list(document->onload_snippets); - init_list(document->timeouts); #endif #ifdef CONFIG_LIBSIXEL @@ -357,8 +356,6 @@ reset_document(struct document *document) free_ecmascript_string_list(&document->onload_snippets); free_uri_list(&document->ecmascript_imports); mem_free_set(&document->body_onkeypress, NULL); -/// kill_timer(&document->timeout); -/// free_document(document->dom); #endif free_list(document->tags); @@ -432,8 +429,6 @@ done_document(struct document *document) #if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS) free_ecmascript_string_list(&document->onload_snippets); free_uri_list(&document->ecmascript_imports); - kill_ecmascript_timeouts(document); - free_list(document->timeouts); mem_free_if(document->body_onkeypress); #endif @@ -474,10 +469,6 @@ release_document(struct document *document) if (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); move_document_to_top_of_format_cache(document); } diff --git a/src/document/document.h b/src/document/document.h index 1d1732c47..4ffeac050 100644 --- a/src/document/document.h +++ b/src/document/document.h @@ -231,8 +231,6 @@ struct document { * dependencies between the various entries so nothing gets removed * unneeded. */ struct uri_list ecmascript_imports; - /** used by setTimeout */ - LIST_OF(struct ecmascript_timeout) timeouts; int ecmascript_counter; char *body_onkeypress; #endif diff --git a/src/ecmascript/ecmascript-c.c b/src/ecmascript/ecmascript-c.c index 06e42447b..f66ec878d 100644 --- a/src/ecmascript/ecmascript-c.c +++ b/src/ecmascript/ecmascript-c.c @@ -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 ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter) { @@ -344,10 +328,10 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter) done_string(&interpreter->code); free_ecmascript_string_list(&interpreter->writecode); /* Is it superfluous? */ - if (interpreter->vs->doc_view) { + if (1) { struct ecmascript_timeout *t; - foreach (t, interpreter->vs->doc_view->document->timeouts) { + foreach (t, interpreter->timeouts) { kill_timer(&t->tid); done_string(&t->code); #ifdef CONFIG_QUICKJS @@ -356,7 +340,7 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter) } #endif } - free_list(interpreter->vs->doc_view->document->timeouts); + free_list(interpreter->timeouts); } interpreter->vs->ecmascript = NULL; interpreter->vs->ecmascript_fragile = 1; diff --git a/src/ecmascript/ecmascript-c.h b/src/ecmascript/ecmascript-c.h index 4c7df50a5..4b9e6b5b3 100644 --- a/src/ecmascript/ecmascript-c.h +++ b/src/ecmascript/ecmascript-c.h @@ -43,7 +43,6 @@ void toggle_ecmascript(struct session *ses); * follows a link with this synstax. */ 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 kill_ecmascript_timeouts(struct document *document); void check_events_for_element(struct ecmascript_interpreter *interpreter, dom_node *element, struct term_event *ev); void ecmascript_reset_state(struct view_state *vs); diff --git a/src/ecmascript/ecmascript.c b/src/ecmascript/ecmascript.c index 0a375f2a9..1876ef588 100644 --- a/src/ecmascript/ecmascript.c +++ b/src/ecmascript/ecmascript.c @@ -254,6 +254,7 @@ ecmascript_get_interpreter(struct view_state *vs) (void)init_string(&interpreter->code); init_list(interpreter->writecode); interpreter->current_writecode = (struct ecmascript_string_list_item *)interpreter->writecode.next; + init_list(interpreter->timeouts); return interpreter; } @@ -549,7 +550,7 @@ ecmascript_set_timeout(void *c, char *code, int timeout, int timeout_next) #ifdef CONFIG_QUICKJS t->fun = JS_NULL; #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); return t; @@ -578,7 +579,7 @@ ecmascript_set_timeout2(void *c, JS::HandleValue f, int timeout, int timeout_nex t->timeout_next = timeout_next; JS::RootedValue fun((JSContext *)interpreter->backend_data, f); 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); return t; @@ -605,7 +606,7 @@ ecmascript_set_timeout2q(void *c, JSValueConst fun, int timeout, int timeout_nex t->ctx = ctx; t->timeout_next = timeout_next; 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); return t; @@ -633,7 +634,7 @@ ecmascript_set_timeout2m(js_State *J, const char *handle, int timeout, int timeo t->fun = handle; 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); return t; diff --git a/src/ecmascript/ecmascript.h b/src/ecmascript/ecmascript.h index 093960da2..de4b93a9a 100644 --- a/src/ecmascript/ecmascript.h +++ b/src/ecmascript/ecmascript.h @@ -40,6 +40,7 @@ extern "C" { struct document; struct document_view; +struct ecmascript_timeout; struct form_state; struct form_view; struct string; @@ -87,6 +88,9 @@ struct ecmascript_interpreter { * is reloaded in another tab and then you just cause the current tab * to redraw. */ unsigned int onload_snippets_cache_id; + + /** used by setTimeout */ + LIST_OF(struct ecmascript_timeout) timeouts; #ifdef CONFIG_ECMASCRIPT_SMJS JSAutoRealm *ar; JS::Heap *ac; @@ -133,7 +137,6 @@ struct ecmascript_timeout { int timeout_next; }; - struct delayed_goto { /* It might look more convenient to pass doc_view around but it could * disappear during wild dances inside of frames or so. */ diff --git a/src/ecmascript/quickjs/window.c b/src/ecmascript/quickjs/window.c index 577a754b5..41e208dd3 100644 --- a/src/ecmascript/quickjs/window.c +++ b/src/ecmascript/quickjs/window.c @@ -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->onmessage, mark_func); - if (elwin->interpreter->vs && elwin->interpreter->vs->doc_view) { - struct document *doc = elwin->interpreter->vs->doc_view->document; - + if (elwin->interpreter) { struct ecmascript_timeout *et; - foreach (et, doc->timeouts) { - + foreach (et, elwin->interpreter->timeouts) { JS_MarkValue(rt, et->fun, mark_func); } }