From 207534f3e0ccb0bc2438cf91da97fa55e399803b Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Wed, 26 May 2021 08:22:33 +0200 Subject: [PATCH] [js] doctype.systemId --- src/ecmascript/spidermonkey/document.c | 32 ++++++++++++++++++++++++++ test/ecmascript/systemId.html | 21 +++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/ecmascript/systemId.html diff --git a/src/ecmascript/spidermonkey/document.c b/src/ecmascript/spidermonkey/document.c index a508505ee..93c097908 100644 --- a/src/ecmascript/spidermonkey/document.c +++ b/src/ecmascript/spidermonkey/document.c @@ -1561,9 +1561,41 @@ doctype_get_property_name(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } +static bool +doctype_get_property_systemId(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_system_id(); + args.rval().setString(JS_NewStringCopyZ(ctx, v.c_str())); + + return true; +} JSPropertySpec doctype_props[] = { JS_PSG("name", doctype_get_property_name, JSPROP_ENUMERATE), + JS_PSG("systemId", doctype_get_property_systemId, JSPROP_ENUMERATE), JS_PS_END }; diff --git a/test/ecmascript/systemId.html b/test/ecmascript/systemId.html new file mode 100644 index 000000000..0e2936f2a --- /dev/null +++ b/test/ecmascript/systemId.html @@ -0,0 +1,21 @@ + + + + +

Click the button to display the doctype systemId of the document.

+ + + +

Note: In Internet Explorer 8 and earlier, the doctype property returns null for HTML and XHTML documents, and will only work for XML documents.

+ +

+ + + + +