mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[libdom] spidermonkey finalizers
This commit is contained in:
parent
4e9862d94b
commit
d8794b5aec
@ -806,16 +806,6 @@ static struct module *ecmascript_modules[] = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
void
|
||||
free_document(void *doc)
|
||||
{
|
||||
if (!doc) {
|
||||
return;
|
||||
}
|
||||
// xmlpp::Document *docu = static_cast<xmlpp::Document *>(doc);
|
||||
// delete docu;
|
||||
}
|
||||
|
||||
static void
|
||||
delayed_goto(void *data)
|
||||
{
|
||||
|
@ -79,6 +79,16 @@ document_parse(struct document *document)
|
||||
return document_parse_text(f->data, f->length);
|
||||
}
|
||||
|
||||
void
|
||||
free_document(void *doc)
|
||||
{
|
||||
if (!doc) {
|
||||
return;
|
||||
}
|
||||
dom_node *ddd = (dom_node *)doc;
|
||||
dom_node_unref(ddd);
|
||||
}
|
||||
|
||||
void
|
||||
el_insert_before(struct document *document, void *element, struct string *source)
|
||||
{
|
||||
|
@ -57,6 +57,11 @@ static void attr_finalize(JS::GCContext *op, JSObject *obj)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_attr *attr = (dom_attr *)JS::GetMaybePtrFromReservedSlot<dom_attr>(obj, 0);
|
||||
|
||||
if (attr) {
|
||||
dom_node_unref(attr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,6 +62,12 @@ static void attributes_finalize(JS::GCContext *op, JSObject *obj)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_namednodemap *attrs = (dom_namednodemap *)JS::GetMaybePtrFromReservedSlot<dom_namednodemap>(obj, 0);
|
||||
|
||||
if (attrs) {
|
||||
dom_namednodemap_unref(attrs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JSClassOps attributes_ops = {
|
||||
|
@ -63,6 +63,11 @@ static void htmlCollection_finalize(JS::GCContext *op, JSObject *obj)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_html_collection *ns = JS::GetMaybePtrFromReservedSlot<dom_html_collection>(obj, 0);
|
||||
|
||||
if (ns) {
|
||||
dom_html_collection_unref(ns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,6 +67,11 @@ static void document_finalize(JS::GCContext *op, JSObject *obj)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_document *doc = JS::GetMaybePtrFromReservedSlot<dom_document>(obj, 0);
|
||||
|
||||
if (doc) {
|
||||
dom_node_unref(doc);
|
||||
}
|
||||
}
|
||||
|
||||
JSClassOps document_ops = {
|
||||
@ -1763,6 +1768,18 @@ document_querySelectorAll(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void doctype_finalize(JS::GCContext *op, JSObject *obj)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_document_type *dtd = JS::GetMaybePtrFromReservedSlot<dom_document_type>(obj, 0);
|
||||
|
||||
if (dtd) {
|
||||
dom_node_unref(dtd);
|
||||
}
|
||||
}
|
||||
|
||||
JSClassOps doctype_ops = {
|
||||
nullptr, // addProperty
|
||||
nullptr, // deleteProperty
|
||||
@ -1770,7 +1787,7 @@ JSClassOps doctype_ops = {
|
||||
nullptr, // newEnumerate
|
||||
nullptr, // resolve
|
||||
nullptr, // mayResolve
|
||||
nullptr, // finalize
|
||||
doctype_finalize, // finalize
|
||||
nullptr, // call
|
||||
nullptr, // construct
|
||||
JS_GlobalObjectTraceHook
|
||||
|
@ -108,6 +108,8 @@ struct element_private {
|
||||
JS::RootedObject thisval;
|
||||
};
|
||||
|
||||
static std::map<void *, struct element_private *> map_privates;
|
||||
|
||||
static void element_finalize(JS::GCContext *op, JSObject *obj);
|
||||
|
||||
JSClassOps element_ops = {
|
||||
@ -166,6 +168,23 @@ static void element_finalize(JS::GCContext *op, JSObject *obj)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot<dom_node>(obj, 0);
|
||||
struct element_private *el_private = JS::GetMaybePtrFromReservedSlot<struct element_private>(obj, 1);
|
||||
|
||||
if (el_private) {
|
||||
map_privates.erase(el);
|
||||
|
||||
struct listener *l;
|
||||
|
||||
foreach(l, el_private->listeners) {
|
||||
mem_free_set(&l->typ, NULL);
|
||||
}
|
||||
free_list(el_private->listeners);
|
||||
mem_free(el_private);
|
||||
}
|
||||
if (el) {
|
||||
dom_node_unref(el);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -4032,7 +4051,6 @@ element_setAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::map<void *, struct element_private *> map_privates;
|
||||
|
||||
JSObject *
|
||||
getElement(JSContext *ctx, void *node)
|
||||
|
@ -60,6 +60,11 @@ static void nodeList_finalize(JS::GCContext *op, JSObject *obj)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_nodelist *nl = JS::GetMaybePtrFromReservedSlot<dom_nodelist>(obj, 0);
|
||||
|
||||
if (nl) {
|
||||
dom_nodelist_unref(nl);
|
||||
}
|
||||
}
|
||||
|
||||
JSClassOps nodeList_ops = {
|
||||
|
Loading…
Reference in New Issue
Block a user