Commit a695888f authored by rob.buis's avatar rob.buis Committed by Commit bot

Update createContextualFragment behavior to latest spec

Update createContextualFragment behavior to latest spec listed under [1].
This means specifically we do not throw an exception when the context node is
not HTML or SVG and if initially the context element is null, we follow step 2
to create an appropriate context element to be used in step 3.

Behavior matches Firefox and Safari.

BUG=616760

[1] https://w3c.github.io/DOM-Parsing/#extensions-to-the-range-interface

Review-Url: https://codereview.chromium.org/2356373002
Cr-Commit-Position: refs/heads/master@{#420573}
parent 74afbf8b
...@@ -19,5 +19,5 @@ try { ...@@ -19,5 +19,5 @@ try {
} }
var result = document.getElementById('result'); var result = document.getElementById('result');
result.textContent = (thrownException && thrownException.message === "Failed to execute 'createContextualFragment' on 'Range': The range's container must be an HTML or SVG Element, Document, or DocumentFragment.") ? 'PASS' : 'FAIL'; result.textContent = thrownException ? 'FAIL' : 'PASS';
</script> </script>
...@@ -19,5 +19,5 @@ try { ...@@ -19,5 +19,5 @@ try {
} }
var result = document.getElementById('result'); var result = document.getElementById('result');
result.textContent = (thrownException && thrownException.message === "Failed to execute 'createContextualFragment' on 'Range': The range's container must be an HTML or SVG Element, Document, or DocumentFragment.") ? 'PASS' : 'FAIL'; result.textContent = thrownException ? 'FAIL' : 'PASS';
</script> </script>
...@@ -884,29 +884,20 @@ DocumentFragment* Range::createContextualFragment(const String& markup, Exceptio ...@@ -884,29 +884,20 @@ DocumentFragment* Range::createContextualFragment(const String& markup, Exceptio
if (!element || isHTMLHtmlElement(element)) { if (!element || isHTMLHtmlElement(element)) {
Document& document = node->document(); Document& document = node->document();
if (document.isHTMLDocument() || document.isXHTMLDocument()) { if (document.isSVGDocument()) {
element = document.documentElement();
if (!element)
element = SVGSVGElement::create(document);
} else {
// Optimization over spec: try to reuse the existing <body> element, if it is available. // Optimization over spec: try to reuse the existing <body> element, if it is available.
element = document.body(); element = document.body();
if (!element) if (!element)
element = HTMLBodyElement::create(document); element = HTMLBodyElement::create(document);
} else if (document.isSVGDocument()) {
element = document.documentElement();
if (!element)
element = SVGSVGElement::create(document);
} }
} }
if (!element || (!element->isHTMLElement() && !element->isSVGElement())) {
exceptionState.throwDOMException(NotSupportedError, "The range's container must be an HTML or SVG Element, Document, or DocumentFragment.");
return nullptr;
}
// Steps 3, 4, 5. // Steps 3, 4, 5.
DocumentFragment* fragment = blink::createContextualFragment(markup, element, AllowScriptingContentAndDoNotMarkAlreadyStarted, exceptionState); return blink::createContextualFragment(markup, element, AllowScriptingContentAndDoNotMarkAlreadyStarted, exceptionState);
if (!fragment)
return nullptr;
return fragment;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment