diff --git a/src/ecmascript/mujs/fragment.c b/src/ecmascript/mujs/fragment.c index 3541953f..b4c52186 100644 --- a/src/ecmascript/mujs/fragment.c +++ b/src/ecmascript/mujs/fragment.c @@ -98,93 +98,6 @@ mjs_getprivate_fragment(js_State *J, int idx) return priv->node; } -#if 0 -static void -mjs_fragment_get_property_attributes(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - dom_namednodemap *attrs = NULL; - dom_exception exc = dom_node_get_attributes(el, &attrs); - - if (exc != DOM_NO_ERR || !attrs) { - js_pushnull(J); - return; - } - mjs_push_attributes(J, attrs); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_checked(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - struct view_state *vs = interpreter->vs; - struct document_view *doc_view; - struct document *doc; - struct el_form_control *fc; - struct form_state *fs; - struct link *link; - int offset, linknum; - - if (!vs) { - js_pushundefined(J); - return; - } - doc_view = vs->doc_view; - - if (!doc_view) { - js_pushundefined(J); - return; - } - doc = doc_view->document; - - if (!el) { - js_pushundefined(J); - return; - } - offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - js_pushundefined(J); - return; - } - linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - js_pushundefined(J); - return; - } - - link = &doc->links[linknum]; - fc = get_link_form_control(link); - - if (!fc) { - js_pushundefined(J); - return; - } - fs = find_form_state(doc_view, fc); - - if (!fs) { - js_pushundefined(J); - return; - } - js_pushboolean(J, fs->state); -} -#endif - static void mjs_fragment_get_property_children(js_State *J) { @@ -259,266 +172,6 @@ mjs_fragment_get_property_childNodes(js_State *J) dom_nodelist_unref(nodes); } -#if 0 -static void -mjs_fragment_get_property_classList(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_element *el = (dom_element *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_ref(el); - dom_tokenlist *tl = NULL; - dom_exception exc = dom_tokenlist_create(el, corestring_dom_class, &tl); -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(el); - - if (exc != DOM_NO_ERR || !tl) { - js_pushnull(J); - return; - } - mjs_push_tokenlist(J, tl); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_className(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_html_element *el = (dom_html_element *)(mjs_getprivate_fragment(J, 0)); - dom_string *classstr = NULL; - dom_exception exc; - - if (!el) { - js_pushnull(J); - return; - } - exc = dom_html_element_get_class_name(el, &classstr); - - if (exc != DOM_NO_ERR) { - js_pushnull(J); - return; - } - if (!classstr) { - js_pushstring(J, ""); - return; - } else { - js_pushstring(J, dom_string_data(classstr)); - dom_string_unref(classstr); - } -} -#endif - -#if 0 -static void -mjs_fragment_get_property_clientHeight(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - struct view_state *vs = interpreter->vs; - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses; - - if (!document) { - js_pushnumber(J, 0); - return; - } - ses = doc_view->session; - - if (!ses) { - js_pushnumber(J, 0); - return; - } - dom_string *tag_name = NULL; - dom_exception exc = dom_node_get_node_name(el, &tag_name); - - if (exc != DOM_NO_ERR || !tag_name) { - js_pushnumber(J, 0); - return; - } - bool root = (!strcmp(dom_string_data(tag_name), "BODY") || !strcmp(dom_string_data(tag_name), "HTML")); - dom_string_unref(tag_name); - - if (root) { - int height = doc_view->box.height * ses->tab->term->cell_height; - js_pushnumber(J, height); - return; - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - js_pushnumber(J, 0); - return; - } - struct node_rect *rect = get_element_rect(document, offset); - - if (!rect) { - js_pushnumber(J, 0); - return; - } - int dy = int_max(0, (rect->y1 + 1 - rect->y0) * ses->tab->term->cell_height); - js_pushnumber(J, dy); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_clientLeft(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - js_pushnumber(J, 0); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_clientTop(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - js_pushnumber(J, 0); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_clientWidth(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - struct view_state *vs = interpreter->vs; - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses; - - if (!document) { - js_pushnumber(J, 0); - return; - } - ses = doc_view->session; - - if (!ses) { - js_pushnumber(J, 0); - return; - } - dom_string *tag_name = NULL; - dom_exception exc = dom_node_get_node_name(el, &tag_name); - - if (exc != DOM_NO_ERR || !tag_name) { - js_pushnumber(J, 0); - return; - } - bool root = (!strcmp(dom_string_data(tag_name), "BODY") || !strcmp(dom_string_data(tag_name), "HTML") || !strcmp(dom_string_data(tag_name), "DIV")); - dom_string_unref(tag_name); - - if (root) { - int width = doc_view->box.width * ses->tab->term->cell_width; - js_pushnumber(J, width); - return; - } - - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - js_pushnumber(J, 0); - return; - } - struct node_rect *rect = get_element_rect(document, offset); - - if (!rect) { - js_pushnumber(J, 0); - return; - } - int dx = int_max(0, (rect->x1 + 1 - rect->x0) * ses->tab->term->cell_width); - js_pushnumber(J, dx); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_dataset(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_element *el = (dom_element *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - mjs_push_dataset(J, el); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_dir(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - dom_string *dir = NULL; - dom_exception exc; - - if (!el) { - js_pushnull(J); - return; - } - exc = dom_element_get_attribute(el, corestring_dom_dir, &dir); - - if (exc != DOM_NO_ERR) { - js_pushnull(J); - return; - } - if (!dir) { - js_pushstring(J, ""); - return; - } else { - if (strcmp(dom_string_data(dir), "auto") && strcmp(dom_string_data(dir), "ltr") && strcmp(dom_string_data(dir), "rtl")) { - js_pushstring(J, ""); - } else { - js_pushstring(J, dom_string_data(dir)); - } - dom_string_unref(dir); - } -} -#endif - static void mjs_fragment_get_property_firstChild(js_State *J) { @@ -605,96 +258,6 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); js_pushnull(J); } -#if 0 -static void -mjs_fragment_get_property_href(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - dom_string *href = NULL; - dom_exception exc; - - if (!el) { - js_pushnull(J); - return; - } - exc = dom_element_get_attribute(el, corestring_dom_href, &href); - - if (exc != DOM_NO_ERR) { - js_pushnull(J); - return; - } - if (!href) { - js_pushstring(J, ""); - return; - } else { - js_pushstring(J, dom_string_data(href)); - dom_string_unref(href); - } -} -#endif - -static void -mjs_fragment_get_property_id(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - dom_string *id = NULL; - dom_exception exc; - - if (!el) { - js_pushnull(J); - return; - } - exc = dom_element_get_attribute(el, corestring_dom_id, &id); - - if (exc != DOM_NO_ERR) { - js_pushnull(J); - return; - } - if (!id) { - js_pushstring(J, ""); - return; - } else { - js_pushstring(J, dom_string_data(id)); - dom_string_unref(id); - } -} - -#if 0 -static void -mjs_fragment_get_property_lang(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - dom_string *lang = NULL; - dom_exception exc; - - if (!el) { - js_pushnull(J); - return; - } - exc = dom_element_get_attribute(el, corestring_dom_lang, &lang); - - if (exc != DOM_NO_ERR) { - js_pushnull(J); - return; - } - if (!lang) { - js_pushstring(J, ""); - } else { - js_pushstring(J, dom_string_data(lang)); - dom_string_unref(lang); - } -} -#endif - static void mjs_fragment_get_property_lastChild(js_State *J) { @@ -901,7 +464,6 @@ mjs_fragment_get_property_nodeValue(js_State *J) dom_string_unref(content); } -#if 0 static void mjs_fragment_get_property_nextSibling(js_State *J) { @@ -928,194 +490,6 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); #endif dom_node_unref(node); } -#endif - -#if 0 -static void -mjs_fragment_get_property_offsetHeight(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - mjs_fragment_get_property_clientHeight(J); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_offsetLeft(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - struct view_state *vs = interpreter->vs; - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses; - - if (!document) { - js_pushnumber(J, 0); - return; - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - js_pushnumber(J, 0); - return; - } - struct node_rect *rect = get_element_rect(document, offset); - - if (!rect) { - js_pushnumber(J, 0); - return; - } - ses = doc_view->session; - - if (!ses) { - js_pushnumber(J, 0); - return; - } - dom_node *node = NULL; - dom_exception exc = dom_node_get_parent_node(el, &node); - if (exc != DOM_NO_ERR || !node) { - js_pushnumber(J, 0); - return; - } - int offset_parent = find_offset(document->element_map_rev, node); - - if (offset_parent <= 0) { - js_pushnumber(J, 0); - return; - } - struct node_rect *rect_parent = get_element_rect(document, offset_parent); - - if (!rect_parent) { - js_pushnumber(J, 0); - return; - } - int dx = int_max(0, (rect->x0 - rect_parent->x0) * ses->tab->term->cell_width); -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(node); - js_pushnumber(J, dx); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_offsetParent(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - dom_node *node = NULL; - dom_exception exc; - - if (!el) { - js_pushnull(J); - return; - } - exc = dom_node_get_parent_node(el, &node); - - if (exc != DOM_NO_ERR || !node) { - js_pushnull(J); - return; - } - mjs_push_element(J, node); -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(node); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_offsetTop(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - struct view_state *vs = interpreter->vs; - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses; - - if (!document) { - js_pushnumber(J, 0); - return; - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - js_pushnumber(J, 0); - return; - } - struct node_rect *rect = get_element_rect(document, offset); - - if (!rect) { - js_pushnumber(J, 0); - return; - } - ses = doc_view->session; - - if (!ses) { - js_pushnumber(J, 0); - return; - } - dom_node *node = NULL; - dom_exception exc = dom_node_get_parent_node(el, &node); - if (exc != DOM_NO_ERR || !node) { - js_pushnumber(J, 0); - return; - } - int offset_parent = find_offset(document->element_map_rev, node); - - if (offset_parent <= 0) { - js_pushnumber(J, 0); - return; - } - struct node_rect *rect_parent = get_element_rect(document, offset_parent); - - if (!rect_parent) { - js_pushnumber(J, 0); - return; - } - int dy = int_max(0, (rect->y0 - rect_parent->y0) * ses->tab->term->cell_height); -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(node); - js_pushnumber(J, dy); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_offsetWidth(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - mjs_fragment_get_property_clientWidth(J); -} -#endif static void mjs_fragment_get_property_ownerDocument(js_State *J) @@ -1182,6 +556,7 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); dom_node_unref(node); } +#if 0 static void mjs_fragment_get_property_previousElementSibling(js_State *J) { @@ -1229,6 +604,7 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); } js_pushnull(J); } +#endif static void mjs_fragment_get_property_previousSibling(js_State *J) @@ -1257,189 +633,6 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); dom_node_unref(node); } -#if 0 -static void -mjs_fragment_get_property_style(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - mjs_push_style(J, el); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_tagName(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - dom_string *tag_name = NULL; - dom_exception exc = dom_node_get_node_name(el, &tag_name); - - if (exc != DOM_NO_ERR || !tag_name) { - js_pushnull(J); - return; - } - js_pushstring(J, dom_string_data(tag_name)); - dom_string_unref(tag_name); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_title(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - dom_string *title = NULL; - dom_exception exc; - - if (!el) { - js_pushnull(J); - return; - } - exc = dom_element_get_attribute(el, corestring_dom_title, &title); - - if (exc != DOM_NO_ERR) { - js_pushnull(J); - return; - } - if (!title) { - js_pushstring(J, ""); - } else { - js_pushstring(J, dom_string_data(title)); - dom_string_unref(title); - } -} -#endif - -#if 0 -static void -mjs_fragment_get_property_value(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - struct view_state *vs = interpreter->vs; - struct document_view *doc_view; - struct document *doc; - struct el_form_control *fc; - struct form_state *fs; - struct link *link; - int offset, linknum; - - if (!vs) { - js_pushundefined(J); - return; - } - doc_view = vs->doc_view; - - if (!doc_view) { - js_pushundefined(J); - return; - } - doc = doc_view->document; - - if (!el) { - js_pushundefined(J); - return; - } - offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - js_pushundefined(J); - return; - } - linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - js_pushundefined(J); - return; - } - - link = &doc->links[linknum]; - fc = get_link_form_control(link); - - if (!fc) { - js_pushundefined(J); - return; - } - fs = find_form_state(doc_view, fc); - - if (!fs) { - js_pushundefined(J); - return; - } - js_pushstring(J, fs->value); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_innerHtml(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - struct string buf; - if (!init_string(&buf)) { - js_error(J, "out of memory"); - return; - } - ecmascript_walk_tree(&buf, el, true, false); - js_pushstring(J, buf.source); - done_string(&buf); -} -#endif - -#if 0 -static void -mjs_fragment_get_property_outerHtml(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushnull(J); - return; - } - struct string buf; - if (!init_string(&buf)) { - js_error(J, "out of memory"); - return; - } - ecmascript_walk_tree(&buf, el, false, false); - js_pushstring(J, buf.source); - done_string(&buf); -} -#endif - static void mjs_fragment_get_property_textContent(js_State *J) { @@ -1463,596 +656,6 @@ mjs_fragment_get_property_textContent(js_State *J) dom_string_unref(content); } -#if 0 -static void -mjs_fragment_set_property_checked(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - struct view_state *vs = interpreter->vs; - struct document_view *doc_view; - struct document *doc; - struct el_form_control *fc; - struct form_state *fs; - struct link *link; - int offset, linknum; - - if (!vs) { - js_pushundefined(J); - return; - } - doc_view = vs->doc_view; - - if (!doc_view) { - js_pushundefined(J); - return; - } - doc = doc_view->document; - - if (!el) { - js_pushundefined(J); - return; - } - offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - js_pushundefined(J); - return; - } - linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - js_pushundefined(J); - return; - } - - link = &doc->links[linknum]; - fc = get_link_form_control(link); - - if (!fc) { - js_pushundefined(J); - return; - } - fs = find_form_state(doc_view, fc); - - if (!fs) { - js_pushundefined(J); - return; - } - - if (fc->type != FC_CHECKBOX && fc->type != FC_RADIO) { - js_pushundefined(J); - return; - } - fs->state = js_toboolean(J, 1); - js_pushundefined(J); -} -#endif - -#if 0 -static void -mjs_fragment_set_property_className(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_string *classstr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - assert(interpreter); - dom_html_element *el = (dom_html_element *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushundefined(J); - return; - } - const char *str = js_tostring(J, 1); - - if (!str) { - js_error(J, "out of memory"); - return; - } - exc = dom_string_create((const uint8_t *)str, strlen(str), &classstr); - - if (exc == DOM_NO_ERR && classstr) { - exc = dom_html_element_set_class_name(el, classstr); - interpreter->changed = 1; - dom_string_unref(classstr); - } - js_pushundefined(J); -} -#endif - -#if 0 -static void -mjs_fragment_set_property_dir(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - assert(interpreter); - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushundefined(J); - return; - } - const char *str = js_tostring(J, 1); - - if (!str) { - js_error(J, "out of memory"); - return; - } - if (!strcmp(str, "ltr") || !strcmp(str, "rtl") || !strcmp(str, "auto")) { - dom_string *dir = NULL; - exc = dom_string_create((const uint8_t *)str, strlen(str), &dir); - - if (exc == DOM_NO_ERR && dir) { - exc = dom_element_set_attribute(el, corestring_dom_dir, dir); - interpreter->changed = 1; - dom_string_unref(dir); - } - } - js_pushundefined(J); -} -#endif - -#if 0 -static void -mjs_fragment_set_property_href(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_string *hrefstr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - assert(interpreter); - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushundefined(J); - return; - } - const char *str = js_tostring(J, 1); - if (!str) { - js_error(J, "out of memory"); - return; - } - exc = dom_string_create((const uint8_t *)str, strlen(str), &hrefstr); - - if (exc == DOM_NO_ERR && hrefstr) { - exc = dom_element_set_attribute(el, corestring_dom_href, hrefstr); - interpreter->changed = 1; - dom_string_unref(hrefstr); - } - js_pushundefined(J); -} -#endif - -static void -mjs_fragment_set_property_id(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_string *idstr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - assert(interpreter); - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushundefined(J); - return; - } - const char *str = js_tostring(J, 1); - if (!str) { - js_error(J, "out of memory"); - return; - } - exc = dom_string_create((const uint8_t *)str, strlen(str), &idstr); - - if (exc == DOM_NO_ERR && idstr) { - exc = dom_element_set_attribute(el, corestring_dom_id, idstr); - interpreter->changed = 1; - dom_string_unref(idstr); - } - js_pushundefined(J); -} - -#if 0 -static void -mjs_fragment_set_property_innerHtml(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_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushundefined(J); - return; - } - const char *s = js_tostring(J, 1); - - if (!s) { - js_error(J, "out of memory"); - return; - } - dom_hubbub_parser_params parse_params; - dom_hubbub_error error; - dom_hubbub_parser *parser = NULL; - struct dom_document *doc = NULL; - struct dom_document_fragment *fragment = NULL; - dom_exception exc; - struct dom_node *child = NULL, *html = NULL, *body = NULL; - struct dom_nodelist *bodies = NULL; - - exc = dom_node_get_owner_document(el, &doc); - if (exc != DOM_NO_ERR) goto out; - - parse_params.enc = "UTF-8"; - parse_params.fix_enc = true; - parse_params.enable_script = false; - parse_params.msg = NULL; - parse_params.script = NULL; - parse_params.ctx = NULL; - parse_params.daf = NULL; - - error = dom_hubbub_fragment_parser_create(&parse_params, - doc, - &parser, - &fragment); - if (error != DOM_HUBBUB_OK) { - fprintf(stderr, "Unable to create fragment parser!"); - goto out; - } - - error = dom_hubbub_parser_parse_chunk(parser, (const uint8_t*)s, strlen(s)); - if (error != DOM_HUBBUB_OK) { - fprintf(stderr, "Unable to parse HTML chunk"); - goto out; - } - error = dom_hubbub_parser_completed(parser); - if (error != DOM_HUBBUB_OK) { - fprintf(stderr, "Unable to complete parser"); - goto out; - } - - /* Parse is finished, transfer contents of fragment into node */ - - /* 1. empty this node */ - exc = dom_node_get_first_child(el, &child); - if (exc != DOM_NO_ERR) goto out; - while (child != NULL) { - struct dom_node *cref; - exc = dom_node_remove_child(el, child, &cref); - if (exc != DOM_NO_ERR) goto out; -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(child); - child = NULL; -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(cref); - exc = dom_node_get_first_child(el, &child); - if (exc != DOM_NO_ERR) goto out; - } - - /* 2. the first child in the fragment will be an HTML element - * because that's how hubbub works, walk through that to the body - * element hubbub will have created, we want to migrate that element's - * children into ourself. - */ - exc = dom_node_get_first_child(fragment, &html); - if (exc != DOM_NO_ERR) goto out; - - /* We can then ask that HTML element to give us its body */ - exc = dom_element_get_elements_by_tag_name(html, corestring_dom_BODY, &bodies); - if (exc != DOM_NO_ERR) goto out; - - /* And now we can get the body which will be the zeroth body */ - exc = dom_nodelist_item(bodies, 0, &body); - if (exc != DOM_NO_ERR) goto out; - - /* 3. Migrate the children */ - exc = dom_node_get_first_child(body, &child); - if (exc != DOM_NO_ERR) goto out; - while (child != NULL) { - struct dom_node *cref; - exc = dom_node_remove_child(body, child, &cref); - if (exc != DOM_NO_ERR) goto out; -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(cref); - exc = dom_node_append_child(el, child, &cref); - if (exc != DOM_NO_ERR) goto out; -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(cref); -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(child); - child = NULL; - exc = dom_node_get_first_child(body, &child); - if (exc != DOM_NO_ERR) goto out; - } -out: - if (parser != NULL) { - dom_hubbub_parser_destroy(parser); - } - if (doc != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(doc); - } - if (fragment != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(fragment); - } - if (child != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(child); - } - if (html != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(html); - } - if (bodies != NULL) { - dom_nodelist_unref(bodies); - } - if (body != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(body); - } - interpreter->changed = 1; - js_pushundefined(J); -} -#endif - -#if 0 -static void -mjs_fragment_set_property_innerText(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - mjs_fragment_set_property_textContent(J); -} -#endif - -#if 0 -static void -mjs_fragment_set_property_lang(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_string *langstr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - assert(interpreter); - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushundefined(J); - return; - } - const char *str = js_tostring(J, 1); - if (!str) { - js_error(J, "out of memory"); - return; - } - exc = dom_string_create((const uint8_t *)str, strlen(str), &langstr); - - if (exc == DOM_NO_ERR && langstr) { - exc = dom_element_set_attribute(el, corestring_dom_lang, langstr); - interpreter->changed = 1; - dom_string_unref(langstr); - } - js_pushundefined(J); -} -#endif - -#if 0 -static void -mjs_fragment_set_property_outerHtml(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - struct view_state *vs = interpreter->vs; - if (!vs) { - js_pushundefined(J); - return; - } - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushundefined(J); - return; - } - dom_node *parent = NULL; - dom_exception exc = dom_node_get_parent_node(el, &parent); - - if (exc != DOM_NO_ERR) { - js_pushundefined(J); - return; - } - size_t size; - const char *s = js_tostring(J, 1); - - if (!s) { - js_error(J, "out of memory"); - return; - } - size = strlen(s); - struct dom_node *cref = NULL; - - dom_hubbub_parser_params parse_params; - dom_hubbub_error error; - dom_hubbub_parser *parser = NULL; - struct dom_document *doc = NULL; - struct dom_document_fragment *fragment = NULL; - struct dom_node *child = NULL, *html = NULL, *body = NULL; - struct dom_nodelist *bodies = NULL; - - exc = dom_node_get_owner_document(el, &doc); - if (exc != DOM_NO_ERR) goto out; - - parse_params.enc = "UTF-8"; - parse_params.fix_enc = true; - parse_params.enable_script = false; - parse_params.msg = NULL; - parse_params.script = NULL; - parse_params.ctx = NULL; - parse_params.daf = NULL; - - error = dom_hubbub_fragment_parser_create(&parse_params, - doc, - &parser, - &fragment); - if (error != DOM_HUBBUB_OK) { - fprintf(stderr, "Unable to create fragment parser!"); - goto out; - } - - error = dom_hubbub_parser_parse_chunk(parser, (const uint8_t*)s, size); - if (error != DOM_HUBBUB_OK) { - fprintf(stderr, "Unable to parse HTML chunk"); - goto out; - } - error = dom_hubbub_parser_completed(parser); - if (error != DOM_HUBBUB_OK) { - fprintf(stderr, "Unable to complete parser"); - goto out; - } - - /* The first child in the fragment will be an HTML element - * because that's how hubbub works, walk through that to the body - * element hubbub will have created, we want to migrate that element's - * children into ourself. - */ - exc = dom_node_get_first_child(fragment, &html); - if (exc != DOM_NO_ERR) goto out; - - /* We can then ask that HTML element to give us its body */ - exc = dom_element_get_elements_by_tag_name(html, corestring_dom_BODY, &bodies); - if (exc != DOM_NO_ERR) goto out; - - /* And now we can get the body which will be the zeroth body */ - exc = dom_nodelist_item(bodies, 0, &body); - if (exc != DOM_NO_ERR) goto out; - - /* Migrate the children */ - exc = dom_node_get_first_child(body, &child); - if (exc != DOM_NO_ERR) goto out; - while (child != NULL) { - exc = dom_node_remove_child(body, child, &cref); - if (exc != DOM_NO_ERR) goto out; -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(cref); - - dom_node *spare = NULL; - exc = dom_node_insert_before(parent, child, el, &spare); - - if (exc != DOM_NO_ERR) goto out; -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(spare); -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(cref); -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(child); - child = NULL; - exc = dom_node_get_first_child(body, &child); - if (exc != DOM_NO_ERR) goto out; - } - exc = dom_node_remove_child(parent, el, &cref); - - if (exc != DOM_NO_ERR) goto out; -out: - if (parser != NULL) { - dom_hubbub_parser_destroy(parser); - } - if (doc != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(doc); - } - if (fragment != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(fragment); - } - if (child != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(child); - } - if (html != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(html); - } - if (bodies != NULL) { - dom_nodelist_unref(bodies); - } - if (body != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(body); - } - if (cref != NULL) { -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(cref); - } -#ifdef ECMASCRIPT_DEBUG -fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); -#endif - dom_node_unref(parent); - interpreter->changed = 1; - - js_pushundefined(J); -} -#endif - static void mjs_fragment_set_property_textContent(js_State *J) { @@ -2084,120 +687,6 @@ mjs_fragment_set_property_textContent(js_State *J) js_pushundefined(J); } -#if 0 -static void -mjs_fragment_set_property_title(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_string *titlestr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - assert(interpreter); - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - - if (!el) { - js_pushundefined(J); - return; - } - const char *str = js_tostring(J, 1); - - if (!str) { - js_error(J, "out of memory"); - return; - } - exc = dom_string_create((const uint8_t *)str, strlen(str), &titlestr); - - if (exc == DOM_NO_ERR && titlestr) { - exc = dom_element_set_attribute(el, corestring_dom_title, titlestr); - interpreter->changed = 1; - dom_string_unref(titlestr); - } - js_pushundefined(J); -} -#endif - -#if 0 -static void -mjs_fragment_set_property_value(js_State *J) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(mjs_getprivate_fragment(J, 0)); - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - struct view_state *vs = interpreter->vs; - struct document_view *doc_view; - struct document *doc; - struct el_form_control *fc; - struct form_state *fs; - struct link *link; - int offset, linknum; - - if (!vs) { - js_pushundefined(J); - return; - } - doc_view = vs->doc_view; - - if (!doc_view) { - js_pushundefined(J); - return; - } - doc = doc_view->document; - - if (!el) { - js_pushundefined(J); - return; - } - offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - js_pushundefined(J); - return; - } - linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - js_pushundefined(J); - return; - } - - link = &doc->links[linknum]; - fc = get_link_form_control(link); - - if (!fc) { - js_pushundefined(J); - return; - } - fs = find_form_state(doc_view, fc); - - if (!fs) { - js_pushundefined(J); - return; - } - - if (fc->type != FC_FILE) { - const char *str = js_tostring(J, 1); - char *string; - - if (!str) { - js_error(J, "!str"); - return; - } - - string = stracpy(str); - mem_free_set(&fs->value, string); - - if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) { - fs->state = strlen(fs->value); - } - } - js_pushundefined(J); -} -#endif - #if 0 // Common part of all add_child_element*() methods. static xmlpp::Element* @@ -2800,49 +1289,24 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); addmethod(J, "removeEventListener", mjs_fragment_removeEventListener, 3); addmethod(J, "toString", mjs_fragment_toString, 0); -//// addproperty(J, "attributes", mjs_fragment_get_property_attributes, NULL); -//// addproperty(J, "checked", mjs_fragment_get_property_checked, mjs_fragment_set_property_checked); 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, "classList", mjs_fragment_get_property_classList, NULL); -//// addproperty(J, "className", mjs_fragment_get_property_className, mjs_fragment_set_property_className); -// addproperty(J, "clientHeight", mjs_fragment_get_property_clientHeight, NULL); -// addproperty(J, "clientLeft", mjs_fragment_get_property_clientLeft, NULL); -// addproperty(J, "clientTop", mjs_fragment_get_property_clientTop, NULL); -// addproperty(J, "clientWidth", mjs_fragment_get_property_clientWidth, NULL); -//// addproperty(J, "dataset", mjs_fragment_get_property_dataset, NULL); -//// addproperty(J, "dir", mjs_fragment_get_property_dir, mjs_fragment_set_property_dir); addproperty(J, "firstChild", mjs_fragment_get_property_firstChild, NULL); addproperty(J, "firstElementChild", mjs_fragment_get_property_firstElementChild, NULL); -//// addproperty(J, "href", mjs_fragment_get_property_href, mjs_fragment_set_property_href); - addproperty(J, "id", mjs_fragment_get_property_id, mjs_fragment_set_property_id); -//// addproperty(J, "innerHTML", mjs_fragment_get_property_innerHtml, mjs_fragment_set_property_innerHtml); -//// addproperty(J, "innerText", mjs_fragment_get_property_innerHtml, mjs_fragment_set_property_innerText); -//// addproperty(J, "lang", mjs_fragment_get_property_lang, mjs_fragment_set_property_lang); 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, "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, NULL); -// addproperty(J, "offsetHeight", mjs_fragment_get_property_offsetHeight, NULL); -// addproperty(J, "offsetLeft", mjs_fragment_get_property_offsetLeft, NULL); -//// addproperty(J, "offsetParent", mjs_fragment_get_property_offsetParent, NULL); -// addproperty(J, "offsetTop", mjs_fragment_get_property_offsetTop, NULL); -// addproperty(J, "offsetWidth", mjs_fragment_get_property_offsetWidth, NULL); -//// addproperty(J, "outerHTML", mjs_fragment_get_property_outerHtml, mjs_fragment_set_property_outerHtml); 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, "previousElementSibling", mjs_fragment_get_property_previousElementSibling, NULL); addproperty(J, "previousSibling", mjs_fragment_get_property_previousSibling, NULL); -//// addproperty(J, "style", mjs_fragment_get_property_style, NULL); -//// addproperty(J, "tagName", mjs_fragment_get_property_tagName, NULL); addproperty(J, "textContent", mjs_fragment_get_property_textContent, mjs_fragment_set_property_textContent); -//// addproperty(J, "title", mjs_fragment_get_property_title, mjs_fragment_set_property_title); -//// addproperty(J, "value", mjs_fragment_get_property_value, mjs_fragment_set_property_value); } }