1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

[quickjs] init/deinit maps

This commit is contained in:
Witold Filipczyk 2023-04-04 14:35:06 +02:00
parent f562a8ed99
commit e4f195c7ad
12 changed files with 115 additions and 24 deletions

View File

@ -112,7 +112,7 @@ static const JSCFunctionListEntry js_attr_proto_funcs[] = {
JS_CFUNC_DEF("toString", 0, js_attr_toString)
};
static void *map_attrs;
void *map_attrs;
static
void js_attr_finalizer(JSRuntime *rt, JSValue val)
@ -140,7 +140,6 @@ getAttr(JSContext *ctx, void *node)
if (!initialized) {
JS_NewClassID(&js_attr_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_attr_class_id, &js_attr_class);
map_attrs = attr_create_new_attrs_map();
initialized = 1;
}
second = attr_find_in_map(map_attrs, node);

View File

@ -289,8 +289,6 @@ getAttributes(JSContext *ctx, void *node)
static int initialized;
/* create the element class */
if (!initialized) {
map_attributes = attr_create_new_attributes_map();
map_rev_attributes = attr_create_new_attributes_map_rev();
initialized = 1;
}
second = attr_find_in_map(map_attributes, node);

View File

@ -289,8 +289,6 @@ getCollection(JSContext *ctx, void *node)
JSValue second;
if (!initialized) {
map_collections = attr_create_new_collections_map();
map_rev_collections = attr_create_new_collections_map_rev();
initialized = 1;
}
second = attr_find_in_map(map_collections, node);

View File

@ -1759,7 +1759,6 @@ getDoctype(JSContext *ctx, void *node)
JS_NewClassID(&js_doctype_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_doctype_class_id, &js_doctype_class);
initialized = 1;
map_doctypes = attr_create_new_doctypes_map();
}
second = attr_find_in_map(map_doctypes, node);

View File

@ -2561,8 +2561,6 @@ getElement(JSContext *ctx, void *node)
if (!initialized) {
JS_NewClassID(&js_element_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_element_class_id, &js_element_class);
map_elements = attr_create_new_elements_map();
map_privates = attr_create_new_privates_map_void();
initialized = 1;
}
second = attr_find_in_map(map_elements, node);

View File

@ -1018,8 +1018,6 @@ getForm(JSContext *ctx, struct form *form)
static int initialized;
if (!initialized) {
map_form = attr_create_new_form_map();
map_form_rev = attr_create_new_form_map_rev();
initialized = 1;
}
second = attr_find_in_map(map_form, (void *)form);

View File

@ -262,8 +262,6 @@ getForms(JSContext *ctx, void *node)
JSValue second;
static int initialized;
if (!initialized) {
map_forms = attr_create_new_forms_map();
map_rev_forms = attr_create_new_forms_map_rev();
initialized = 1;
}
second = attr_find_in_map(map_forms, node);

View File

@ -1597,7 +1597,6 @@ getInput(JSContext *ctx, struct form_state *fs)
JS_NewClassID(&js_input_class_id);
JS_NewClass(JS_GetRuntime(ctx), js_input_class_id, &js_input_class);
initialized = 1;
map_inputs = attr_create_new_input_map();
}
second = attr_find_in_map(map_inputs, (void *)fs);

View File

