diff --git a/src/ecmascript/mujs/window.cpp b/src/ecmascript/mujs/window.cpp index 2a247df1..21b478e0 100644 --- a/src/ecmascript/mujs/window.cpp +++ b/src/ecmascript/mujs/window.cpp @@ -25,6 +25,7 @@ #include "ecmascript/timer.h" #include "intl/libintl.h" #include "main/select.h" +#include "main/timer.h" #include "osdep/newwin.h" #include "osdep/sysname.h" #include "protocol/http/http.h" @@ -194,17 +195,11 @@ mjs_window_clearTimeout(js_State *J) timer_id_T id = reinterpret_cast(number); if (found_in_map_timer(id)) { - struct ecmascript_timeout *t; - - foreach (t, interpreter->vs->doc_view->document->timeouts) { - if (id == t->tid) { - kill_timer(&t->tid); - done_string(&t->code); - del_from_list(t); - mem_free(t); - break; - } - } + struct ecmascript_timeout *t = (struct ecmascript_timeout *)(id->data); + kill_timer(&t->tid); + done_string(&t->code); + del_from_list(t); + mem_free(t); } js_pushundefined(J); } diff --git a/src/ecmascript/quickjs/window.cpp b/src/ecmascript/quickjs/window.cpp index a998ec26..e1ea34f7 100644 --- a/src/ecmascript/quickjs/window.cpp +++ b/src/ecmascript/quickjs/window.cpp @@ -25,6 +25,7 @@ #include "ecmascript/timer.h" #include "intl/libintl.h" #include "main/select.h" +#include "main/timer.h" #include "osdep/newwin.h" #include "osdep/sysname.h" #include "protocol/http/http.h" @@ -247,17 +248,11 @@ js_window_clearTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueC timer_id_T id = reinterpret_cast(number); if (found_in_map_timer(id)) { - struct ecmascript_timeout *t; - - foreach (t, interpreter->vs->doc_view->document->timeouts) { - if (id == t->tid) { - kill_timer(&t->tid); - done_string(&t->code); - del_from_list(t); - mem_free(t); - break; - } - } + struct ecmascript_timeout *t = (struct ecmascript_timeout *)(id->data); + kill_timer(&t->tid); + done_string(&t->code); + del_from_list(t); + mem_free(t); } return JS_UNDEFINED; diff --git a/src/ecmascript/spidermonkey/window.cpp b/src/ecmascript/spidermonkey/window.cpp index a6578dc3..546d86c8 100644 --- a/src/ecmascript/spidermonkey/window.cpp +++ b/src/ecmascript/spidermonkey/window.cpp @@ -28,6 +28,7 @@ #include "ecmascript/timer.h" #include "intl/libintl.h" #include "main/select.h" +#include "main/timer.h" #include "osdep/newwin.h" #include "osdep/sysname.h" #include "protocol/http/http.h" @@ -407,17 +408,11 @@ window_clearTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval) timer_id_T id = reinterpret_cast(number); if (found_in_map_timer(id)) { - struct ecmascript_timeout *t; - - foreach (t, interpreter->vs->doc_view->document->timeouts) { - if (id == t->tid) { - kill_timer(&t->tid); - done_string(&t->code); - del_from_list(t); - mem_free(t); - break; - } - } + struct ecmascript_timeout *t = (struct ecmascript_timeout *)(id->data); + kill_timer(&t->tid); + done_string(&t->code); + del_from_list(t); + mem_free(t); } return true; } diff --git a/src/main/timer.cpp b/src/main/timer.cpp index 739043ac..d2cafd31 100644 --- a/src/main/timer.cpp +++ b/src/main/timer.cpp @@ -37,14 +37,6 @@ #include "ecmascript/timer.h" #endif -struct timer { - LIST_HEAD(struct timer); - - timeval_T interval; - void (*func)(void *); - void *data; -}; - /* @timers.next points to the timer with the smallest interval, * @timers.next->next to the second smallest, and so on. */ static INIT_LIST_OF(struct timer, timers); diff --git a/src/main/timer.h b/src/main/timer.h index 54cd6537..3c9fabf4 100644 --- a/src/main/timer.h +++ b/src/main/timer.h @@ -1,14 +1,20 @@ #ifndef EL__MAIN_TIMER_H #define EL__MAIN_TIMER_H +#include "util/lists.h" #include "util/time.h" #ifdef __cplusplus extern "C" { #endif -/* Only available internally. */ -struct timer; +struct timer { + LIST_HEAD(struct timer); + + timeval_T interval; + void (*func)(void *); + void *data; +}; /* Little hack, timer_id_T is in fact a pointer to the timer, so * it has to be of a pointer type.