diff --git a/src/ecmascript/quickjs/fragment.c b/src/ecmascript/quickjs/fragment.c index e80e2b39..3af6b1eb 100644 --- a/src/ecmascript/quickjs/fragment.c +++ b/src/ecmascript/quickjs/fragment.c @@ -90,177 +90,6 @@ js_getopaque_fragment(JSValueConst obj, JSClassID class_id) return res->node; } -#if 0 -static JSValue -js_fragment_get_property_attributes(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - dom_namednodemap *attrs = NULL; - dom_exception exc; - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - exc = dom_node_get_attributes(el, &attrs); - - if (exc != DOM_NO_ERR || !attrs) { - //dom_node_unref(el); - return JS_NULL; - } - JSValue rr = getAttributes(ctx, attrs); - JS_FreeValue(ctx, rr); - //dom_node_unref(el); - - RETURN_JS(rr); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_checked(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - 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) { - return JS_UNDEFINED; - } - doc_view = vs->doc_view; - - if (!doc_view) { - return JS_UNDEFINED; - } - doc = doc_view->document; - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - - offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - - link = &doc->links[linknum]; - fc = get_link_form_control(link); - - if (!fc) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - fs = find_form_state(doc_view, fc); - - if (!fs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - //dom_node_unref(el); - return JS_NULL; /* detached */ - } - //dom_node_unref(el); - - return JS_NewBool(ctx, fs->state); -} -#endif - -#if 0 -static JSValue -js_fragment_set_property_checked(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - 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) { - return JS_UNDEFINED; - } - doc_view = vs->doc_view; - - if (!doc_view) { - return JS_UNDEFINED; - } - doc = doc_view->document; - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - - offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - - link = &doc->links[linknum]; - fc = get_link_form_control(link); - - if (!fc) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - fs = find_form_state(doc_view, fc); - - if (!fs) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - - if (fc->type != FC_CHECKBOX && fc->type != FC_RADIO) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - fs->state = JS_ToBool(ctx, val); - //dom_node_unref(el); - - return JS_UNDEFINED; -} -#endif static JSValue js_fragment_get_property_children(JSContext *ctx, JSValueConst this_val) @@ -348,258 +177,7 @@ js_fragment_get_property_childNodes(JSContext *ctx, JSValueConst this_val) RETURN_JS(rr); } -#if 0 -static JSValue -js_fragment_get_property_classList(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - dom_element *el = (dom_element *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - dom_tokenlist *tl = NULL; - dom_exception exc = dom_tokenlist_create(el, corestring_dom_class, &tl); - //dom_node_unref(el); - - if (exc != DOM_NO_ERR || !tl) { - return JS_NULL; - } - - return getTokenlist(ctx, tl); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_className(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - JSValue r; - - dom_html_element *el = (dom_html_element *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - dom_string *classstr = NULL; - dom_exception exc; - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - - exc = dom_html_element_get_class_name(el, &classstr); - - if (exc != DOM_NO_ERR) { - //dom_node_unref(el); - return JS_NULL; - } - if (!classstr) { - r = JS_NewString(ctx, ""); - } else { - r = JS_NewStringLen(ctx, dom_string_data(classstr), dom_string_length(classstr)); - dom_string_unref(classstr); - } - //dom_node_unref(el); - - RETURN_JS(r); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_clientHeight(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - 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) { - return JS_NewInt32(ctx, 0); - } - ses = doc_view->session; - - if (!ses) { - return JS_NewInt32(ctx, 0); - } - dom_string *tag_name = NULL; - dom_exception exc = dom_node_get_node_name(el, &tag_name); - - if (exc != DOM_NO_ERR || !tag_name) { - return JS_NewInt32(ctx, 0); - } - 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; - return JS_NewInt32(ctx, height); - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - return JS_NewInt32(ctx, 0); - } - struct node_rect *rect = get_element_rect(document, offset); - - if (!rect) { - return JS_NewInt32(ctx, 0); - } - int dy = int_max(0, (rect->y1 + 1 - rect->y0) * ses->tab->term->cell_height); - - return JS_NewInt32(ctx, dy); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_clientLeft(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - return JS_NewInt32(ctx, 0); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_clientTop(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - return JS_NewInt32(ctx, 0); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_clientWidth(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - 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) { - return JS_NewInt32(ctx, 0); - } - ses = doc_view->session; - - if (!ses) { - return JS_NewInt32(ctx, 0); - } - dom_string *tag_name = NULL; - dom_exception exc = dom_node_get_node_name(el, &tag_name); - - if (exc != DOM_NO_ERR || !tag_name) { - return JS_NewInt32(ctx, 0); - } - 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; - return JS_NewInt32(ctx, width); - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - return JS_NewInt32(ctx, 0); - } - struct node_rect *rect = get_element_rect(document, offset); - - if (!rect) { - return JS_NewInt32(ctx, 0); - } - int dx = int_max(0, (rect->x1 + 1 - rect->x0) * ses->tab->term->cell_width); - - return JS_NewInt32(ctx, dx); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_dataset(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - dom_element *el = (dom_element *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - return getDataset(ctx, el); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_dir(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - JSValue r; - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - dom_string *dir = NULL; - dom_exception exc; - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - exc = dom_element_get_attribute(el, corestring_dom_dir, &dir); - - if (exc != DOM_NO_ERR) { - //dom_node_unref(el); - return JS_NULL; - } - if (!dir) { - r = JS_NewString(ctx, ""); - } else { - if (strcmp(dom_string_data(dir), "auto") && strcmp(dom_string_data(dir), "ltr") && strcmp(dom_string_data(dir), "rtl")) { - r = JS_NewString(ctx, ""); - } else { - r = JS_NewStringLen(ctx, dom_string_data(dir), dom_string_length(dir)); - } - dom_string_unref(dir); - } - //dom_node_unref(el); - - RETURN_JS(r); -} -#endif static JSValue js_fragment_get_property_firstChild(JSContext *ctx, JSValueConst this_val) @@ -695,111 +273,6 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); return JS_NULL; } -#if 0 -static JSValue -js_fragment_get_property_href(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - dom_string *href = NULL; - dom_exception exc; - JSValue r; - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - exc = dom_element_get_attribute(el, corestring_dom_href, &href); - - if (exc != DOM_NO_ERR) { - //dom_node_unref(el); - return JS_NULL; - } - if (!href) { - r = JS_NewString(ctx, ""); - } else { - r = JS_NewStringLen(ctx, dom_string_data(href), dom_string_length(href)); - dom_string_unref(href); - } - //dom_node_unref(el); - - RETURN_JS(r); -} -#endif - -static JSValue -js_fragment_get_property_id(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - dom_string *id = NULL; - dom_exception exc; - JSValue r; - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - exc = dom_element_get_attribute(el, corestring_dom_id, &id); - - if (exc != DOM_NO_ERR) { - //dom_node_unref(el); - return JS_NULL; - } - if (!id) { - r = JS_NewString(ctx, ""); - } else { - r = JS_NewStringLen(ctx, dom_string_data(id), dom_string_length(id)); - dom_string_unref(id); - } - //dom_node_unref(el); - - RETURN_JS(r); -} - -#if 0 -static JSValue -js_fragment_get_property_lang(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - dom_string *lang = NULL; - dom_exception exc; - JSValue r; - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - exc = dom_element_get_attribute(el, corestring_dom_lang, &lang); - - if (exc != DOM_NO_ERR) { - //dom_node_unref(el); - return JS_NULL; - } - if (!lang) { - r = JS_NewString(ctx, ""); - } else { - r = JS_NewStringLen(ctx, dom_string_data(lang), dom_string_length(lang)); - dom_string_unref(lang); - } - //dom_node_unref(el); - - RETURN_JS(r); -} -#endif static JSValue js_fragment_get_property_lastChild(JSContext *ctx, JSValueConst this_val) @@ -1036,7 +509,6 @@ js_fragment_get_property_nodeValue(JSContext *ctx, JSValueConst this_val) RETURN_JS(r); } -#if 0 static JSValue js_fragment_get_property_nextSibling(JSContext *ctx, JSValueConst this_val) { @@ -1068,177 +540,8 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); return rr; } -#endif -#if 0 -static JSValue -js_fragment_get_property_offsetHeight(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - return js_fragment_get_property_clientHeight(ctx, this_val); -} -#endif -#if 0 -static JSValue -js_fragment_get_property_offsetLeft(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - 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) { - return JS_NewInt32(ctx, 0); - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - return JS_NewInt32(ctx, 0); - } - struct node_rect *rect = get_element_rect(document, offset); - - if (!rect) { - return JS_NewInt32(ctx, 0); - } - ses = doc_view->session; - - if (!ses) { - return JS_NewInt32(ctx, 0); - } - dom_node *node = NULL; - dom_exception exc = dom_node_get_parent_node(el, &node); - if (exc != DOM_NO_ERR || !node) { - return JS_NewInt32(ctx, 0); - } - int offset_parent = find_offset(document->element_map_rev, node); - - if (offset_parent <= 0) { - return JS_NewInt32(ctx, 0); - } - struct node_rect *rect_parent = get_element_rect(document, offset_parent); - - if (!rect_parent) { - return JS_NewInt32(ctx, 0); - } - 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); - return JS_NewInt32(ctx, dx); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_offsetParent(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - dom_node *el = (dom_node *)js_getopaque_fragment(this_val, js_fragment_class_id); - dom_node *node = NULL; - dom_exception exc; - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - exc = dom_node_get_parent_node(el, &node); - - if (exc != DOM_NO_ERR || !node) { - //dom_node_unref(el); - return JS_NULL; - } - //dom_node_unref(el); - - return getElement(ctx, node); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_offsetTop(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - 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) { - return JS_NewInt32(ctx, 0); - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - return JS_NewInt32(ctx, 0); - } - struct node_rect *rect = get_element_rect(document, offset); - - if (!rect) { - return JS_NewInt32(ctx, 0); - } - ses = doc_view->session; - - if (!ses) { - return JS_NewInt32(ctx, 0); - } - dom_node *node = NULL; - dom_exception exc = dom_node_get_parent_node(el, &node); - if (exc != DOM_NO_ERR || !node) { - return JS_NewInt32(ctx, 0); - } - int offset_parent = find_offset(document->element_map_rev, node); - - if (offset_parent <= 0) { - return JS_NewInt32(ctx, 0); - } - struct node_rect *rect_parent = get_element_rect(document, offset_parent); - - if (!rect_parent) { - return JS_NewInt32(ctx, 0); - } - 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); - return JS_NewInt32(ctx, dy); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_offsetWidth(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - return js_fragment_get_property_clientWidth(ctx, this_val); -} -#endif static JSValue js_fragment_get_property_ownerDocument(JSContext *ctx, JSValueConst this_val) @@ -1315,6 +618,7 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); return rr; } +#if 0 static JSValue js_fragment_get_property_previousElementSibling(JSContext *ctx, JSValueConst this_val) { @@ -1365,6 +669,7 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); return JS_NULL; } +#endif static JSValue js_fragment_get_property_previousSibling(JSContext *ctx, JSValueConst this_val) @@ -1397,217 +702,6 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); return rr; } -#if 0 -static JSValue -js_fragment_get_property_style(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - - return getStyle(ctx, el); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_tagName(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - JSValue r; - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - dom_string *tag_name = NULL; - dom_exception exc = dom_node_get_node_name(el, &tag_name); - - if (exc != DOM_NO_ERR || !tag_name) { - //dom_node_unref(el); - return JS_NULL; - } - r = JS_NewStringLen(ctx, dom_string_data(tag_name), dom_string_length(tag_name)); - dom_string_unref(tag_name); - //dom_node_unref(el); - - RETURN_JS(r); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_title(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - dom_string *title = NULL; - dom_exception exc; - JSValue r; - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - exc = dom_element_get_attribute(el, corestring_dom_title, &title); - - if (exc != DOM_NO_ERR) { - //dom_node_unref(el); - return JS_NULL; - } - if (!title) { - r = JS_NewString(ctx, ""); - } else { - r = JS_NewStringLen(ctx, dom_string_data(title), dom_string_length(title)); - dom_string_unref(title); - } - //dom_node_unref(el); - - RETURN_JS(r); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_value(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - JSValue r; - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - 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) { - return JS_UNDEFINED; - } - doc_view = vs->doc_view; - - if (!doc_view) { - return JS_UNDEFINED; - } - doc = doc_view->document; - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - - link = &doc->links[linknum]; - fc = get_link_form_control(link); - - if (!fc) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - fs = find_form_state(doc_view, fc); - - if (!fs) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - r = JS_NewString(ctx, fs->value); - //dom_node_unref(el); - - RETURN_JS(r); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_innerHtml(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - struct string buf; - - if (!init_string(&buf)) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - ecmascript_walk_tree(&buf, el, true, false); - JSValue ret = JS_NewStringLen(ctx, buf.source, buf.length); - done_string(&buf); - //dom_node_unref(el); - - RETURN_JS(ret); -} -#endif - -#if 0 -static JSValue -js_fragment_get_property_outerHtml(JSContext *ctx, JSValueConst this_val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_NULL; - } - //dom_node_ref(el); - struct string buf; - - if (!init_string(&buf)) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - ecmascript_walk_tree(&buf, el, false, false); - JSValue ret = JS_NewStringLen(ctx, buf.source, buf.length); - done_string(&buf); - //dom_node_unref(el); - - RETURN_JS(ret); -} -#endif static JSValue js_fragment_get_property_textContent(JSContext *ctx, JSValueConst this_val) @@ -1637,570 +731,6 @@ js_fragment_get_property_textContent(JSContext *ctx, JSValueConst this_val) RETURN_JS(ret); } -#if 0 -static JSValue -js_fragment_set_property_className(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - REF_JS(val); - dom_string *classstr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - assert(interpreter); - dom_html_element *el = (dom_html_element *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - size_t len; - const char *str = JS_ToCStringLen(ctx, &len, val); - - if (!str) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - exc = dom_string_create((const uint8_t *)str, len, &classstr); - - if (exc == DOM_NO_ERR && classstr) { - exc = dom_html_element_set_class_name(el, classstr); - interpreter->changed = 1; - dom_string_unref(classstr); - } - JS_FreeCString(ctx, str); - //dom_node_unref(el); - - return JS_UNDEFINED; -} -#endif - -#if 0 -static JSValue -js_fragment_set_property_dir(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - REF_JS(val); - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - assert(interpreter); - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - size_t len; - const char *str = JS_ToCStringLen(ctx, &len, val); - - if (!str) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - if (!strcmp(str, "ltr") || !strcmp(str, "rtl") || !strcmp(str, "auto")) { - dom_string *dir = NULL; - exc = dom_string_create((const uint8_t *)str, len, &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_FreeCString(ctx, str); - //dom_node_unref(el); - - return JS_UNDEFINED; -} -#endif - -#if 0 -static JSValue -js_fragment_set_property_href(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - REF_JS(val); - dom_string *hrefstr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - assert(interpreter); - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - size_t len; - const char *str = JS_ToCStringLen(ctx, &len, val); - - if (!str) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - exc = dom_string_create((const uint8_t *)str, len, &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_FreeCString(ctx, str); - //dom_node_unref(el); - - return JS_UNDEFINED; -} -#endif - -static JSValue -js_fragment_set_property_id(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - REF_JS(val); - dom_string *idstr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - assert(interpreter); - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - size_t len; - const char *str = JS_ToCStringLen(ctx, &len, val); - - if (!str) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - exc = dom_string_create((const uint8_t *)str, len, &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_FreeCString(ctx, str); - //dom_node_unref(el); - - return JS_UNDEFINED; -} - -#if 0 -static JSValue -js_fragment_set_property_innerHtml(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - REF_JS(val); - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - - size_t size; - const char *s = JS_ToCStringLen(ctx, &size, val); - - if (!s) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - 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, 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; - } - - /* 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); - } - JS_FreeCString(ctx, s); - interpreter->changed = 1; - //dom_node_unref(el); - - return JS_UNDEFINED; -} -#endif - -#if 0 -static JSValue -js_fragment_set_property_innerText(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - return js_fragment_set_property_textContent(ctx, this_val, val); -} -#endif - -#if 0 -static JSValue -js_fragment_set_property_lang(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - REF_JS(val); - dom_string *langstr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - assert(interpreter); - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - - size_t len; - const char *str = JS_ToCStringLen(ctx, &len, val); - - if (!str) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - exc = dom_string_create((const uint8_t *)str, len, &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_FreeCString(ctx, str); - //dom_node_unref(el); - - return JS_UNDEFINED; -} -#endif - -#if 0 -static JSValue -js_fragment_set_property_outerHtml(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - REF_JS(val); - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - struct view_state *vs = interpreter->vs; - if (!vs) { - return JS_UNDEFINED; - } - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - dom_node *parent = NULL; - dom_exception exc = dom_node_get_parent_node(el, &parent); - - if (exc != DOM_NO_ERR) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - size_t size; - const char *s = JS_ToCStringLen(ctx, &size, val); - - if (!s) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - 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); - JS_FreeCString(ctx, s); - interpreter->changed = 1; - //dom_node_unref(el); - - return JS_UNDEFINED; -} -#endif static JSValue js_fragment_set_property_textContent(JSContext *ctx, JSValueConst this_val, JSValue val) @@ -2239,132 +769,6 @@ js_fragment_set_property_textContent(JSContext *ctx, JSValueConst this_val, JSVa return JS_UNDEFINED; } -#if 0 -static JSValue -js_fragment_set_property_title(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - REF_JS(val); - dom_string *titlestr = NULL; - dom_exception exc; - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - assert(interpreter); - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - size_t len; - const char *str = JS_ToCStringLen(ctx, &len, val); - - if (!str) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - exc = dom_string_create((const uint8_t *)str, len, &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_FreeCString(ctx, str); - //dom_node_unref(el); - - return JS_UNDEFINED; -} -#endif - -#if 0 -static JSValue -js_fragment_set_property_value(JSContext *ctx, JSValueConst this_val, JSValue val) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - REF_JS(this_val); - - dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - 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) { - return JS_UNDEFINED; - } - doc_view = vs->doc_view; - - if (!doc_view) { - return JS_UNDEFINED; - } - doc = doc_view->document; - - if (!el) { - return JS_UNDEFINED; - } - //dom_node_ref(el); - offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - - link = &doc->links[linknum]; - fc = get_link_form_control(link); - - if (!fc) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - fs = find_form_state(doc_view, fc); - - if (!fs) { - //dom_node_unref(el); - return JS_UNDEFINED; - } - - if (fc->type != FC_FILE) { - const char *str; - char *string; - size_t len; - - str = JS_ToCStringLen(ctx, &len, val); - - if (!str) { - //dom_node_unref(el); - return JS_EXCEPTION; - } - - string = stracpy(str); - JS_FreeCString(ctx, str); - - mem_free_set(&fs->value, string); - - if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) { - fs->state = strlen(fs->value); - } - } - //dom_node_unref(el); - - return JS_UNDEFINED; -} -#endif #if 0 // Common part of all add_child_element*() methods. @@ -2706,7 +1110,6 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); } #endif - static JSValue js_fragment_contains(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { @@ -3070,49 +1473,24 @@ js_fragment_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon } static const JSCFunctionListEntry js_fragment_proto_funcs[] = { -//// JS_CGETSET_DEF("attributes", js_fragment_get_property_attributes, NULL), -//// JS_CGETSET_DEF("checked", js_fragment_get_property_checked, js_fragment_set_property_checked), JS_CGETSET_DEF("children", js_fragment_get_property_children, NULL), JS_CGETSET_DEF("childElementCount", js_fragment_get_property_childElementCount, NULL), JS_CGETSET_DEF("childNodes", js_fragment_get_property_childNodes, NULL), -//// JS_CGETSET_DEF("classList", js_fragment_get_property_classList, NULL), -//// JS_CGETSET_DEF("className", js_fragment_get_property_className, js_fragment_set_property_className), -// JS_CGETSET_DEF("clientHeight", js_fragment_get_property_clientHeight, NULL), -// JS_CGETSET_DEF("clientLeft", js_fragment_get_property_clientLeft, NULL), -// JS_CGETSET_DEF("clientTop", js_fragment_get_property_clientTop, NULL), -// JS_CGETSET_DEF("clientWidth", js_fragment_get_property_clientWidth, NULL), -//// JS_CGETSET_DEF("dataset", js_fragment_get_property_dataset, NULL), -//// JS_CGETSET_DEF("dir", js_fragment_get_property_dir, js_fragment_set_property_dir), JS_CGETSET_DEF("firstChild", js_fragment_get_property_firstChild, NULL), JS_CGETSET_DEF("firstElementChild", js_fragment_get_property_firstElementChild, NULL), -//// JS_CGETSET_DEF("href", js_fragment_get_property_href, js_fragment_set_property_href), - JS_CGETSET_DEF("id", js_fragment_get_property_id, js_fragment_set_property_id), -//// JS_CGETSET_DEF("innerHTML", js_fragment_get_property_innerHtml, js_fragment_set_property_innerHtml), -//// JS_CGETSET_DEF("innerText", js_fragment_get_property_innerHtml, js_fragment_set_property_innerText), -//// JS_CGETSET_DEF("lang", js_fragment_get_property_lang, js_fragment_set_property_lang), JS_CGETSET_DEF("lastChild", js_fragment_get_property_lastChild, NULL), JS_CGETSET_DEF("lastElementChild", js_fragment_get_property_lastElementChild, NULL), -//// JS_CGETSET_DEF("nextElementSibling", js_fragment_get_property_nextElementSibling, NULL), -//// JS_CGETSET_DEF("nextSibling", js_fragment_get_property_nextSibling, NULL), + JS_CGETSET_DEF("nextSibling", js_fragment_get_property_nextSibling, NULL), JS_CGETSET_DEF("nodeName", js_fragment_get_property_nodeName, NULL), // Node JS_CGETSET_DEF("nodeType", js_fragment_get_property_nodeType, NULL), // Node JS_CGETSET_DEF("nodeValue", js_fragment_get_property_nodeValue, NULL), // Node -// JS_CGETSET_DEF("offsetHeight", js_fragment_get_property_offsetHeight, NULL), -// JS_CGETSET_DEF("offsetLeft", js_fragment_get_property_offsetLeft, NULL), -//// JS_CGETSET_DEF("offsetParent", js_fragment_get_property_offsetParent, NULL), -// JS_CGETSET_DEF("offsetTop", js_fragment_get_property_offsetTop, NULL), -// JS_CGETSET_DEF("offsetWidth", js_fragment_get_property_offsetWidth, NULL), -//// JS_CGETSET_DEF("outerHTML", js_fragment_get_property_outerHtml, js_fragment_set_property_outerHtml), JS_CGETSET_DEF("ownerDocument", js_fragment_get_property_ownerDocument, NULL), // Node JS_CGETSET_DEF("parentElement", js_fragment_get_property_parentElement, NULL), // Node JS_CGETSET_DEF("parentNode", js_fragment_get_property_parentNode, NULL), // Node - JS_CGETSET_DEF("previousElementSibling", js_fragment_get_property_previousElementSibling, NULL), +//// JS_CGETSET_DEF("previousElementSibling", js_fragment_get_property_previousElementSibling, NULL), JS_CGETSET_DEF("previousSibling", js_fragment_get_property_previousSibling, NULL), // Node -//// JS_CGETSET_DEF("style", js_fragment_get_property_style, NULL), -//// JS_CGETSET_DEF("tagName", js_fragment_get_property_tagName, NULL), JS_CGETSET_DEF("textContent", js_fragment_get_property_textContent, js_fragment_set_property_textContent), // Node -//// JS_CGETSET_DEF("title", js_fragment_get_property_title, js_fragment_set_property_title), -//// JS_CGETSET_DEF("value", js_fragment_get_property_value, js_fragment_set_property_value), + JS_CFUNC_DEF("addEventListener", 3, js_fragment_addEventListener), JS_CFUNC_DEF("appendChild", 1, js_fragment_appendChild), // Node JS_CFUNC_DEF("cloneNode", 1, js_fragment_cloneNode), // Node