mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[js] document.scripts
This commit is contained in:
parent
35d7847808
commit
c71b0f2ee1
@ -533,6 +533,48 @@ document_get_property_referrer(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
document_get_property_scripts(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
JSCompartment *comp = js::GetContextCompartment(ctx);
|
||||
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(comp);
|
||||
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||
struct document *document = doc_view->document;
|
||||
|
||||
if (!document->dom) {
|
||||
document->dom = document_parse(document);
|
||||
}
|
||||
|
||||
if (!document->dom) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
xmlpp::Element* root = (xmlpp::Element *)document->dom;
|
||||
|
||||
std::string xpath = "//script";
|
||||
xmlpp::Node::NodeSet *elements = new xmlpp::Node::NodeSet;
|
||||
|
||||
*elements = root->find(xpath);
|
||||
|
||||
if (elements->size() == 0) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
JSObject *elem = getCollection(ctx, elements);
|
||||
|
||||
if (elem) {
|
||||
args.rval().setObject(*elem);
|
||||
} else {
|
||||
args.rval().setNull();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
document_get_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
@ -674,6 +716,7 @@ JSPropertySpec document_props[] = {
|
||||
JS_PSG("links", document_get_property_links, JSPROP_ENUMERATE),
|
||||
JS_PSGS("location", document_get_property_location, document_set_property_location, JSPROP_ENUMERATE),
|
||||
JS_PSG("referrer", document_get_property_referrer, JSPROP_ENUMERATE),
|
||||
JS_PSG("scripts", document_get_property_scripts, JSPROP_ENUMERATE),
|
||||
JS_PSGS("title", document_get_property_title, document_set_property_title, JSPROP_ENUMERATE), /* TODO: Charset? */
|
||||
JS_PSGS("url", document_get_property_url, document_set_property_url, JSPROP_ENUMERATE),
|
||||
JS_PS_END
|
||||
|
17
test/ecmascript/scripts.html
Normal file
17
test/ecmascript/scripts.html
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<button onclick="myFunction()">Try it</button>
|
||||
|
||||
<p id="demo"></p>
|
||||
|
||||
<script>
|
||||
function myFunction() {
|
||||
var x = document.scripts.length;
|
||||
alert(x);
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user