mirror of
https://github.com/rkd77/elinks.git
synced 2024-09-27 02:56:18 -04:00
[ecmascript] timer.cpp -> timer.c
hash instead of map. The goal is to get C++ free code for mujs and quickjs.
This commit is contained in:
parent
447c452339
commit
78483386c2
@ -10,11 +10,11 @@ SUBDIRS-$(CONFIG_QUICKJS) += quickjs
|
||||
|
||||
SUBDIRS-$(CONFIG_ECMASCRIPT_SMJS) += spidermonkey
|
||||
|
||||
OBJS-$(CONFIG_ECMASCRIPT_SMJS) += ecmascript.obj ecmascript-c.obj localstorage-db.obj spidermonkey.obj timer.obj
|
||||
OBJS-$(CONFIG_ECMASCRIPT_SMJS) += ecmascript.obj ecmascript-c.obj localstorage-db.obj spidermonkey.obj timer.o
|
||||
|
||||
OBJS-$(CONFIG_MUJS) += ecmascript.obj ecmascript-c.obj localstorage-db.obj mujs.obj timer.obj
|
||||
OBJS-$(CONFIG_MUJS) += ecmascript.obj ecmascript-c.obj localstorage-db.obj mujs.obj timer.o
|
||||
|
||||
OBJS-$(CONFIG_QUICKJS) += ecmascript.obj ecmascript-c.obj localstorage-db.obj quickjs.obj timer.obj
|
||||
OBJS-$(CONFIG_QUICKJS) += ecmascript.obj ecmascript-c.obj localstorage-db.obj quickjs.obj timer.o
|
||||
|
||||
ifeq ($(CONFIG_ECMASCRIPT_SMJS), yes)
|
||||
CONFIG_ANY_SPIDERMONKEY = yes
|
||||
|
@ -58,8 +58,6 @@
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
std::map<struct timer *, bool> map_timer;
|
||||
|
||||
/* TODO: We should have some kind of ACL for the scripts - i.e. ability to
|
||||
* disallow the scripts to open new windows (or so that the windows are always
|
||||
* directed to tabs, this particular option would be a tristate), disallow
|
||||
@ -623,6 +621,7 @@ init_ecmascript_module(struct module *module)
|
||||
#else
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
#endif
|
||||
init_map_timer();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -634,6 +633,7 @@ done_ecmascript_module(struct module *module)
|
||||
mem_free_if(console_log_filename);
|
||||
mem_free_if(console_error_filename);
|
||||
mem_free_if(local_storage_filename);
|
||||
done_map_timer();
|
||||
}
|
||||
|
||||
static struct module *ecmascript_modules[] = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
#INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||
if conf_data.get('CONFIG_ECMASCRIPT_SMJS')
|
||||
srcs += files('ecmascript.cpp', 'ecmascript-c.cpp', 'localstorage-db.cpp', 'spidermonkey.cpp', 'timer.cpp')
|
||||
srcs += files('ecmascript.cpp', 'ecmascript-c.cpp', 'localstorage-db.cpp', 'spidermonkey.cpp', 'timer.c')
|
||||
subdir('spidermonkey')
|
||||
endif
|
||||
|
||||
@ -17,12 +17,12 @@ if CONFIG_ANY_SPIDERMONKEY
|
||||
endif
|
||||
|
||||
if conf_data.get('CONFIG_MUJS')
|
||||
srcs += files('ecmascript.cpp', 'ecmascript-c.cpp', 'localstorage-db.cpp', 'mujs.cpp', 'timer.cpp')
|
||||
srcs += files('ecmascript.cpp', 'ecmascript-c.cpp', 'localstorage-db.cpp', 'mujs.cpp', 'timer.c')
|
||||
subdir('mujs')
|
||||
endif
|
||||
|
||||
if conf_data.get('CONFIG_QUICKJS')
|
||||
srcs += files('ecmascript.cpp', 'ecmascript-c.cpp', 'localstorage-db.cpp', 'quickjs.cpp', 'timer.cpp')
|
||||
srcs += files('ecmascript.cpp', 'ecmascript-c.cpp', 'localstorage-db.cpp', 'quickjs.cpp', 'timer.c')
|
||||
subdir('quickjs')
|
||||
endif
|
||||
|
||||
|
90
src/ecmascript/timer.c
Normal file
90
src/ecmascript/timer.c
Normal file
@ -0,0 +1,90 @@
|
||||
/* ECMAScript timer */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/timer.h"
|
||||
#include "util/hash.h"
|
||||
#include "util/string.h"
|
||||
|
||||
struct timer;
|
||||
static struct hash *map_timer;
|
||||
|
||||
void
|
||||
init_map_timer(void)
|
||||
{
|
||||
map_timer = init_hash8();
|
||||
}
|
||||
|
||||
void
|
||||
done_map_timer(void)
|
||||
{
|
||||
struct hash_item *item;
|
||||
int i;
|
||||
|
||||
if (!map_timer) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach_hash_item (item, *map_timer, i) {
|
||||
mem_free_set(&item->key, NULL);
|
||||
}
|
||||
free_hash(&map_timer);
|
||||
}
|
||||
|
||||
void
|
||||
add_to_map_timer(struct timer *timer)
|
||||
{
|
||||
if (map_timer) {
|
||||
char *key = memacpy((const char *)&timer, sizeof(timer));
|
||||
|
||||
if (key) {
|
||||
add_hash_item(map_timer, key, sizeof(timer), (void *)(intptr_t)1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
del_from_map_timer(struct timer *timer)
|
||||
{
|
||||
if (map_timer) {
|
||||
char *key = memacpy((const char *)&timer, sizeof(timer));
|
||||
|
||||
if (key) {
|
||||
struct hash_item *item = get_hash_item(map_timer, key, sizeof(timer));
|
||||
|
||||
if (item) {
|
||||
mem_free_set(&item->key, NULL);
|
||||
del_hash_item(map_timer, item);
|
||||
}
|
||||
mem_free(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
found_in_map_timer(struct timer *timer)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
if (map_timer) {
|
||||
char *key = memacpy((const char *)&timer, sizeof(timer));
|
||||
|
||||
if (key) {
|
||||
struct hash_item *item = get_hash_item(map_timer, key, sizeof(timer));
|
||||
|
||||
if (item) {
|
||||
ret = true;
|
||||
}
|
||||
mem_free(key);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/* ECMAScript timer */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/timer.h"
|
||||
|
||||
struct timer;
|
||||
|
||||
extern std::map<struct timer *, bool> map_timer;
|
||||
|
||||
void
|
||||
add_to_map_timer(struct timer *timer)
|
||||
{
|
||||
map_timer[timer] = true;
|
||||
}
|
||||
|
||||
void
|
||||
del_from_map_timer(struct timer *timer)
|
||||
{
|
||||
map_timer.erase(timer);
|
||||
}
|
||||
|
||||
bool
|
||||
found_in_map_timer(struct timer *timer)
|
||||
{
|
||||
return map_timer.find(timer) != map_timer.end();
|
||||
}
|
@ -9,6 +9,8 @@ extern "C" {
|
||||
|
||||
struct timer;
|
||||
|
||||
void init_map_timer(void);
|
||||
void done_map_timer(void);
|
||||
void add_to_map_timer(struct timer *timer);
|
||||
void del_from_map_timer(struct timer *timer);
|
||||
bool found_in_map_timer(struct timer *timer);
|
||||
|
Loading…
Reference in New Issue
Block a user