From 3490d8dfe93eb30132123e6bc635f72dc86bd951 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 12 Sep 2024 16:32:24 +0200 Subject: [PATCH] [spidermonkey] cleanup in fragment --- src/ecmascript/spidermonkey/fragment.cpp | 2293 +--------------------- 1 file changed, 6 insertions(+), 2287 deletions(-) diff --git a/src/ecmascript/spidermonkey/fragment.cpp b/src/ecmascript/spidermonkey/fragment.cpp index a6e41ae6e..d3f213054 100644 --- a/src/ecmascript/spidermonkey/fragment.cpp +++ b/src/ecmascript/spidermonkey/fragment.cpp @@ -70,60 +70,25 @@ #include #include -//static bool fragment_get_property_attributes(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_checked(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_checked(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_children(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_childElementCount(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_childNodes(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_classList(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_className(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_className(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_dataset(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_clientHeight(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_clientLeft(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_clientTop(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_clientWidth(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_firstChild(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_firstElementChild(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp); -static bool fragment_get_property_id(JSContext *ctx, unsigned int argc, JS::Value *vp); -static bool fragment_set_property_id(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_innerText(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_lang(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_lang(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_lastChild(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_lastElementChild(JSContext *ctx, unsigned int argc, JS::Value *vp); //static bool fragment_get_property_nextElementSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); +static bool fragment_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_nodeName(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_nodeType(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_nodeValue(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_offsetHeight(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_offsetLeft(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_offsetParent(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_offsetTop(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_offsetWidth(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_ownerDocument(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_parentElement(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_parentNode(JSContext *ctx, unsigned int argc, JS::Value *vp); -static bool fragment_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); +//static bool fragment_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_previousSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_style(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_tagName(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool fragment_set_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_get_property_value(JSContext *ctx, unsigned int argc, JS::Value *vp); -//static bool fragment_set_property_value(JSContext *ctx, unsigned int argc, JS::Value *vp); struct fragment_listener { LIST_HEAD_EL(struct fragment_listener); @@ -165,49 +130,23 @@ JSClass fragment_class = { }; JSPropertySpec fragment_props[] = { -//// JS_PSG("attributes", fragment_get_property_attributes, JSPROP_ENUMERATE), -//// JS_PSGS("checked", fragment_get_property_checked, fragment_set_property_checked, JSPROP_ENUMERATE), JS_PSG("children", fragment_get_property_children, JSPROP_ENUMERATE), JS_PSG("childElementCount", fragment_get_property_childElementCount, JSPROP_ENUMERATE), JS_PSG("childNodes", fragment_get_property_childNodes, JSPROP_ENUMERATE), -//// JS_PSG("classList", fragment_get_property_classList, JSPROP_ENUMERATE), -//// JS_PSGS("className", fragment_get_property_className, fragment_set_property_className, JSPROP_ENUMERATE), -// JS_PSG("clientHeight", fragment_get_property_clientHeight, JSPROP_ENUMERATE), -// JS_PSG("clientLeft", fragment_get_property_clientLeft, JSPROP_ENUMERATE), -// JS_PSG("clientTop", fragment_get_property_clientTop, JSPROP_ENUMERATE), -// JS_PSG("clientWidth", fragment_get_property_clientWidth, JSPROP_ENUMERATE), -//// JS_PSG("dataset", fragment_get_property_dataset, JSPROP_ENUMERATE), -//// JS_PSGS("dir", fragment_get_property_dir, fragment_set_property_dir, JSPROP_ENUMERATE), JS_PSG("firstChild", fragment_get_property_firstChild, JSPROP_ENUMERATE), JS_PSG("firstElementChild", fragment_get_property_firstElementChild, JSPROP_ENUMERATE), -//// JS_PSGS("href", fragment_get_property_href, fragment_set_property_href, JSPROP_ENUMERATE), - JS_PSGS("id", fragment_get_property_id, fragment_set_property_id, JSPROP_ENUMERATE), -//// JS_PSGS("innerHTML", fragment_get_property_innerHtml, fragment_set_property_innerHtml, JSPROP_ENUMERATE), -//// JS_PSGS("innerText", fragment_get_property_innerHtml, fragment_set_property_innerText, JSPROP_ENUMERATE), -//// JS_PSGS("lang", fragment_get_property_lang, fragment_set_property_lang, JSPROP_ENUMERATE), JS_PSG("lastChild", fragment_get_property_lastChild, JSPROP_ENUMERATE), JS_PSG("lastElementChild", fragment_get_property_lastElementChild, JSPROP_ENUMERATE), -//// JS_PSG("nextElementSibling", fragment_get_property_nextElementSibling, JSPROP_ENUMERATE), -//// JS_PSG("nextSibling", fragment_get_property_nextSibling, JSPROP_ENUMERATE), + JS_PSG("nextSibling", fragment_get_property_nextSibling, JSPROP_ENUMERATE), JS_PSG("nodeName", fragment_get_property_nodeName, JSPROP_ENUMERATE), JS_PSG("nodeType", fragment_get_property_nodeType, JSPROP_ENUMERATE), JS_PSG("nodeValue", fragment_get_property_nodeValue, JSPROP_ENUMERATE), -// JS_PSG("offsetHeight", fragment_get_property_offsetHeight, JSPROP_ENUMERATE), -// JS_PSG("offsetLeft", fragment_get_property_offsetLeft, JSPROP_ENUMERATE), -//// JS_PSG("offsetParent", fragment_get_property_offsetParent, JSPROP_ENUMERATE), -// JS_PSG("offsetTop", fragment_get_property_offsetTop, JSPROP_ENUMERATE), -// JS_PSG("offsetWidth", fragment_get_property_offsetWidth, JSPROP_ENUMERATE), -//// JS_PSGS("outerHTML", fragment_get_property_outerHtml, fragment_set_property_outerHtml, JSPROP_ENUMERATE), JS_PSG("ownerDocument", fragment_get_property_ownerDocument, JSPROP_ENUMERATE), JS_PSG("parentElement", fragment_get_property_parentElement, JSPROP_ENUMERATE), JS_PSG("parentNode", fragment_get_property_parentNode, JSPROP_ENUMERATE), - JS_PSG("previousElementSibling", fragment_get_property_previousElementSibling, JSPROP_ENUMERATE), +//// JS_PSG("previousElementSibling", fragment_get_property_previousElementSibling, JSPROP_ENUMERATE), JS_PSG("previousSibling", fragment_get_property_previousSibling, JSPROP_ENUMERATE), -//// JS_PSG("style", fragment_get_property_style, JSPROP_ENUMERATE), -//// JS_PSG("tagName", fragment_get_property_tagName, JSPROP_ENUMERATE), JS_PSGS("textContent", fragment_get_property_textContent, fragment_set_property_textContent, JSPROP_ENUMERATE), -//// JS_PSGS("title", fragment_get_property_title, fragment_set_property_title, JSPROP_ENUMERATE), -//// JS_PSGS("value", fragment_get_property_value, fragment_set_property_value, JSPROP_ENUMERATE), JS_PS_END }; @@ -245,137 +184,6 @@ static void fragment_finalize(JS::GCContext *op, JSObject *obj) } } -#if 0 -static bool -fragment_get_property_attributes(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - dom_namednodemap *attrs = NULL; - dom_exception exc; - - if (!el) { - args.rval().setNull(); - return true; - } - exc = dom_node_get_attributes(el, &attrs); - - if (exc != DOM_NO_ERR || !attrs) { - args.rval().setNull(); - return true; - } - JSObject *obj = getAttributes(ctx, attrs); - args.rval().setObject(*obj); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_checked(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - struct view_state *vs = interpreter->vs; - - args.rval().setUndefined(); - - if (!vs) { - return true; - } - - struct document_view *doc_view = vs->doc_view; - - if (!doc_view) { - return true; - } - - struct document *doc = doc_view->document; - - if (!doc) { - return true; - } - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - int offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - return true; - } - - int linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - return true; - } - struct link *link = &doc->links[linknum]; - struct el_form_control *fc = get_link_form_control(link); - - if (!fc) { - return true; - } - struct form_state *fs = find_form_state(doc_view, fc); - - if (!fs) { - return true; - } - args.rval().setBoolean(fs->state); - - return true; -} -#endif static bool fragment_get_property_children(JSContext *ctx, unsigned int argc, JS::Value *vp) @@ -556,450 +364,6 @@ fragment_get_property_childNodes(JSContext *ctx, unsigned int argc, JS::Value *v return true; } -#if 0 -static bool -fragment_get_property_classList(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - dom_element *el = (dom_element *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - dom_tokenlist *tl = NULL; - dom_exception exc = dom_tokenlist_create(el, corestring_dom_class, &tl); - - if (exc != DOM_NO_ERR || !tl) { - args.rval().setNull(); - return true; - } - JSObject *res = getTokenlist(ctx, tl); - args.rval().setObject(*res); - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_className(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_html_element *el = (dom_html_element *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - dom_string *classstr = NULL; - dom_exception exc; - - if (!el) { - args.rval().setNull(); - return true; - } - exc = dom_html_element_get_class_name(el, &classstr); - - if (exc != DOM_NO_ERR) { - args.rval().setNull(); - return true; - } - if (!classstr) { - args.rval().setString(JS_NewStringCopyZ(ctx, "")); - } else { - args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(classstr))); - dom_string_unref(classstr); - } - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_dataset(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - JSObject *obj = getDataset(ctx, el); - args.rval().setObject(*obj); - - return true; -} -#endif - - -#if 0 // it does not work yet -static bool -fragment_get_property_clientHeight(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - vs = interpreter->vs; - - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses; - - if (!document) { - args.rval().setInt32(0); - return true; - } - ses = doc_view->session; - - if (!ses) { - args.rval().setInt32(0); - return true; - } - dom_string *tag_name = NULL; - dom_exception exc = dom_node_get_node_name(el, &tag_name); - - if (exc != DOM_NO_ERR || !tag_name) { - args.rval().setInt32(0); - return true; - } - 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; - args.rval().setInt32(height); - return true; - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - args.rval().setInt32(ses->tab->term->cell_height); - return true; - } - struct node_rect *rect = get_fragment_rect(document, offset); - - if (!rect) { - args.rval().setInt32(ses->tab->term->cell_height); - return true; - } - int dy = int_max(0, (rect->y1 + 1 - rect->y0) * ses->tab->term->cell_height); - args.rval().setInt32(dy); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_clientLeft(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - args.rval().setInt32(0); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_clientTop(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - args.rval().setInt32(0); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_clientWidth(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - vs = interpreter->vs; - - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses; - - if (!document) { - args.rval().setInt32(0); - return true; - } - ses = doc_view->session; - - if (!ses) { - args.rval().setInt32(0); - return true; - } - dom_string *tag_name = NULL; - dom_exception exc = dom_node_get_node_name(el, &tag_name); - - if (exc != DOM_NO_ERR || !tag_name) { - args.rval().setInt32(0); - return true; - } - bool root = (!strcmp(dom_string_data(tag_name), "BODY") || !strcmp(dom_string_data(tag_name), "HTML") || !strcmp(dom_string_data(tag_name), "DIV")); - - if (root) { - int width = doc_view->box.width * ses->tab->term->cell_width; - args.rval().setInt32(width); - dom_string_unref(tag_name); - return true; - } - bool pre = (!strcmp(dom_string_data(tag_name), "PRE")); - dom_string_unref(tag_name); - - if (pre) { - dom_string *id = NULL; - exc = dom_element_get_attribute(el, corestring_dom_id, &id); - - if (exc == DOM_NO_ERR && id != NULL) { - if (!strcmp(dom_string_data(id), "cursor")) { - args.rval().setInt32(ses->tab->term->cell_width); - dom_string_unref(id); - return true; - } - if (!strcmp(dom_string_data(id), "console")) { - args.rval().setInt32(doc_view->box.width * ses->tab->term->cell_width); - dom_string_unref(id); - return true; - } - dom_string_unref(id); - } - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - args.rval().setInt32(ses->tab->term->cell_width); - return true; - } - struct node_rect *rect = get_fragment_rect(document, offset); - - if (!rect) { - args.rval().setInt32(ses->tab->term->cell_width); - return true; - } - int dx = int_max(0, (rect->x1 + 1 - rect->x0) * ses->tab->term->cell_width); - args.rval().setInt32(dx); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - dom_string *dir = NULL; - dom_exception exc; - - if (!el) { - args.rval().setNull(); - return true; - } - exc = dom_element_get_attribute(el, corestring_dom_dir, &dir); - - if (exc != DOM_NO_ERR) { - args.rval().setNull(); - return true; - } - if (!dir) { - args.rval().setString(JS_NewStringCopyZ(ctx, "")); - } else { - if (strcmp(dom_string_data(dir), "auto") && strcmp(dom_string_data(dir), "ltr") && strcmp(dom_string_data(dir), "rtl")) { - args.rval().setString(JS_NewStringCopyZ(ctx, "")); - } else { - args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(dir))); - } - dom_string_unref(dir); - } - - return true; -} -#endif static bool fragment_get_property_firstChild(JSContext *ctx, unsigned int argc, JS::Value *vp) @@ -1152,198 +516,6 @@ fragment_get_property_firstElementChild(JSContext *ctx, unsigned int argc, JS::V return true; } -#if 0 -static bool -fragment_get_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - dom_string *href = NULL; - dom_exception exc; - - if (!el) { - args.rval().setNull(); - return true; - } - exc = dom_element_get_attribute(el, corestring_dom_href, &href); - - if (exc != DOM_NO_ERR) { - args.rval().setNull(); - return true; - } - if (!href) { - args.rval().setString(JS_NewStringCopyZ(ctx, "")); - } else { - args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(href))); - dom_string_unref(href); - } - - return true; -} -#endif - -static bool -fragment_get_property_id(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - dom_string *id = NULL; - dom_exception exc; - - if (!el) { - args.rval().setNull(); - return true; - } - exc = dom_element_get_attribute(el, corestring_dom_id, &id); - - if (exc != DOM_NO_ERR) { - args.rval().setNull(); - return true; - } - if (!id) { - args.rval().setString(JS_NewStringCopyZ(ctx, "")); - } else { - args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(id))); - dom_string_unref(id); - } - - return true; -} - -#if 0 -static bool -fragment_get_property_lang(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - dom_string *lang = NULL; - dom_exception exc; - - if (!el) { - args.rval().setNull(); - return true; - } - exc = dom_element_get_attribute(el, corestring_dom_lang, &lang); - - if (exc != DOM_NO_ERR) { - args.rval().setNull(); - return true; - } - if (!lang) { - args.rval().setString(JS_NewStringCopyZ(ctx, "")); - } else { - args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(lang))); - dom_string_unref(lang); - } - - return true; -} -#endif static bool fragment_get_property_lastChild(JSContext *ctx, unsigned int argc, JS::Value *vp) @@ -1750,7 +922,6 @@ fragment_get_property_nodeValue(JSContext *ctx, unsigned int argc, JS::Value *vp return true; } -#if 0 static bool fragment_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value *vp) { @@ -1810,283 +981,6 @@ fragment_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value * return true; } -#endif - -#if 0 -static bool -fragment_get_property_offsetHeight(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - return fragment_get_property_clientHeight(ctx, argc, vp); -} -#endif - -#if 0 -static bool -fragment_get_property_offsetLeft(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - vs = interpreter->vs; - - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses; - - if (!document) { - args.rval().setInt32(0); - return true; - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - args.rval().setInt32(0); - return true; - } - struct node_rect *rect = get_fragment_rect(document, offset); - - if (!rect) { - args.rval().setInt32(0); - return true; - } - ses = doc_view->session; - - if (!ses) { - args.rval().setInt32(0); - return true; - } - dom_node *node = NULL; - dom_exception exc = dom_node_get_parent_node(el, &node); - if (exc != DOM_NO_ERR || !node) { - args.rval().setInt32(0); - return true; - } - int offset_parent = find_offset(document->element_map_rev, node); - - if (offset_parent <= 0) { - args.rval().setInt32(0); - return true; - } - struct node_rect *rect_parent = get_fragment_rect(document, offset_parent); - - if (!rect_parent) { - args.rval().setInt32(0); - return true; - } - int dx = int_max(0, (rect->x0 - rect_parent->x0) * ses->tab->term->cell_width); - dom_node_unref(node); - args.rval().setInt32(dx); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_offsetParent(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - dom_node *node = NULL; - dom_exception exc; - - if (!el) { - args.rval().setNull(); - return true; - } - exc = dom_node_get_parent_node(el, &node); - - if (exc != DOM_NO_ERR || !node) { - args.rval().setNull(); - return true; - } - JSObject *elem = getElement(ctx, node); - dom_node_unref(node); - args.rval().setObject(*elem); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_offsetTop(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - vs = interpreter->vs; - - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses; - - if (!document) { - args.rval().setInt32(0); - return true; - } - int offset = find_offset(document->element_map_rev, el); - - if (offset <= 0) { - args.rval().setInt32(0); - return true; - } - struct node_rect *rect = get_fragment_rect(document, offset); - - if (!rect) { - args.rval().setInt32(0); - return true; - } - ses = doc_view->session; - - if (!ses) { - args.rval().setInt32(0); - return true; - } - dom_node *node = NULL; - dom_exception exc = dom_node_get_parent_node(el, &node); - if (exc != DOM_NO_ERR || !node) { - args.rval().setInt32(0); - return true; - } - int offset_parent = find_offset(document->element_map_rev, node); - - if (offset_parent <= 0) { - args.rval().setInt32(0); - return true; - } - struct node_rect *rect_parent = get_fragment_rect(document, offset_parent); - - if (!rect_parent) { - args.rval().setInt32(0); - return true; - } - int dy = int_max(0, (rect->y0 - rect_parent->y0) * ses->tab->term->cell_height); - dom_node_unref(node); - args.rval().setInt32(dy); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_offsetWidth(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - return fragment_get_property_clientWidth(ctx, argc, vp); -} -#endif static bool fragment_get_property_ownerDocument(JSContext *ctx, unsigned int argc, JS::Value *vp) @@ -2251,6 +1145,7 @@ fragment_get_property_parentNode(JSContext *ctx, unsigned int argc, JS::Value *v return true; } +#if 0 static bool fragment_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, JS::Value *vp) { @@ -2328,6 +1223,7 @@ fragment_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, return true; } +#endif static bool fragment_get_property_previousSibling(JSContext *ctx, unsigned int argc, JS::Value *vp) @@ -2389,359 +1285,6 @@ fragment_get_property_previousSibling(JSContext *ctx, unsigned int argc, JS::Val return true; } -#if 0 -static bool -fragment_get_property_style(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - JSObject *style = getStyle(ctx, el); - args.rval().setObject(*style); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_tagName(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - dom_string *tag_name = NULL; - dom_exception exc = dom_node_get_node_name(el, &tag_name); - - if (exc != DOM_NO_ERR || !tag_name) { - args.rval().setNull(); - return true; - } - args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(tag_name))); - dom_string_unref(tag_name); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - dom_string *title = NULL; - dom_exception exc; - - if (!el) { - args.rval().setNull(); - return true; - } - exc = dom_element_get_attribute(el, corestring_dom_title, &title); - - if (exc != DOM_NO_ERR) { - args.rval().setNull(); - return true; - } - if (!title) { - args.rval().setString(JS_NewStringCopyZ(ctx, "")); - } else { - args.rval().setString(JS_NewStringCopyZ(ctx, dom_string_data(title))); - dom_string_unref(title); - } - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_value(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - struct view_state *vs = interpreter->vs; - - args.rval().setUndefined(); - - if (!vs) { - return true; - } - - struct document_view *doc_view = vs->doc_view; - - if (!doc_view) { - return true; - } - - struct document *doc = doc_view->document; - - if (!doc) { - return true; - } - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - int offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - return true; - } - - int linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - return true; - } - struct link *link = &doc->links[linknum]; - struct el_form_control *fc = get_link_form_control(link); - - if (!fc) { - return true; - } - struct form_state *fs = find_form_state(doc_view, fc); - - if (!fs) { - return true; - } - args.rval().setString(JS_NewStringCopyZ(ctx, fs->value)); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - struct string buf; - if (!init_string(&buf)) { - args.rval().setNull(); - return false; - } - ecmascript_walk_tree(&buf, el, true, false); - args.rval().setString(JS_NewStringCopyZ(ctx, buf.source)); - done_string(&buf); - - return true; -} -#endif - -#if 0 -static bool -fragment_get_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - struct view_state *vs; - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - vs = interpreter->vs; - if (!vs) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - args.rval().setNull(); - return true; - } - struct string buf; - if (!init_string(&buf)) { - args.rval().setNull(); - return false; - } - ecmascript_walk_tree(&buf, el, false, false); - args.rval().setString(JS_NewStringCopyZ(ctx, buf.source)); - done_string(&buf); - - return true; -} -#endif - static bool fragment_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *vp) { @@ -2799,757 +1342,9 @@ fragment_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value * return true; } -#if 0 -static bool -fragment_set_property_checked(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JS::Realm *comp = js::GetContextRealm(ctx); - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - struct view_state *vs = interpreter->vs; - args.rval().setUndefined(); - - if (!vs) { - return true; - } - - struct document_view *doc_view = vs->doc_view; - - if (!doc_view) { - return true; - } - - struct document *doc = doc_view->document; - - if (!doc) { - return true; - } - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - int offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - return true; - } - - int linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - return true; - } - struct link *link = &doc->links[linknum]; - struct el_form_control *fc = get_link_form_control(link); - - if (!fc) { - return true; - } - struct form_state *fs = find_form_state(doc_view, fc); - - if (!fs) { - return true; - } - - if (fc->type != FC_CHECKBOX && fc->type != FC_RADIO) { - return true; - } - fs->state = args[0].toBoolean(); - - return true; -} -#endif - -#if 0 -static bool -fragment_set_property_className(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - args.rval().setUndefined(); - - struct view_state *vs = interpreter->vs; - if (!vs) { - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - - dom_html_element *el = (dom_html_element *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - char *str = jsval_to_string(ctx, args[0]); - - if (!str) { - return false; - } - size_t len = strlen(str); - dom_string *classstr = NULL; - dom_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); - debug_dump_xhtml(document->dom); - } - mem_free(str); - - return true; -} -#endif - -#if 0 -static bool -fragment_set_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - args.rval().setUndefined(); - - struct view_state *vs = interpreter->vs; - if (!vs) { - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - char *str = jsval_to_string(ctx, args[0]); - - if (!str) { - return false; - } - size_t len = strlen(str); - - if (!strcmp(str, "ltr") || !strcmp(str, "rtl") || !strcmp(str, "auto")) { - dom_string *dir = NULL; - dom_exception 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); - debug_dump_xhtml(document->dom); - } - } - mem_free(str); - - return true; -} -#endif - -#if 0 -static bool -fragment_set_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - args.rval().setUndefined(); - - struct view_state *vs = interpreter->vs; - if (!vs) { - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - char *str = jsval_to_string(ctx, args[0]); - - if (!str) { - return false; - } - size_t len = strlen(str); - dom_string *hrefstr = NULL; - dom_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); - debug_dump_xhtml(document->dom); - } - mem_free(str); - - return true; -} -#endif - -static bool -fragment_set_property_id(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - args.rval().setUndefined(); - - struct view_state *vs = interpreter->vs; - if (!vs) { - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - char *str = jsval_to_string(ctx, args[0]); - - if (!str) { - return false; - } - size_t len = strlen(str); - dom_string *idstr = NULL; - dom_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); - debug_dump_xhtml(document->dom); - } - mem_free(str); - - return true; -} - -#if 0 -static bool -fragment_set_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - args.rval().setUndefined(); - - struct view_state *vs = interpreter->vs; - if (!vs) { - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - char *s = jsval_to_string(ctx, args[0]); - - if (!s) { - return false; - } - size_t size = strlen(s); - - 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; - dom_node_unref(child); - child = NULL; - 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; - dom_node_unref(cref); - exc = dom_node_append_child(el, child, &cref); - if (exc != DOM_NO_ERR) goto out; - dom_node_unref(cref); - 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) { - dom_node_unref(doc); - } - if (fragment != NULL) { - dom_node_unref(fragment); - } - if (child != NULL) { - dom_node_unref(child); - } - if (html != NULL) { - dom_node_unref(html); - } - if (bodies != NULL) { - dom_nodelist_unref(bodies); - } - if (body != NULL) { - dom_node_unref(body); - } - mem_free(s); - interpreter->changed = 1; - debug_dump_xhtml(document->dom); - - return true; -} -#endif - -#if 0 -static bool -fragment_set_property_innerText(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - return fragment_set_property_textContent(ctx, argc, vp); -} -#endif - -#if 0 -static bool -fragment_set_property_lang(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - args.rval().setUndefined(); - - struct view_state *vs = interpreter->vs; - if (!vs) { - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - char *str = jsval_to_string(ctx, args[0]); - - if (!str) { - return false; - } - size_t len = strlen(str); - dom_string *langstr = NULL; - dom_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); - debug_dump_xhtml(document->dom); - } - mem_free(str); - - return true; -} -#endif - -#if 0 -static bool -fragment_set_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - - /* This can be called if @obj if not itself an instance of the - * appropriate class but has one in its prototype chain. Fail - * such calls. */ - if (!JS_InstanceOf(ctx, hobj, &fragment_class, NULL)) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - args.rval().setUndefined(); - - struct view_state *vs = interpreter->vs; - if (!vs) { - return true; - } - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - dom_node *parent = NULL; - dom_exception exc = dom_node_get_parent_node(el, &parent); - - if (exc != DOM_NO_ERR) { - return true; - } - - char *s = jsval_to_string(ctx, args[0]); - - if (!s) { - return false; - } - size_t 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; - dom_node_unref(cref); - - dom_node *spare = NULL; - exc = dom_node_insert_before(parent, child, el, &spare); - - if (exc != DOM_NO_ERR) goto out; - dom_node_unref(spare); - dom_node_unref(cref); - 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) { - dom_node_unref(doc); - } - if (fragment != NULL) { - dom_node_unref(fragment); - } - if (child != NULL) { - dom_node_unref(child); - } - if (html != NULL) { - dom_node_unref(html); - } - if (bodies != NULL) { - dom_nodelist_unref(bodies); - } - if (body != NULL) { - dom_node_unref(body); - } - if (cref != NULL) { - dom_node_unref(cref); - } - dom_node_unref(parent); - - mem_free(s); - interpreter->changed = 1; - debug_dump_xhtml(document->dom); - - return true; -} -#endif static bool fragment_set_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *vp) @@ -3669,82 +1464,6 @@ fragment_set_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp) } #endif -#if 0 -static bool -fragment_set_property_value(JSContext *ctx, unsigned int argc, JS::Value *vp) -{ -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif - JS::CallArgs args = CallArgsFromVp(argc, vp); - JS::RootedObject hobj(ctx, &args.thisv().toObject()); - - JS::Realm *comp = js::GetContextRealm(ctx); - - if (!comp) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return false; - } - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp); - struct view_state *vs = interpreter->vs; - - args.rval().setUndefined(); - - if (!vs) { - return true; - } - - struct document_view *doc_view = vs->doc_view; - - if (!doc_view) { - return true; - } - - struct document *doc = doc_view->document; - - if (!doc) { - return true; - } - dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); - - if (!el) { - return true; - } - int offset = find_offset(doc->element_map_rev, el); - - if (offset < 0) { - return true; - } - - int linknum = get_link_number_by_offset(doc, offset); - - if (linknum < 0) { - return true; - } - struct link *link = &doc->links[linknum]; - struct el_form_control *fc = get_link_form_control(link); - - if (!fc) { - return true; - } - struct form_state *fs = find_form_state(doc_view, fc); - - if (!fs) { - return true; - } - - if (fc->type != FC_FILE) { - mem_free_set(&fs->value, jsval_to_string(ctx, args[0])); - if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) { - fs->state = strlen(fs->value); - } - } - - return true; -} -#endif static bool fragment_addEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval); static bool fragment_appendChild(JSContext *ctx, unsigned int argc, JS::Value *rval);