1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

[js] document.documentURI

This commit is contained in:
Witold Filipczyk 2021-05-25 15:58:15 +02:00
parent ed8bff2b82
commit 9a0b89e189
2 changed files with 54 additions and 0 deletions

View File

@ -343,6 +343,44 @@ document_get_property_documentElement(JSContext *ctx, unsigned int argc, JS::Val
return true;
}
static bool
document_get_property_documentURI(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct view_state *vs;
JSCompartment *comp = js::GetContextCompartment(ctx);
if (!comp) {
return false;
}
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(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))
return false;
vs = interpreter->vs;
if (!vs) {
return false;
}
char *str = get_uri_string(vs->uri, URI_BASE);
if (!str) {
return false;
}
args.rval().setString(JS_NewStringCopyZ(ctx, str));
mem_free(str);
return true;
}
static bool
document_get_property_domain(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
@ -886,6 +924,7 @@ JSPropertySpec document_props[] = {
JS_PSG("charset", document_get_property_charset, JSPROP_ENUMERATE),
JS_PSG("characterSet", document_get_property_charset, JSPROP_ENUMERATE),
JS_PSG("documentElement", document_get_property_documentElement, JSPROP_ENUMERATE),
JS_PSG("documentURI", document_get_property_documentURI, JSPROP_ENUMERATE),
JS_PSG("domain", document_get_property_domain, JSPROP_ENUMERATE),
JS_PSG("forms", document_get_property_forms, JSPROP_ENUMERATE),
JS_PSG("head", document_get_property_head, JSPROP_ENUMERATE),

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the location of this document</p>
<p><strong>Note:</strong> Internet Explorer does not support the documentURI property.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.documentURI;
alert(x);
}
</script>
</body>
</html>