mirror of
https://github.com/rkd77/elinks.git
synced 2024-06-30 01:55:30 +00:00
[spidermonkey] element.querySelector
This commit is contained in:
parent
4a6b920586
commit
667167bd90
|
@ -28,6 +28,7 @@
|
||||||
#include "document/libdom/renderer2.h"
|
#include "document/libdom/renderer2.h"
|
||||||
#include "document/view.h"
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/ecmascript-c.h"
|
||||||
#include "ecmascript/spidermonkey/attr.h"
|
#include "ecmascript/spidermonkey/attr.h"
|
||||||
#include "ecmascript/spidermonkey/attributes.h"
|
#include "ecmascript/spidermonkey/attributes.h"
|
||||||
#include "ecmascript/spidermonkey/collection.h"
|
#include "ecmascript/spidermonkey/collection.h"
|
||||||
|
@ -4735,48 +4736,28 @@ element_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot<dom_node>(hobj, 0);
|
||||||
// TODO
|
|
||||||
#if 0
|
|
||||||
xmlpp::Element *el = JS::GetMaybePtrFromReservedSlot<xmlpp::Element>(hobj, 0);
|
|
||||||
|
|
||||||
if (!el) {
|
if (!el) {
|
||||||
args.rval().setBoolean(false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct string cssstr;
|
|
||||||
if (!init_string(&cssstr)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
jshandle_value_to_char_string(&cssstr, ctx, args[0]);
|
|
||||||
xmlpp::ustring css = cssstr.source;
|
|
||||||
xmlpp::ustring xpath = css2xpath(css);
|
|
||||||
done_string(&cssstr);
|
|
||||||
|
|
||||||
xmlpp::Node::NodeSet elements;
|
|
||||||
|
|
||||||
try {
|
|
||||||
elements = el->find(xpath);
|
|
||||||
} catch (xmlpp::exception &e) {
|
|
||||||
args.rval().setNull();
|
args.rval().setNull();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
char *selector = jsval_to_string(ctx, args[0]);
|
||||||
|
|
||||||
for (auto node: elements)
|
if (!selector) {
|
||||||
{
|
args.rval().setNull();
|
||||||
if (isAncestor(el, static_cast<xmlpp::Element *>(node)))
|
|
||||||
{
|
|
||||||
JSObject *elem = getElement(ctx, node);
|
|
||||||
|
|
||||||
if (elem) {
|
|
||||||
args.rval().setObject(*elem);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
void *ret = walk_tree_query(el, selector, 0);
|
||||||
}
|
mem_free(selector);
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
args.rval().setNull();
|
args.rval().setNull();
|
||||||
#endif
|
} else {
|
||||||
|
JSObject *el = getElement(ctx, ret);
|
||||||
|
args.rval().setObject(*el);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user