mirror of
https://github.com/rkd77/elinks.git
synced 2025-05-18 00:48:57 -04:00
[mujs] nodelist.c
This commit is contained in:
parent
a9fdb49327
commit
32908c4b09
@ -1,6 +1,6 @@
|
|||||||
top_builddir=../../../..
|
top_builddir=../../../..
|
||||||
include $(top_builddir)/Makefile.config
|
include $(top_builddir)/Makefile.config
|
||||||
|
|
||||||
OBJS = attr.o attributes.o collection.o console.o forms.o history.o implementation.o keyboard.o localstorage.o mapa.obj message.o navigator.o
|
OBJS = attr.o attributes.o collection.o console.o forms.o history.o implementation.o keyboard.o localstorage.o mapa.obj message.o navigator.o nodelist.o
|
||||||
|
|
||||||
include $(top_srcdir)/Makefile.lib
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
@ -1 +1 @@
|
|||||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'forms.c', 'history.c', 'implementation.c', 'keyboard.c', 'localstorage.c', 'mapa.cpp', 'message.c', 'navigator.c')
|
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'forms.c', 'history.c', 'implementation.c', 'keyboard.c', 'localstorage.c', 'mapa.cpp', 'message.c', 'navigator.c', 'nodelist.c')
|
||||||
|
125
src/ecmascript/libdom/mujs/nodelist.c
Normal file
125
src/ecmascript/libdom/mujs/nodelist.c
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
/* The MuJS nodeList object implementation. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_LIBDOM
|
||||||
|
#include <dom/dom.h>
|
||||||
|
#include <dom/bindings/hubbub/parser.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/libdom/mujs/mapa.h"
|
||||||
|
#include "ecmascript/mujs.h"
|
||||||
|
#include "ecmascript/mujs/element.h"
|
||||||
|
#include "ecmascript/mujs/nodelist.h"
|
||||||
|
#include "ecmascript/mujs/window.h"
|
||||||
|
|
||||||
|
void *map_nodelist;
|
||||||
|
void *map_rev_nodelist;
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_push_nodeList_item2(js_State *J, int idx)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
dom_nodelist *nl = (dom_nodelist *)(js_touserdata(J, 0, "nodelist"));
|
||||||
|
dom_node *element = NULL;
|
||||||
|
dom_exception err;
|
||||||
|
|
||||||
|
if (!nl) {
|
||||||
|
js_pushundefined(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
err = dom_nodelist_item(nl, idx, (void *)&element);
|
||||||
|
|
||||||
|
if (err != DOM_NO_ERR || !element) {
|
||||||
|
js_pushundefined(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mjs_push_element(J, element);
|
||||||
|
dom_node_unref(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_nodeList_item(js_State *J)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
int index = js_toint32(J, 1);
|
||||||
|
|
||||||
|
mjs_push_nodeList_item2(J, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_nodeList_set_items(js_State *J, void *node)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
dom_nodelist *nl = (dom_nodelist *)(node);
|
||||||
|
dom_exception err;
|
||||||
|
uint32_t length, i;
|
||||||
|
|
||||||
|
if (!nl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
err = dom_nodelist_get_length(nl, &length);
|
||||||
|
|
||||||
|
if (err != DOM_NO_ERR) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < length; i++) {
|
||||||
|
dom_node *element = NULL;
|
||||||
|
err = dom_nodelist_item(nl, i, &element);
|
||||||
|
|
||||||
|
if (err != DOM_NO_ERR || !element) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
mjs_push_element(J, element);
|
||||||
|
js_setindex(J, 1, i);
|
||||||
|
dom_node_unref(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_nodeList_toString(js_State *J)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
js_pushstring(J, "[nodeList object]");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_nodeList_finalizer(js_State *J, void *node)
|
||||||
|
{
|
||||||
|
attr_erase_from_map(map_nodelist, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mjs_push_nodelist(js_State *J, void *node)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
js_newobject(J);
|
||||||
|
{
|
||||||
|
js_newuserdata(J, "nodelist", node, mjs_nodeList_finalizer);
|
||||||
|
addmethod(J, "item", mjs_nodeList_item, 1);
|
||||||
|
addmethod(J, "toString", mjs_nodeList_toString, 0);
|
||||||
|
mjs_nodeList_set_items(J, node);
|
||||||
|
}
|
||||||
|
attr_save_in_map(map_nodelist, node, node);
|
||||||
|
}
|
@ -54,6 +54,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#ifndef CONFIG_LIBDOM
|
||||||
static std::map<void *, void *> map_nodelist;
|
static std::map<void *, void *> map_nodelist;
|
||||||
static std::map<void *, void *> map_rev_nodelist;
|
static std::map<void *, void *> map_rev_nodelist;
|
||||||
|
|
||||||
@ -172,3 +173,4 @@ mjs_push_nodelist(js_State *J, void *node)
|
|||||||
}
|
}
|
||||||
map_nodelist[node] = node;
|
map_nodelist[node] = node;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -3,6 +3,14 @@
|
|||||||
|
|
||||||
#include <mujs.h>
|
#include <mujs.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
void mjs_push_nodelist(js_State *J, void *node);
|
void mjs_push_nodelist(js_State *J, void *node);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user