diff --git a/src/document/document.c b/src/document/document.c index e585239a..372eee07 100644 --- a/src/document/document.c +++ b/src/document/document.c @@ -55,6 +55,7 @@ init_document(struct cache_entry *cached, struct document_options *options) #ifdef CONFIG_ECMASCRIPT init_list(document->onload_snippets); + init_list(document->timeouts); #endif object_nolock(document, "document"); @@ -105,6 +106,20 @@ done_link_members(struct link *link) mem_free_if(link->points); } +#ifdef CONFIG_ECMASCRIPT +void +kill_timeouts(struct document *document) +{ + struct timeout_data *td; + + foreach (td, document->timeouts) { + kill_timer(&td->timer); + mem_free(td->code); + } + free_list(document->timeouts); +} +#endif + void done_document(struct document *document) { @@ -154,6 +169,7 @@ done_document(struct document *document) #ifdef CONFIG_ECMASCRIPT free_string_list(&document->onload_snippets); free_uri_list(&document->ecmascript_imports); + kill_timeouts(document); #endif free_list(document->tags); @@ -174,6 +190,9 @@ release_document(struct document *document) if_assert_failed return; if (document->refresh) kill_document_refresh(document->refresh); +#ifdef CONFIG_ECMASCRIPT + kill_timeouts(document); +#endif object_unlock(document); move_to_top_of_list(format_cache, document); } diff --git a/src/document/document.h b/src/document/document.h index 11ccaa37..43b350fb 100644 --- a/src/document/document.h +++ b/src/document/document.h @@ -144,6 +144,15 @@ struct search { }; #endif +#ifdef CONFIG_ECMASCRIPT +struct timeout_data { + LIST_HEAD(struct timeout_data); + struct ecmascript_interpreter *interpreter; + unsigned char *code; + timer_id_T timer; +}; +#endif + struct document { OBJECT_HEAD(struct document); @@ -165,6 +174,8 @@ struct document { * dependencies between the various entries so nothing gets removed * unneeded. */ struct uri_list ecmascript_imports; + /** used by setTimeout */ + LIST_OF(struct timeout_data) timeouts; #endif #ifdef CONFIG_CSS /** @todo FIXME: We should externally maybe using cache_entry store the @@ -246,6 +257,11 @@ int get_format_cache_refresh_count(void); void shrink_format_cache(int); +#ifdef CONFIG_ECMASCRIPT +void kill_timeouts(struct document *document); +#endif + + extern struct module document_module; /** @todo FIXME: support for entities and all Unicode characters. diff --git a/src/ecmascript/ecmascript.c b/src/ecmascript/ecmascript.c index b7f05e76..2994a13f 100644 --- a/src/ecmascript/ecmascript.c +++ b/src/ecmascript/ecmascript.c @@ -127,7 +127,6 @@ ecmascript_get_interpreter(struct view_state *vs) interpreter->vs = vs; interpreter->vs->ecmascript_fragile = 0; init_list(interpreter->onload_snippets); - init_list(interpreter->timeouts); #ifdef CONFIG_ECMASCRIPT_SEE see_get_interpreter(interpreter); #else @@ -136,19 +135,6 @@ ecmascript_get_interpreter(struct view_state *vs) return interpreter; } -static void -kill_timeouts(struct ecmascript_interpreter *interpreter) -{ - struct timeout_data *td; - - foreach (td, interpreter->timeouts) { - kill_timer(&td->timer); - mem_free(td->code); - } - free_list(interpreter->timeouts); -} - - void ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter) { @@ -164,7 +150,9 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter) spidermonkey_put_interpreter(interpreter); #endif free_string_list(&interpreter->onload_snippets); - kill_timeouts(interpreter); + /* Is it superfluous? */ + if (interpreter->vs->doc_view) + kill_timeouts(interpreter->vs->doc_view->document); interpreter->vs->ecmascript = NULL; interpreter->vs->ecmascript_fragile = 1; mem_free(interpreter); @@ -369,7 +357,7 @@ struct timeout_data * ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, unsigned char *code, int timeout) { struct timeout_data *td; - assert(interpreter); + assert(interpreter && interpreter->vs->doc_view->document); if (!code) return NULL; td = mem_calloc(1, sizeof(*td)); @@ -381,7 +369,7 @@ ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, unsigned char td->code = code; install_timer(&td->timer, timeout, ecmascript_timeout_handler, td); if (td->timer != TIMER_ID_UNDEF) { - add_to_list_end(interpreter->timeouts, td); + add_to_list_end(interpreter->vs->doc_view->document->timeouts, td); return td; } mem_free(code); diff --git a/src/ecmascript/ecmascript.h b/src/ecmascript/ecmascript.h index f15088d7..69e6e2ed 100644 --- a/src/ecmascript/ecmascript.h +++ b/src/ecmascript/ecmascript.h @@ -11,22 +11,14 @@ #include "util/time.h" struct document; -struct ecmascript_interpreter; struct string; struct terminal; +struct timeout_data; struct uri; struct view_state; - #define get_ecmascript_enable() get_opt_bool("ecmascript.enable") -struct timeout_data { - LIST_HEAD(struct timeout_data); - struct ecmascript_interpreter *interpreter; - unsigned char *code; - timer_id_T timer; -}; - struct ecmascript_interpreter { struct view_state *vs; void *backend_data; @@ -49,9 +41,6 @@ struct ecmascript_interpreter { * go through the list we maintain a pointer to the last processed * entry. */ LIST_OF(struct string_list_item) onload_snippets; - - /* The list of snippets used by setTimeout. */ - LIST_OF(struct timeout_data) timeouts; struct string_list_item *current_onload_snippet; /* ID of the {struct document} where those onload_snippets belong to.