1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-29 01:45:34 +00:00

Revert "Moved timeouts from document to the ecmascript_interpreter."

This reverts commit fa0fd41c94.
This commit is contained in:
Witold Filipczyk 2007-09-21 20:18:38 +02:00 committed by Witold Filipczyk
parent 25536d1e2f
commit c06122a029
4 changed files with 41 additions and 29 deletions

View File

@ -55,6 +55,7 @@ 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
object_nolock(document, "document"); object_nolock(document, "document");
@ -105,6 +106,20 @@ done_link_members(struct link *link)
mem_free_if(link->points); 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 void
done_document(struct document *document) done_document(struct document *document)
{ {
@ -154,6 +169,7 @@ done_document(struct document *document)
#ifdef CONFIG_ECMASCRIPT #ifdef CONFIG_ECMASCRIPT
free_string_list(&document->onload_snippets); free_string_list(&document->onload_snippets);
free_uri_list(&document->ecmascript_imports); free_uri_list(&document->ecmascript_imports);
kill_timeouts(document);
#endif #endif
free_list(document->tags); free_list(document->tags);
@ -174,6 +190,9 @@ release_document(struct document *document)
if_assert_failed return; if_assert_failed return;
if (document->refresh) kill_document_refresh(document->refresh); if (document->refresh) kill_document_refresh(document->refresh);
#ifdef CONFIG_ECMASCRIPT
kill_timeouts(document);
#endif
object_unlock(document); object_unlock(document);
move_to_top_of_list(format_cache, document); move_to_top_of_list(format_cache, document);
} }

View File

@ -144,6 +144,15 @@ struct search {
}; };
#endif #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 { struct document {
OBJECT_HEAD(struct document); OBJECT_HEAD(struct document);
@ -165,6 +174,8 @@ 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 timeout_data) timeouts;
#endif #endif
#ifdef CONFIG_CSS #ifdef CONFIG_CSS
/** @todo FIXME: We should externally maybe using cache_entry store the /** @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); void shrink_format_cache(int);
#ifdef CONFIG_ECMASCRIPT
void kill_timeouts(struct document *document);
#endif
extern struct module document_module; extern struct module document_module;
/** @todo FIXME: support for entities and all Unicode characters. /** @todo FIXME: support for entities and all Unicode characters.

View File

@ -127,7 +127,6 @@ ecmascript_get_interpreter(struct view_state *vs)
interpreter->vs = vs; interpreter->vs = vs;
interpreter->vs->ecmascript_fragile = 0; interpreter->vs->ecmascript_fragile = 0;
init_list(interpreter->onload_snippets); init_list(interpreter->onload_snippets);
init_list(interpreter->timeouts);
#ifdef CONFIG_ECMASCRIPT_SEE #ifdef CONFIG_ECMASCRIPT_SEE
see_get_interpreter(interpreter); see_get_interpreter(interpreter);
#else #else
@ -136,19 +135,6 @@ ecmascript_get_interpreter(struct view_state *vs)
return interpreter; 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 void
ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter) ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
{ {
@ -164,7 +150,9 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
spidermonkey_put_interpreter(interpreter); spidermonkey_put_interpreter(interpreter);
#endif #endif
free_string_list(&interpreter->onload_snippets); 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 = NULL;
interpreter->vs->ecmascript_fragile = 1; interpreter->vs->ecmascript_fragile = 1;
mem_free(interpreter); mem_free(interpreter);
@ -369,7 +357,7 @@ struct timeout_data *
ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, unsigned char *code, int timeout) ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, unsigned char *code, int timeout)
{ {
struct timeout_data *td; struct timeout_data *td;
assert(interpreter); assert(interpreter && interpreter->vs->doc_view->document);
if (!code) return NULL; if (!code) return NULL;
td = mem_calloc(1, sizeof(*td)); td = mem_calloc(1, sizeof(*td));
@ -381,7 +369,7 @@ ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, unsigned char
td->code = code; td->code = code;
install_timer(&td->timer, timeout, ecmascript_timeout_handler, td); install_timer(&td->timer, timeout, ecmascript_timeout_handler, td);
if (td->timer != TIMER_ID_UNDEF) { 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; return td;
} }
mem_free(code); mem_free(code);

View File

@ -11,22 +11,14 @@
#include "util/time.h" #include "util/time.h"
struct document; struct document;
struct ecmascript_interpreter;
struct string; struct string;
struct terminal; struct terminal;
struct timeout_data;
struct uri; struct uri;
struct view_state; struct view_state;
#define get_ecmascript_enable() get_opt_bool("ecmascript.enable") #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 ecmascript_interpreter {
struct view_state *vs; struct view_state *vs;
void *backend_data; void *backend_data;
@ -49,9 +41,6 @@ struct ecmascript_interpreter {
* go through the list we maintain a pointer to the last processed * go through the list we maintain a pointer to the last processed
* entry. */ * entry. */
LIST_OF(struct string_list_item) onload_snippets; 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; struct string_list_item *current_onload_snippet;
/* ID of the {struct document} where those onload_snippets belong to. /* ID of the {struct document} where those onload_snippets belong to.