mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
Moved timeouts from document to the ecmascript_interpreter.
This simplifies the code.
This commit is contained in:
parent
05fe38b7b2
commit
fa0fd41c94
@ -55,7 +55,6 @@ 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");
|
||||
@ -106,20 +105,6 @@ 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)
|
||||
{
|
||||
@ -169,7 +154,6 @@ 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);
|
||||
@ -190,9 +174,6 @@ 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);
|
||||
}
|
||||
|
@ -144,15 +144,6 @@ 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);
|
||||
|
||||
@ -174,8 +165,6 @@ 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
|
||||
@ -257,11 +246,6 @@ 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.
|
||||
|
@ -127,6 +127,7 @@ 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
|
||||
@ -135,6 +136,19 @@ 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)
|
||||
{
|
||||
@ -150,9 +164,7 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
spidermonkey_put_interpreter(interpreter);
|
||||
#endif
|
||||
free_string_list(&interpreter->onload_snippets);
|
||||
/* Is it superfluous? */
|
||||
if (interpreter->vs->doc_view)
|
||||
kill_timeouts(interpreter->vs->doc_view->document);
|
||||
kill_timeouts(interpreter);
|
||||
interpreter->vs->ecmascript = NULL;
|
||||
interpreter->vs->ecmascript_fragile = 1;
|
||||
mem_free(interpreter);
|
||||
@ -357,7 +369,7 @@ struct timeout_data *
|
||||
ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, unsigned char *code, int timeout)
|
||||
{
|
||||
struct timeout_data *td;
|
||||
assert(interpreter && interpreter->vs->doc_view->document);
|
||||
assert(interpreter);
|
||||
if (!code) return NULL;
|
||||
|
||||
td = mem_calloc(1, sizeof(*td));
|
||||
@ -369,7 +381,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->vs->doc_view->document->timeouts, td);
|
||||
add_to_list_end(interpreter->timeouts, td);
|
||||
return td;
|
||||
}
|
||||
mem_free(code);
|
||||
|
@ -11,14 +11,22 @@
|
||||
#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;
|
||||
@ -41,6 +49,9 @@ 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.
|
||||
|
Loading…
Reference in New Issue
Block a user