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

[js] publicId

This commit is contained in:
Witold Filipczyk 2021-05-27 16:16:10 +02:00
parent d6df9584c9
commit 8b2ef1ef45
2 changed files with 54 additions and 0 deletions

View File

@ -1561,6 +1561,38 @@ doctype_get_property_name(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
static bool
doctype_get_property_publicId(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
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, &doctype_class, NULL))
return false;
xmlpp::Dtd *dtd = JS_GetPrivate(hobj);
if (!dtd) {
args.rval().setNull();
return true;
}
std::string v = dtd->get_external_id();
args.rval().setString(JS_NewStringCopyZ(ctx, v.c_str()));
return true;
}
static bool
doctype_get_property_systemId(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
@ -1595,6 +1627,7 @@ doctype_get_property_systemId(JSContext *ctx, unsigned int argc, JS::Value *vp)
JSPropertySpec doctype_props[] = {
JS_PSG("name", doctype_get_property_name, JSPROP_ENUMERATE),
JS_PSG("publicId", doctype_get_property_publicId, JSPROP_ENUMERATE),
JS_PSG("systemId", doctype_get_property_systemId, JSPROP_ENUMERATE),
JS_PS_END
};

View File

@ -0,0 +1,21 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<body>
<p>Click the button to display the doctype systemId of the document.</p>
<button onclick="myFunction()">Try it</button>
<p><strong>Note:</strong> In Internet Explorer 8 and earlier, the doctype property returns <em>null</em> for HTML and XHTML documents, and will only work for XML documents.</p>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.doctype.publicId;
alert(x);
}
</script>
</body>
</html>