1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[ecmascript] clearTimeout without iteration over timeouts list

This commit is contained in:
Witold Filipczyk 2022-09-07 21:28:31 +02:00
parent bce7e87bb8
commit fb30cb3bf4
5 changed files with 26 additions and 43 deletions

View File

@ -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<timer_id_T>(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);
}

View File

@ -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<timer_id_T>(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;

View File

@ -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<timer_id_T>(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;
}

View File

@ -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);

View File

@ -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.