diff --git a/src/js/spidermonkey/collection.cpp b/src/js/spidermonkey/collection.cpp index e8e1fa9bc..3afed4cae 100644 --- a/src/js/spidermonkey/collection.cpp +++ b/src/js/spidermonkey/collection.cpp @@ -30,6 +30,7 @@ #include "js/ecmascript-c.h" #include "js/spidermonkey/collection.h" #include "js/spidermonkey/element.h" +#include "js/spidermonkey/node.h" #include "intl/libintl.h" #include "main/select.h" #include "osdep/newwin.h" @@ -359,7 +360,7 @@ htmlCollection2_item2(JSContext *ctx, JS::HandleObject hobj, int idx, JS::Mutabl if (err != DOM_NO_ERR) { return true; } - JSObject *obj = getElement(ctx, node); + JSObject *obj = getNode(ctx, node); hvp.setObject(*obj); dom_node_unref(node); @@ -422,7 +423,7 @@ htmlCollection2_namedItem2(JSContext *ctx, JS::HandleObject hobj, char *str, JS: if (err == DOM_NO_ERR && val) { if (dom_string_caseless_isequal(name, val)) { - JSObject *obj = (JSObject *)getElement(ctx, element); + JSObject *obj = (JSObject *)getNode(ctx, element); hvp.setObject(*obj); dom_string_unref(val); @@ -438,7 +439,7 @@ htmlCollection2_namedItem2(JSContext *ctx, JS::HandleObject hobj, char *str, JS: if (err == DOM_NO_ERR && val) { if (dom_string_caseless_isequal(name, val)) { - JSObject *obj = (JSObject *)getElement(ctx, element); + JSObject *obj = (JSObject *)getNode(ctx, element); hvp.setObject(*obj); dom_string_unref(val); @@ -492,7 +493,7 @@ htmlCollection_set_items(JSContext *ctx, JS::HandleObject hobj, void *node) if (err != DOM_NO_ERR || !element) { continue; } - JSObject *obj = getElement(ctx, element); + JSObject *obj = getNode(ctx, element); if (!obj) { continue; diff --git a/src/js/spidermonkey/customevent.cpp b/src/js/spidermonkey/customevent.cpp index 87e41c61a..260d7b363 100644 --- a/src/js/spidermonkey/customevent.cpp +++ b/src/js/spidermonkey/customevent.cpp @@ -29,6 +29,7 @@ #include "js/spidermonkey/customevent.h" #include "js/spidermonkey/element.h" #include "js/spidermonkey/heartbeat.h" +#include "js/spidermonkey/node.h" #include "js/timer.h" #include "intl/libintl.h" #include "main/select.h" @@ -402,7 +403,7 @@ customEvent_get_property_target(JSContext *ctx, unsigned int argc, JS::Value *vp args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, target); + JSObject *obj = getNode(ctx, target); args.rval().setObject(*obj); dom_node_unref(target); diff --git a/src/js/spidermonkey/document.cpp b/src/js/spidermonkey/document.cpp index c82e1f5a8..cc22dc846 100644 --- a/src/js/spidermonkey/document.cpp +++ b/src/js/spidermonkey/document.cpp @@ -43,6 +43,7 @@ #include "js/spidermonkey/event.h" #include "js/spidermonkey/fragment.h" #include "js/spidermonkey/heartbeat.h" +#include "js/spidermonkey/node.h" #include "js/spidermonkey/nodelist.h" #include "js/spidermonkey/nodelist2.h" #include "js/spidermonkey/text.h" @@ -271,7 +272,7 @@ document_get_property_body(JSContext *ctx, unsigned int argc, JS::Value *vp) args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, body); + JSObject *obj = getNode(ctx, body); args.rval().setObject(*obj); return true; @@ -481,7 +482,7 @@ document_get_property_currentScript(JSContext *ctx, unsigned int argc, JS::Value dom_string_unref(tag_name); if (isScript) { - JSObject *obj = getElement(ctx, elem); + JSObject *obj = getNode(ctx, elem); args.rval().setObject(*obj); return true; } @@ -570,7 +571,7 @@ document_get_property_documentElement(JSContext *ctx, unsigned int argc, JS::Val args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, root); + JSObject *obj = getNode(ctx, root); args.rval().setObject(*obj); return true; @@ -1654,7 +1655,7 @@ document_createComment(JSContext *ctx, unsigned int argc, JS::Value *vp) args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, comment); + JSObject *obj = getNode(ctx, comment); args.rval().setObject(*obj); return true; @@ -1747,7 +1748,7 @@ document_createElement(JSContext *ctx, unsigned int argc, JS::Value *vp) args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, element); + JSObject *obj = getNode(ctx, element); args.rval().setObject(*obj); return true; @@ -1963,7 +1964,7 @@ document_getElementById(JSContext *ctx, unsigned int argc, JS::Value *vp) args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, element); + JSObject *obj = getNode(ctx, element); args.rval().setObject(*obj); return true; @@ -2139,7 +2140,7 @@ document_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp) if (!ret) { args.rval().setNull(); } else { - JSObject *el = getElement(ctx, ret); + JSObject *el = getNode(ctx, ret); args.rval().setObject(*el); } diff --git a/src/js/spidermonkey/element.cpp b/src/js/spidermonkey/element.cpp index 4b6a15a92..a69eaa541 100644 --- a/src/js/spidermonkey/element.cpp +++ b/src/js/spidermonkey/element.cpp @@ -39,6 +39,7 @@ #include "js/spidermonkey/element.h" #include "js/spidermonkey/heartbeat.h" #include "js/spidermonkey/keyboard.h" +#include "js/spidermonkey/node.h" #include "js/spidermonkey/nodelist.h" #include "js/spidermonkey/nodelist2.h" #include "js/spidermonkey/style.h" @@ -1048,7 +1049,7 @@ element_get_property_firstChild(JSContext *ctx, unsigned int argc, JS::Value *vp return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -1131,7 +1132,7 @@ element_get_property_firstElementChild(JSContext *ctx, unsigned int argc, JS::Va if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { dom_nodelist_unref(nodes); - JSObject *elem = getElement(ctx, child); + JSObject *elem = getNode(ctx, child); dom_node_unref(child); args.rval().setObject(*elem); return true; @@ -1387,7 +1388,7 @@ element_get_property_lastChild(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } - JSObject *elem = getElement(ctx, last_child); + JSObject *elem = getNode(ctx, last_child); dom_node_unref(last_child); args.rval().setObject(*elem); @@ -1469,7 +1470,7 @@ element_get_property_lastElementChild(JSContext *ctx, unsigned int argc, JS::Val if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { dom_nodelist_unref(nodes); - JSObject *elem = getElement(ctx, child); + JSObject *elem = getNode(ctx, child); dom_node_unref(child); args.rval().setObject(*elem); return true; @@ -1547,7 +1548,7 @@ element_get_property_nextElementSibling(JSContext *ctx, unsigned int argc, JS::V exc = dom_node_get_node_type(next, &type); if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { - JSObject *elem = getElement(ctx, next); + JSObject *elem = getNode(ctx, next); dom_node_unref(next); args.rval().setObject(*elem); return true; @@ -1852,7 +1853,7 @@ element_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value *v args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -2019,7 +2020,7 @@ element_get_property_offsetParent(JSContext *ctx, unsigned int argc, JS::Value * args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -2229,7 +2230,7 @@ element_get_property_parentElement(JSContext *ctx, unsigned int argc, JS::Value args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -2289,7 +2290,7 @@ element_get_property_parentNode(JSContext *ctx, unsigned int argc, JS::Value *vp args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -2361,7 +2362,7 @@ element_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, J exc = dom_node_get_node_type(prev, &type); if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { - JSObject *elem = getElement(ctx, prev); + JSObject *elem = getNode(ctx, prev); dom_node_unref(prev); args.rval().setObject(*elem); return true; @@ -2427,7 +2428,7 @@ element_get_property_previousSibling(JSContext *ctx, unsigned int argc, JS::Valu args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -4061,7 +4062,7 @@ element_appendChild(JSContext *ctx, unsigned int argc, JS::Value *rval) if (exc == DOM_NO_ERR && res) { interpreter->changed = 1; - JSObject *obj = getElement(ctx, res); + JSObject *obj = getNode(ctx, res); dom_node_unref(res); args.rval().setObject(*obj); debug_dump_xhtml(document->dom); @@ -4194,7 +4195,7 @@ element_cloneNode(JSContext *ctx, unsigned int argc, JS::Value *rval) args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, clone); + JSObject *obj = getNode(ctx, clone); dom_node_unref(clone); args.rval().setObject(*obj); @@ -4319,7 +4320,7 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); args.rval().setNull(); return true; } - JSObject *ret = getElement(ctx, res); + JSObject *ret = getNode(ctx, res); dom_node_unref(res); args.rval().setObject(*ret); @@ -4859,7 +4860,7 @@ element_insertBefore(JSContext *ctx, unsigned int argc, JS::Value *rval) if (err != DOM_NO_ERR || !spare) { return false; } - JSObject *obj = getElement(ctx, spare); + JSObject *obj = getNode(ctx, spare); dom_node_unref(spare); args.rval().setObject(*obj); interpreter->changed = 1; @@ -5048,7 +5049,7 @@ element_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp) if (!ret) { args.rval().setNull(); } else { - JSObject *el = getElement(ctx, ret); + JSObject *el = getNode(ctx, ret); dom_node_unref(ret); args.rval().setObject(*el); } @@ -5258,7 +5259,7 @@ element_removeChild(JSContext *ctx, unsigned int argc, JS::Value *rval) if (exc == DOM_NO_ERR && spare) { interpreter->changed = 1; - JSObject *obj = getElement(ctx, spare); + JSObject *obj = getNode(ctx, spare); dom_node_unref(spare); args.rval().setObject(*obj); debug_dump_xhtml(document->dom); diff --git a/src/js/spidermonkey/event.cpp b/src/js/spidermonkey/event.cpp index 516caba2f..c73e1567b 100644 --- a/src/js/spidermonkey/event.cpp +++ b/src/js/spidermonkey/event.cpp @@ -29,6 +29,7 @@ #include "js/spidermonkey/element.h" #include "js/spidermonkey/heartbeat.h" #include "js/spidermonkey/event.h" +#include "js/spidermonkey/node.h" #include "js/timer.h" #include "intl/libintl.h" #include "main/select.h" @@ -346,7 +347,7 @@ event_get_property_target(JSContext *ctx, unsigned int argc, JS::Value *vp) args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, target); + JSObject *obj = getNode(ctx, target); args.rval().setObject(*obj); dom_node_unref(target); diff --git a/src/js/spidermonkey/fragment.cpp b/src/js/spidermonkey/fragment.cpp index 0fce722bb..ebd5a1281 100644 --- a/src/js/spidermonkey/fragment.cpp +++ b/src/js/spidermonkey/fragment.cpp @@ -40,6 +40,7 @@ #include "js/spidermonkey/fragment.h" #include "js/spidermonkey/heartbeat.h" #include "js/spidermonkey/keyboard.h" +#include "js/spidermonkey/node.h" #include "js/spidermonkey/nodelist.h" #include "js/spidermonkey/nodelist2.h" #include "js/spidermonkey/style.h" @@ -421,7 +422,7 @@ fragment_get_property_firstChild(JSContext *ctx, unsigned int argc, JS::Value *v return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -504,7 +505,7 @@ fragment_get_property_firstElementChild(JSContext *ctx, unsigned int argc, JS::V if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { dom_nodelist_unref(nodes); - JSObject *elem = getElement(ctx, child); + JSObject *elem = getNode(ctx, child); dom_node_unref(child); args.rval().setObject(*elem); return true; @@ -572,7 +573,7 @@ fragment_get_property_lastChild(JSContext *ctx, unsigned int argc, JS::Value *vp return true; } - JSObject *elem = getElement(ctx, last_child); + JSObject *elem = getNode(ctx, last_child); dom_node_unref(last_child); args.rval().setObject(*elem); @@ -654,7 +655,7 @@ fragment_get_property_lastElementChild(JSContext *ctx, unsigned int argc, JS::Va if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { dom_nodelist_unref(nodes); - JSObject *elem = getElement(ctx, child); + JSObject *elem = getNode(ctx, child); dom_node_unref(child); args.rval().setObject(*elem); return true; @@ -733,7 +734,7 @@ fragment_get_property_nextElementSibling(JSContext *ctx, unsigned int argc, JS:: exc = dom_node_get_node_type(next, &type); if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { - JSObject *elem = getElement(ctx, next); + JSObject *elem = getNode(ctx, next); dom_node_unref(next); args.rval().setObject(*elem); return true; @@ -1039,7 +1040,7 @@ fragment_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value * args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -1142,7 +1143,7 @@ fragment_get_property_parentElement(JSContext *ctx, unsigned int argc, JS::Value args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -1202,7 +1203,7 @@ fragment_get_property_parentNode(JSContext *ctx, unsigned int argc, JS::Value *v args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -1275,7 +1276,7 @@ fragment_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, exc = dom_node_get_node_type(prev, &type); if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { - JSObject *elem = getElement(ctx, prev); + JSObject *elem = getNode(ctx, prev); dom_node_unref(prev); args.rval().setObject(*elem); return true; @@ -1342,7 +1343,7 @@ fragment_get_property_previousSibling(JSContext *ctx, unsigned int argc, JS::Val args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -1729,7 +1730,7 @@ fragment_appendChild(JSContext *ctx, unsigned int argc, JS::Value *rval) if (exc == DOM_NO_ERR && res) { interpreter->changed = 1; - JSObject *obj = getElement(ctx, res); + JSObject *obj = getNode(ctx, res); dom_node_unref(res); args.rval().setObject(*obj); debug_dump_xhtml(document->dom); @@ -1779,7 +1780,7 @@ fragment_cloneNode(JSContext *ctx, unsigned int argc, JS::Value *rval) args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, clone); + JSObject *obj = getNode(ctx, clone); dom_node_unref(clone); args.rval().setObject(*obj); @@ -1970,7 +1971,7 @@ fragment_insertBefore(JSContext *ctx, unsigned int argc, JS::Value *rval) if (err != DOM_NO_ERR || !spare) { return false; } - JSObject *obj = getElement(ctx, spare); + JSObject *obj = getNode(ctx, spare); dom_node_unref(spare); args.rval().setObject(*obj); interpreter->changed = 1; @@ -2120,7 +2121,7 @@ fragment_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp) if (!ret) { args.rval().setNull(); } else { - JSObject *el = getElement(ctx, ret); + JSObject *el = getNode(ctx, ret); dom_node_unref(ret); args.rval().setObject(*el); } @@ -2228,7 +2229,7 @@ fragment_removeChild(JSContext *ctx, unsigned int argc, JS::Value *rval) if (exc == DOM_NO_ERR && spare) { interpreter->changed = 1; - JSObject *obj = getElement(ctx, spare); + JSObject *obj = getNode(ctx, spare); dom_node_unref(spare); args.rval().setObject(*obj); debug_dump_xhtml(document->dom); diff --git a/src/js/spidermonkey/keyboard.cpp b/src/js/spidermonkey/keyboard.cpp index 2e1c0fd6d..9021d4ca3 100644 --- a/src/js/spidermonkey/keyboard.cpp +++ b/src/js/spidermonkey/keyboard.cpp @@ -32,6 +32,7 @@ #include "js/spidermonkey/element.h" #include "js/spidermonkey/heartbeat.h" #include "js/spidermonkey/keyboard.h" +#include "js/spidermonkey/node.h" #include "js/timer.h" #include "intl/libintl.h" #include "main/select.h" @@ -451,7 +452,7 @@ keyboardEvent_get_property_target(JSContext *ctx, unsigned int argc, JS::Value * args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, target); + JSObject *obj = getNode(ctx, target); args.rval().setObject(*obj); dom_node_unref(target); diff --git a/src/js/spidermonkey/nodelist.cpp b/src/js/spidermonkey/nodelist.cpp index ee0d6bdeb..bc58e63eb 100644 --- a/src/js/spidermonkey/nodelist.cpp +++ b/src/js/spidermonkey/nodelist.cpp @@ -26,6 +26,7 @@ #include "document/view.h" #include "js/ecmascript.h" #include "js/spidermonkey/element.h" +#include "js/spidermonkey/node.h" #include "js/spidermonkey/nodelist.h" #include "js/spidermonkey/window.h" #include "intl/libintl.h" @@ -208,7 +209,7 @@ nodeList_item2(JSContext *ctx, JS::HandleObject hobj, int idx, JS::MutableHandle if (err != DOM_NO_ERR || !element) { return true; } - JSObject *obj = getElement(ctx, element); + JSObject *obj = getNode(ctx, element); hvp.setObject(*obj); dom_node_unref(element); @@ -259,7 +260,7 @@ nodeList_set_items(JSContext *ctx, JS::HandleObject hobj, void *node) if (err != DOM_NO_ERR || !element) { continue; } - JSObject *obj = getElement(ctx, element); + JSObject *obj = getNode(ctx, element); if (obj) { JS::RootedObject v(ctx, obj); diff --git a/src/js/spidermonkey/nodelist2.cpp b/src/js/spidermonkey/nodelist2.cpp index 358ea5c4a..a498e9d80 100644 --- a/src/js/spidermonkey/nodelist2.cpp +++ b/src/js/spidermonkey/nodelist2.cpp @@ -27,6 +27,7 @@ #include "js/ecmascript.h" #include "js/ecmascript-c.h" #include "js/spidermonkey/element.h" +#include "js/spidermonkey/node.h" #include "js/spidermonkey/nodelist2.h" #include "js/spidermonkey/window.h" #include "intl/libintl.h" @@ -156,7 +157,7 @@ nodeList2_item(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } - JSObject *res = getElement(ctx, sn->node); + JSObject *res = getNode(ctx, sn->node); args.rval().setObject(*res); return true; } @@ -182,7 +183,7 @@ getNodeList2(JSContext *ctx, void *res) int i = 0; foreach (sn, *sni) { - JSObject *obj = getElement(ctx, sn->node); + JSObject *obj = getNode(ctx, sn->node); if (obj) { JS::RootedObject v(ctx, obj); diff --git a/src/js/spidermonkey/text.cpp b/src/js/spidermonkey/text.cpp index ce51d1c49..3eb65c67f 100644 --- a/src/js/spidermonkey/text.cpp +++ b/src/js/spidermonkey/text.cpp @@ -39,6 +39,7 @@ #include "js/spidermonkey/element.h" #include "js/spidermonkey/heartbeat.h" #include "js/spidermonkey/keyboard.h" +#include "js/spidermonkey/node.h" #include "js/spidermonkey/nodelist.h" #include "js/spidermonkey/nodelist2.h" #include "js/spidermonkey/style.h" @@ -88,6 +89,8 @@ static bool text_get_property_parentElement(JSContext *ctx, unsigned int argc, J static bool text_get_property_parentNode(JSContext *ctx, unsigned int argc, JS::Value *vp); //static bool text_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool text_get_property_previousSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); +static bool text_get_property_tagName(JSContext *ctx, unsigned int argc, JS::Value *vp); + static bool text_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool text_set_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *vp); @@ -147,6 +150,7 @@ JSPropertySpec text_props[] = { JS_PSG("parentNode", text_get_property_parentNode, JSPROP_ENUMERATE), //// JS_PSG("previousElementSibling", text_get_property_previousElementSibling, JSPROP_ENUMERATE), JS_PSG("previousSibling", text_get_property_previousSibling, JSPROP_ENUMERATE), + JS_PSG("tagName", text_get_property_tagName, JSPROP_ENUMERATE), JS_PSGS("textContent", text_get_property_textContent, text_set_property_textContent, JSPROP_ENUMERATE), JS_PS_END }; @@ -421,7 +425,7 @@ text_get_property_firstChild(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -504,7 +508,7 @@ text_get_property_firstElementChild(JSContext *ctx, unsigned int argc, JS::Value if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { dom_nodelist_unref(nodes); - JSObject *elem = getElement(ctx, child); + JSObject *elem = getNode(ctx, child); dom_node_unref(child); args.rval().setObject(*elem); return true; @@ -572,7 +576,7 @@ text_get_property_lastChild(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } - JSObject *elem = getElement(ctx, last_child); + JSObject *elem = getNode(ctx, last_child); dom_node_unref(last_child); args.rval().setObject(*elem); @@ -654,7 +658,7 @@ text_get_property_lastElementChild(JSContext *ctx, unsigned int argc, JS::Value if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { dom_nodelist_unref(nodes); - JSObject *elem = getElement(ctx, child); + JSObject *elem = getNode(ctx, child); dom_node_unref(child); args.rval().setObject(*elem); return true; @@ -733,7 +737,7 @@ text_get_property_nextElementSibling(JSContext *ctx, unsigned int argc, JS::Valu exc = dom_node_get_node_type(next, &type); if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { - JSObject *elem = getElement(ctx, next); + JSObject *elem = getNode(ctx, next); dom_node_unref(next); args.rval().setObject(*elem); return true; @@ -1039,7 +1043,7 @@ text_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value *vp) args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -1142,7 +1146,7 @@ text_get_property_parentElement(JSContext *ctx, unsigned int argc, JS::Value *vp args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -1202,7 +1206,7 @@ text_get_property_parentNode(JSContext *ctx, unsigned int argc, JS::Value *vp) args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); @@ -1275,7 +1279,7 @@ text_get_property_previousElementSibling(JSContext *ctx, unsigned int argc, JS:: exc = dom_node_get_node_type(prev, &type); if (exc == DOM_NO_ERR && type == DOM_ELEMENT_NODE) { - JSObject *elem = getElement(ctx, prev); + JSObject *elem = getNode(ctx, prev); dom_node_unref(prev); args.rval().setObject(*elem); return true; @@ -1342,13 +1346,71 @@ text_get_property_previousSibling(JSContext *ctx, unsigned int argc, JS::Value * args.rval().setNull(); return true; } - JSObject *elem = getElement(ctx, node); + JSObject *elem = getNode(ctx, node); dom_node_unref(node); args.rval().setObject(*elem); return true; } +static bool +text_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, &text_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; +} + static bool text_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *vp) { @@ -1729,7 +1791,7 @@ text_appendChild(JSContext *ctx, unsigned int argc, JS::Value *rval) if (exc == DOM_NO_ERR && res) { interpreter->changed = 1; - JSObject *obj = getElement(ctx, res); + JSObject *obj = getNode(ctx, res); dom_node_unref(res); args.rval().setObject(*obj); debug_dump_xhtml(document->dom); @@ -1779,7 +1841,7 @@ text_cloneNode(JSContext *ctx, unsigned int argc, JS::Value *rval) args.rval().setNull(); return true; } - JSObject *obj = getElement(ctx, clone); + JSObject *obj = getNode(ctx, clone); dom_node_unref(clone); args.rval().setObject(*obj); @@ -1970,7 +2032,7 @@ text_insertBefore(JSContext *ctx, unsigned int argc, JS::Value *rval) if (err != DOM_NO_ERR || !spare) { return false; } - JSObject *obj = getElement(ctx, spare); + JSObject *obj = getNode(ctx, spare); dom_node_unref(spare); args.rval().setObject(*obj); interpreter->changed = 1; @@ -2120,7 +2182,7 @@ text_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp) if (!ret) { args.rval().setNull(); } else { - JSObject *el = getElement(ctx, ret); + JSObject *el = getNode(ctx, ret); dom_node_unref(ret); args.rval().setObject(*el); } @@ -2228,7 +2290,7 @@ text_removeChild(JSContext *ctx, unsigned int argc, JS::Value *rval) if (exc == DOM_NO_ERR && spare) { interpreter->changed = 1; - JSObject *obj = getElement(ctx, spare); + JSObject *obj = getNode(ctx, spare); dom_node_unref(spare); args.rval().setObject(*obj); debug_dump_xhtml(document->dom);