diff --git a/src/ecmascript/spidermonkey/element.c b/src/ecmascript/spidermonkey/element.c index a890b3d5..aa067307 100644 --- a/src/ecmascript/spidermonkey/element.c +++ b/src/ecmascript/spidermonkey/element.c @@ -71,6 +71,7 @@ static bool element_get_property_lastChild(JSContext *ctx, unsigned int argc, JS static bool element_get_property_lastElementChild(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool element_get_property_nextElementSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool element_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value *vp); +static bool element_get_property_nodeType(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool element_get_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool element_set_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool element_get_property_parentElement(JSContext *ctx, unsigned int argc, JS::Value *vp); @@ -109,6 +110,7 @@ JSPropertySpec element_props[] = { JS_PSG("lastElementChild", element_get_property_lastElementChild, JSPROP_ENUMERATE), JS_PSG("nextElementSibling", element_get_property_nextElementSibling, JSPROP_ENUMERATE), JS_PSG("nextSibling", element_get_property_nextSibling, JSPROP_ENUMERATE), + JS_PSG("nodeType", element_get_property_nodeType, JSPROP_ENUMERATE), JS_PSGS("outerHTML", element_get_property_outerHtml, element_set_property_outerHtml, JSPROP_ENUMERATE), JS_PSG("parentElement", element_get_property_parentElement, JSPROP_ENUMERATE), JS_PSG("parentNode", element_get_property_parentNode, JSPROP_ENUMERATE), @@ -622,6 +624,55 @@ element_get_property_nextElementSibling(JSContext *ctx, unsigned int argc, JS::V return true; } +static bool +element_get_property_nodeType(JSContext *ctx, unsigned int argc, JS::Value *vp) +{ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + + struct view_state *vs; + JSCompartment *comp = js::GetContextCompartment(ctx); + + if (!comp) { + return false; + } + + struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(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, &element_class, NULL)) + return false; + + vs = interpreter->vs; + if (!vs) { + return false; + } + + xmlpp::Node *node = JS_GetPrivate(hobj); + + if (!node) { + args.rval().setNull(); + return true; + } + + int ret = 8; + + if (dynamic_cast(node)) { + ret = 1; + } else if (dynamic_cast(node)) { + ret = 2; + } else if (dynamic_cast(node)) { + ret = 3; + } else if (dynamic_cast(node)) { + ret = 8; + } + args.rval().setInt32(ret); + + return true; +} + static bool element_get_property_nextSibling(JSContext *ctx, unsigned int argc, JS::Value *vp) { diff --git a/test/ecmascript/nodeType.html b/test/ecmascript/nodeType.html new file mode 100644 index 00000000..d56f463d --- /dev/null +++ b/test/ecmascript/nodeType.html @@ -0,0 +1,19 @@ + + + + +

Click the button to get the node type of this element.

+ + + +

+ + + + + \ No newline at end of file