@ -196,6 +196,21 @@ attr_clear_map(void *m)
mapa->clear();
}
void
attr_clear_map_rev(void *m)
{
std::map<JSValueConst, void *> *mapa = static_cast<std::map<JSValueConst, void *> *>(m);
mapa->clear();
}
void
attr_clear_map_void(void *m)
{
std::map<void *, void *> *mapa = static_cast<std::map<void *, void *> *>(m);
mapa->clear();
}
void
attr_clear_map_str(void *m)
{
@ -213,6 +228,36 @@ delete_map_str(void *m)
}
}
void
attr_delete_map(void *m)
{
std::map<void *, JSValueConst> *mapa = static_cast<std::map<void *, JSValueConst> *>(m);
if (mapa) {
delete(mapa);
}
}
void
attr_delete_map_rev(void *m)
{
std::map<JSValueConst, void *> *mapa = static_cast<std::map<JSValueConst, void *> *>(m);
if (mapa) {
delete(mapa);
}
}
void
attr_delete_map_void(void *m)
{
std::map<void *, void *> *mapa = static_cast<std::map<void *, void *> *>(m);
if (mapa) {
delete(mapa);
}
}
JSValue
attr_find_in_map(void *m, void *node)
{
@ -259,13 +304,6 @@ attr_save_in_map_rev(void *m, JSValueConst value, void *node)
(*mapa)[value] = node;
}
void
attr_clear_map_rev(void *m)
{
std::map<JSValueConst, void *> *mapa = static_cast<std::map<JSValueConst, void *> *>(m);
mapa->clear();
}
void *
attr_find_in_map_rev(void *m, JSValueConst value)
{

View File

@ -9,6 +9,22 @@ extern "C" {
struct Xhr;
extern void *map_attrs;
extern void *map_attributes;
extern void *map_rev_attributes;
extern void *map_collections;
extern void *map_rev_collections;
extern void *map_doctypes;
extern void *map_elements;
extern void *map_privates;
extern void *map_form;
extern void *map_form_rev;
extern void *map_forms;
extern void *map_rev_forms;
extern void *map_inputs;
extern void *map_nodelist;
extern void *map_rev_nodelist;
void attr_save_in_map(void *m, void *node, JSValueConst value);
void attr_save_in_map_void(void *m, void *node, void *value);
@ -34,8 +50,13 @@ void *attr_create_new_requestHeaders_map(void);
void *attr_create_new_responseHeaders_map(void);
void attr_clear_map(void *m);
void attr_clear_map_rev(void *m);
void attr_clear_map_void(void *m);
void attr_clear_map_str(void *m);
void delete_map_str(void *m);
void attr_delete_map(void *m);
void attr_delete_map_rev(void *m);
void attr_delete_map_void(void *m);
JSValue attr_find_in_map(void *m, void *node);
void *attr_find_in_map_void(void *m, void *node);

View File

@ -161,8 +161,6 @@ getNodeList(JSContext *ctx, void *node)
JSValue second, nodeList_obj;
if (!initialized) {
map_nodelist = attr_create_new_nodelist_map();
map_rev_nodelist = attr_create_new_nodelist_map_rev();
initialized = 1;
}
second = attr_find_in_map(map_nodelist, node);

View File

@ -24,6 +24,7 @@
#include "document/renderer.h"
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/libdom/quickjs/mapa.h"
#include "ecmascript/quickjs.h"
#include "ecmascript/quickjs/console.h"
#include "ecmascript/quickjs/document.h"
@ -61,13 +62,27 @@
/*** Global methods */
static void
quickjs_init(struct module *xxx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
map_attrs = attr_create_new_attrs_map();
map_attributes = attr_create_new_attributes_map();
map_rev_attributes = attr_create_new_attributes_map_rev();
map_collections = attr_create_new_collections_map();
map_rev_collections = attr_create_new_collections_map_rev();
map_doctypes = attr_create_new_doctypes_map();
map_elements = attr_create_new_elements_map();
map_privates = attr_create_new_privates_map_void();
map_form = attr_create_new_form_map();
map_form_rev = attr_create_new_form_map_rev();
map_forms = attr_create_new_forms_map();
map_rev_forms = attr_create_new_forms_map_rev();
map_inputs = attr_create_new_input_map();
map_nodelist = attr_create_new_nodelist_map();
map_rev_nodelist = attr_create_new_nodelist_map_rev();
//js_module_init_ok = spidermonkey_runtime_addref();
}
@ -77,6 +92,38 @@ quickjs_done(struct module *xxx)
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
attr_clear_map(map_attrs);
attr_clear_map(map_attributes);
attr_clear_map_rev(map_rev_attributes);
attr_clear_map(map_collections);
attr_clear_map_rev(map_rev_collections);
attr_clear_map(map_doctypes);
attr_clear_map(map_elements);
attr_clear_map_void(map_privates);
attr_clear_map(map_form);
attr_clear_map_rev(map_form_rev);
attr_clear_map(map_forms);
attr_clear_map_rev(map_rev_forms);
attr_clear_map(map_inputs);
attr_clear_map(map_nodelist);
attr_clear_map_rev(map_rev_nodelist);
attr_delete_map(map_attrs);
attr_delete_map(map_attributes);
attr_delete_map_rev(map_rev_attributes);
attr_delete_map(map_collections);
attr_delete_map_rev(map_rev_collections);
attr_delete_map(map_doctypes);
attr_delete_map(map_elements);
attr_delete_map_void(map_privates);
attr_delete_map(map_form);
attr_delete_map_rev(map_form_rev);
attr_delete_map(map_forms);
attr_delete_map_rev(map_rev_forms);
attr_delete_map(map_inputs);
attr_delete_map(map_nodelist);
attr_delete_map_rev(map_rev_nodelist);
// if (js_module_init_ok)
// spidermonkey_runtime_release();
}