mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] Fixes in querySelector
This commit is contained in:
parent
8ec96e4f90
commit
b9482dfbbf
@ -3021,6 +3021,19 @@ element_matches(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
isAncestor(xmlpp::Element *el, xmlpp::Element *node)
|
||||
{
|
||||
while (node) {
|
||||
if (el == node) {
|
||||
return true;
|
||||
}
|
||||
node = node->get_parent();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
element_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
@ -3065,20 +3078,19 @@ element_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (elements.size() == 0) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
auto node = elements[0];
|
||||
|
||||
JSObject *elem = getElement(ctx, node);
|
||||
|
||||
if (elem) {
|
||||
args.rval().setObject(*elem);
|
||||
} else {
|
||||
args.rval().setNull();
|
||||
for (auto node: elements)
|
||||
{
|
||||
if (isAncestor(el, node))
|
||||
{
|
||||
JSObject *elem = getElement(ctx, node);
|
||||
|
||||
if (elem) {
|
||||
args.rval().setObject(*elem);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
args.rval().setNull();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -3125,6 +3137,7 @@ element_querySelectorAll(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
} catch (xmlpp::exception) {
|
||||
}
|
||||
|
||||
elements->erase(std::remove_if(elements->begin(), elements->end(), [el](xmlpp::Node *node){return !isAncestor(el, node);}));
|
||||
JSObject *elem = getCollection(ctx, elements);
|
||||
|
||||
if (elem) {
|
||||
|
Loading…
Reference in New Issue
Block a user