1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-26 01:15:37 +00:00

[document] childNodes

This commit is contained in:
Witold Filipczyk 2021-09-17 19:18:07 +02:00
parent d5bc97e7f9
commit da7ed8f90b
2 changed files with 74 additions and 1 deletions

View File

@ -361,6 +361,79 @@ document_get_property_charset(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
static bool
document_get_property_childNodes(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 = 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, &document_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;
}
struct document *document = vs->doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
}
xmlpp::Document *docu = (xmlpp::Document *)document->dom;
xmlpp::Element* root = (xmlpp::Element *)docu->get_root_node();
if (!root) {
args.rval().setNull();
return true;
}
xmlpp::Node::NodeList *nodes = new xmlpp::Node::NodeList;
*nodes = root->get_children();
if (nodes->empty()) {
delete nodes;
args.rval().setNull();
return true;
}
JSObject *elem = getNodeList(ctx, nodes);
args.rval().setObject(*elem);
return true;
}
static bool
document_get_property_doctype(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
@ -1157,6 +1230,7 @@ JSPropertySpec document_props[] = {
JS_PSG("charset", document_get_property_charset, JSPROP_ENUMERATE),
JS_PSG("characterSet", document_get_property_charset, JSPROP_ENUMERATE),
JS_PSG("childNodes", document_get_property_childNodes, JSPROP_ENUMERATE),
JS_PSG("doctype", document_get_property_doctype, JSPROP_ENUMERATE),
JS_PSG("documentElement", document_get_property_documentElement, JSPROP_ENUMERATE),
JS_PSG("documentURI", document_get_property_documentURI, JSPROP_ENUMERATE),

View File

@ -396,7 +396,6 @@ element_get_property_childNodes(JSContext *ctx, unsigned int argc, JS::Value *vp
return true;
}
static bool
element_get_property_className(JSContext *ctx, unsigned int argc, JS::Value *vp)
{