Bug 1276240 - Ignore typeExtension argument if the value is null or undefined. r=smaug
MozReview-Commit-ID: 4ZeySrIpgFr
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4768,17 +4768,19 @@ nsDocument::SetScriptGlobalObject(nsIScr
#endif
bool allowDNSPrefetch;
docShell->GetAllowDNSPrefetch(&allowDNSPrefetch);
mAllowDNSPrefetch = allowDNSPrefetch;
}
}
MaybeRescheduleAnimationFrameNotifications();
- mRegistry = new Registry();
+ if (Preferences::GetBool("dom.webcomponents.enabled")) {
+ mRegistry = new Registry();
+ }
}
// Remember the pointer to our window (or lack there of), to avoid
// having to QI every time it's asked for.
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mScriptGlobalObject);
mWindow = window;
// Now that we know what our window is, we can flush the CSP errors to the
@@ -5664,18 +5666,20 @@ nsDocument::CreateElement(const nsAStrin
const nsAString& aTypeExtension,
ErrorResult& rv)
{
RefPtr<Element> elem = nsIDocument::CreateElement(aTagName, rv);
if (rv.Failed()) {
return nullptr;
}
- if (!aTagName.Equals(aTypeExtension)) {
- // Custom element type can not extend itself.
+ if (!aTypeExtension.IsVoid() &&
+ !aTagName.Equals(aTypeExtension)) {
+ // do not process 'is' if it is null or the extended type is the same as
+ // the localName
SetupCustomElement(elem, GetDefaultNamespaceID(), &aTypeExtension);
}
return elem.forget();
}
NS_IMETHODIMP
nsDocument::CreateElementNS(const nsAString& aNamespaceURI,
@@ -5722,29 +5726,33 @@ nsDocument::CreateElementNS(const nsAStr
{
RefPtr<Element> elem = nsIDocument::CreateElementNS(aNamespaceURI,
aQualifiedName,
rv);
if (rv.Failed()) {
return nullptr;
}
+ if (aTypeExtension.IsVoid() ||
+ aQualifiedName.Equals(aTypeExtension)) {
+ // do not process 'is' if it is null or the extended type is the same as
+ // the localName
+ return elem.forget();
+ }
+
int32_t nameSpaceId = kNameSpaceID_Wildcard;
if (!aNamespaceURI.EqualsLiteral("*")) {
rv = nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
nameSpaceId);
if (rv.Failed()) {
return nullptr;
}
}
- if (!aQualifiedName.Equals(aTypeExtension)) {
- // A custom element type can not extend itself.
- SetupCustomElement(elem, nameSpaceId, &aTypeExtension);
- }
+ SetupCustomElement(elem, nameSpaceId, &aTypeExtension);
return elem.forget();
}
NS_IMETHODIMP
nsDocument::CreateTextNode(const nsAString& aData, nsIDOMText** aReturn)
{
*aReturn = nsIDocument::CreateTextNode(aData).take();
--- a/dom/tests/mochitest/webcomponents/mochitest.ini
+++ b/dom/tests/mochitest/webcomponents/mochitest.ini
@@ -1,15 +1,16 @@
[DEFAULT]
support-files =
inert_style.css
[test_bug900724.html]
[test_bug1017896.html]
[test_bug1176757.html]
+[test_bug1276240.html]
[test_content_element.html]
[test_custom_element_adopt_callbacks.html]
[test_custom_element_callback_innerhtml.html]
[test_custom_element_clone_callbacks.html]
[test_custom_element_clone_callbacks_extended.html]
[test_custom_element_import_node_created_callback.html]
[test_custom_element_in_shadow.html]
[test_nested_content_element.html]
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/webcomponents/test_bug1276240.html
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1276240
+-->
+<head>
+ <title>Test for Bug 1276240</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank"
+ href="https://bugzilla.mozilla.org/show_bug.cgi?id=1276240">Mozilla Bug 1276240</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 1276240 **/
+// when passing null for the second argument, it would be ignored
+
+function test() {
+ var e = document.createElement("p", null);
+ is(e.getAttribute("is"), null);
+
+ e = document.createElement("p", undefined);
+ is(e.getAttribute("is"), null);
+
+ e = document.createElementNS("http://www.w3.org/1999/xhtml", "p", null);
+ is(e.getAttribute("is"), null);
+
+ e = document.createElementNS("http://www.w3.org/1999/xhtml", "p", undefined);
+ is(e.getAttribute("is"), null);
+}
+
+function runTest() {
+ test();
+ SimpleTest.finish();
+}
+
+// test with webcomponents enabled
+test();
+
+// test with webcomponents disabled
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv(
+ { 'set': [["dom.webcomponents.enabled", false]]}, runTest);
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -258,19 +258,19 @@ partial interface Document {
partial interface Document {
[Throws, Func="nsDocument::IsWebComponentsEnabled"]
object registerElement(DOMString name, optional ElementRegistrationOptions options);
};
//http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#dfn-document-register
partial interface Document {
[NewObject, Throws]
- Element createElement(DOMString localName, DOMString typeExtension);
+ Element createElement(DOMString localName, DOMString? typeExtension);
[NewObject, Throws]
- Element createElementNS(DOMString? namespace, DOMString qualifiedName, DOMString typeExtension);
+ Element createElementNS(DOMString? namespace, DOMString qualifiedName, DOMString? typeExtension);
};
// http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html#sec-document-interface
partial interface Document {
readonly attribute boolean hidden;
readonly attribute boolean mozHidden;
readonly attribute VisibilityState visibilityState;
readonly attribute VisibilityState mozVisibilityState;