1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[quickjs] element.matches

TODO forEach
This commit is contained in:
Witold Filipczyk 2024-05-06 21:07:27 +02:00
parent 7c9c3f83bf
commit 3406220379
2 changed files with 12 additions and 31 deletions

View File

@ -2787,44 +2787,25 @@ js_element_matches(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif #endif
REF_JS(this_val); REF_JS(this_val);
// TODO
#if 0
if (argc != 1) { if (argc != 1) {
return JS_UNDEFINED; return JS_UNDEFINED;
} }
xmlpp::Element *el = static_cast<xmlpp::Element *>(js_getopaque(this_val, js_element_class_id)); dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id));
if (!el) { if (!el) {
return JS_FALSE; return JS_FALSE;
} }
const char *str; const char *selector;
size_t len; size_t len;
str = JS_ToCStringLen(ctx, &len, argv[0]); selector = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) { if (!selector) {
return JS_EXCEPTION;
}
xmlpp::ustring css = str;
xmlpp::ustring xpath = css2xpath(css);
JS_FreeCString(ctx, str);
xmlpp::Node::NodeSet elements;
try {
elements = el->find(xpath);
} catch (xmlpp::exception &e) {
return JS_FALSE; return JS_FALSE;
} }
void *res = el_match_selector(selector, el);
JS_FreeCString(ctx, selector);
for (auto node: elements) { return JS_NewBool(ctx, res);
if (node == el) {
return JS_TRUE;
}
}
#endif
return JS_FALSE;
} }
static JSValue static JSValue

View File

@ -21,11 +21,11 @@ console.error('element.matches');
birds = document.querySelectorAll('li'); birds = document.querySelectorAll('li');
ch = false; ch = false;
var counter = 0; // var counter = 0;
birds.forEach(function(b) { // birds.forEach(function(b) {
counter++; // counter++;
}); // });
console.assert(counter === 3, 'Three'); // console.assert(counter === 3, 'Three');
console.exit(0); console.exit(0);