1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

[mujs] DocumentFragment constructor

This commit is contained in:
Witold Filipczyk 2024-11-15 18:20:01 +01:00
parent ee1f176515
commit 4872ecbd52
5 changed files with 88 additions and 6 deletions

View File

@ -112,6 +112,7 @@ struct ecmascript_interpreter {
#endif
#ifdef CONFIG_MUJS
const char *fun;
void *doc;
#endif
int element_offset;
unsigned int changed:1;

View File

@ -36,6 +36,7 @@
#include "js/mujs/domparser.h"
#include "js/mujs/element.h"
#include "js/mujs/event.h"
#include "js/mujs/fragment.h"
#include "js/mujs/history.h"
#include "js/mujs/image.h"
#include "js/mujs/keyboard.h"
@ -171,6 +172,7 @@ mujs_get_interpreter(struct ecmascript_interpreter *interpreter)
mjs_push_document(J, document->dom);
mjs_document_init(J);
mjs_fragment_init(J);
return J;
#if 0

View File

@ -1715,12 +1715,12 @@ mjs_push_document(js_State *J, void *doc)
addproperty(J, "title", mjs_document_get_property_title, mjs_document_set_property_title); /* TODO: Charset? */
addproperty(J, "URL", mjs_document_get_property_url, mjs_document_set_property_url);
}
js_defglobal(J, "document", JS_DONTENUM);
js_setglobal(J, "document");
init_list(doc_private->listeners);
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
doc_private->interpreter = interpreter;
doc_private->node = doc;
interpreter->doc = doc_private->node = doc;
doc_private->ref_count = 1;
doc_private->thisval = js_ref(J);
if (doc) {

View File

@ -1350,13 +1350,91 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__);
}
}
static void
mjs_DocumentFragment_fun(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushundefined(J);
}
static void
mjs_DocumentFragment_constructor(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
dom_document *doc = (dom_document *)interpreter->doc;
if (!doc) {
js_pushnull(J);
return;
}
dom_document_fragment *fragment = NULL;
dom_exception exc = dom_document_create_document_fragment(doc, &fragment);
if (exc != DOM_NO_ERR || !fragment) {
js_pushnull(J);
return;
}
struct mjs_fragment_private *el_private = (struct mjs_fragment_private *)mem_calloc(1, sizeof(*el_private));
if (!el_private) {
dom_node_unref((dom_node *)fragment);
js_pushnull(J);
return;
}
el_private->node = fragment;
js_newobject(J);
{
js_copy(J, 0);
el_private->thisval = js_ref(J);
js_newuserdata(J, "fragment", el_private, mjs_fragment_finalizer);
addmethod(J, "addEventListener", mjs_fragment_addEventListener, 3);
addmethod(J, "appendChild",mjs_fragment_appendChild, 1);
addmethod(J, "cloneNode", mjs_fragment_cloneNode, 1);
addmethod(J, "contains", mjs_fragment_contains, 1);
addmethod(J, "dispatchEvent", mjs_fragment_dispatchEvent, 1);
addmethod(J, "hasChildNodes", mjs_fragment_hasChildNodes, 0);
addmethod(J, "insertBefore", mjs_fragment_insertBefore, 2);
addmethod(J, "isEqualNode", mjs_fragment_isEqualNode, 1);
addmethod(J, "isSameNode", mjs_fragment_isSameNode, 1);
addmethod(J, "querySelector", mjs_fragment_querySelector, 1);
addmethod(J, "querySelectorAll", mjs_fragment_querySelectorAll, 1);
addmethod(J, "removeChild", mjs_fragment_removeChild, 1);
addmethod(J, "removeEventListener", mjs_fragment_removeEventListener, 3);
addmethod(J, "toString", mjs_fragment_toString, 0);
addproperty(J, "children", mjs_fragment_get_property_children, NULL);
addproperty(J, "childElementCount", mjs_fragment_get_property_childElementCount, NULL);
addproperty(J, "childNodes", mjs_fragment_get_property_childNodes, NULL);
addproperty(J, "firstChild", mjs_fragment_get_property_firstChild, NULL);
addproperty(J, "firstElementChild", mjs_fragment_get_property_firstElementChild, NULL);
addproperty(J, "lastChild", mjs_fragment_get_property_lastChild, NULL);
addproperty(J, "lastElementChild", mjs_fragment_get_property_lastElementChild, NULL);
//// addproperty(J, "nextElementSibling", mjs_fragment_get_property_nextElementSibling, NULL);
addproperty(J, "nextSibling", mjs_fragment_get_property_nextSibling, NULL);
addproperty(J, "nodeName", mjs_fragment_get_property_nodeName, NULL);
addproperty(J, "nodeType", mjs_fragment_get_property_nodeType, NULL);
addproperty(J, "nodeValue", mjs_fragment_get_property_nodeValue, mjs_fragment_set_property_nodeValue);
addproperty(J, "ownerDocument", mjs_fragment_get_property_ownerDocument, NULL);
addproperty(J, "parentElement", mjs_fragment_get_property_parentElement, NULL);
addproperty(J, "parentNode", mjs_fragment_get_property_parentNode, NULL);
//// addproperty(J, "previousElementSibling", mjs_fragment_get_property_previousElementSibling, NULL);
addproperty(J, "previousSibling", mjs_fragment_get_property_previousSibling, NULL);
addproperty(J, "textContent", mjs_fragment_get_property_textContent, mjs_fragment_set_property_textContent);
}
}
int
mjs_fragment_init(js_State *J)
{
#if 0
mjs_push_node(J, NULL);
js_defglobal(J, "fragment", JS_DONTENUM);
#endif
js_pushglobal(J);
js_newcconstructor(J, mjs_DocumentFragment_fun, mjs_DocumentFragment_constructor, "DocumentFragment", 0);
js_defglobal(J, "DocumentFragment", JS_DONTENUM);
return 0;
}

View File

@ -9,6 +9,7 @@ extern "C" {
void *mjs_getprivate_fragment(js_State *J, int idx);
void mjs_push_fragment(js_State *J, void *node);
int mjs_fragment_init(js_State *J);
#ifdef __cplusplus
}