Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow custom elements inside a window-less documents https://bugs.webkit.org/show_bug.cgi?id=154944 <rdar://problem/24944875> Reviewed by Antti Koivisto. Disallow custom elements inside a window-less documents such as the shared inert document of template elements and the ones created by DOMImplementation.createDocument and DOMImplementation.createHTMLDocument. Throw NotSupportedError in defineCustomElement when it's called in such a document as discussed in: WICG/webcomponents#369 Tests: fast/custom-elements/parser/parser-constructs-custom-element-in-document-write.html fast/custom-elements/parser/parser-uses-registry-of-owner-document.html * bindings/js/JSDOMBinding.cpp: (WebCore::throwNotSupportedError): Added. * bindings/js/JSDOMBinding.h: * bindings/js/JSDocumentCustom.cpp: (WebCore::JSDocument::defineCustomElement): Throw NotSupportedError when the context object's document doesn't have a browsing context (i.e. window-less). * html/parser/HTMLDocumentParser.cpp: (WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder): Replaced a FIXME with an assertion now that we disallow instantiation of custom elements inside a template element. LayoutTests: Disallow custom elements inside template elements and share the registry for windowless documents https://bugs.webkit.org/show_bug.cgi?id=154944 <rdar://problem/24944875> Reviewed by Antti Koivisto. Added various tests to ensure the custom elements registry is not shared between documents with distinct browsing context (e.g. iframes) but shared among the ones that share a single browsing context (e.g. documents created by DOMImplementation). Also added a test case for defineCustomElement to ensure it throws NotSupportedError when it's called on a template element's inert owner document as well as a basic test case for document.write. * fast/custom-elements/Document-defineCustomElement-expected.txt: * fast/custom-elements/Document-defineCustomElement.html: Added a new test case. * fast/custom-elements/parser/parser-constructs-custom-element-in-document-write-expected.txt: Added. * fast/custom-elements/parser/parser-constructs-custom-element-in-document-write.html: Added. * fast/custom-elements/parser/parser-uses-registry-of-owner-document-expected.txt: Added. * fast/custom-elements/parser/parser-uses-registry-of-owner-document.html: Added. Canonical link: https://commits.webkit.org/173073@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197528 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
13 changed files
with
237 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...st/custom-elements/parser/parser-constructs-custom-element-in-document-write-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
PASS HTML parser must instantiate custom elements inside document.write | ||
|
30 changes: 30 additions & 0 deletions
30
...Tests/fast/custom-elements/parser/parser-constructs-custom-element-in-document-write.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Custom Elements: Changes to the HTML parser</title> | ||
<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> | ||
<meta name="assert" content="HTML parser must construct custom elements inside document.write"> | ||
<script src="../../../resources/testharness.js"></script> | ||
<script src="../../../resources/testharnessreport.js"></script> | ||
<link rel='stylesheet' href='../../../resources/testharness.css'> | ||
</head> | ||
<body> | ||
<div id="log"></div> | ||
<script> | ||
|
||
class MyCustomElement extends HTMLElement { } | ||
document.defineCustomElement('my-custom-element', MyCustomElement); | ||
|
||
document.write('<my-custom-element></my-custom-element>'); | ||
|
||
test(function () { | ||
var instance = document.querySelector('my-custom-element'); | ||
|
||
assert_true(instance instanceof HTMLElement); | ||
assert_true(instance instanceof MyCustomElement); | ||
|
||
}, 'HTML parser must instantiate custom elements inside document.write'); | ||
|
||
</script> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
LayoutTests/fast/custom-elements/parser/parser-uses-registry-of-owner-document-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
PASS HTML parser must not instantiate custom elements inside template elements | ||
PASS HTML parser must not use the registry of the owner element's document inside an iframe | ||
PASS HTML parser must use the registry of the content document inside an iframe | ||
PASS HTML parser must not instantiate a custom element defined inside an frame in frame element's owner document | ||
PASS HTML parser must use the registry of window.document in a document created by document.implementation.createHTMLDocument() | ||
PASS HTML parser must use the registry of window.document in a document created by document.implementation.createXHTMLDocument() | ||
|
98 changes: 98 additions & 0 deletions
98
LayoutTests/fast/custom-elements/parser/parser-uses-registry-of-owner-document.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Custom Elements: Changes to the HTML parser</title> | ||
<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> | ||
<meta name="assert" content="HTML parser must use the owner document's custom element registry"> | ||
<script src="../../../resources/testharness.js"></script> | ||
<script src="../../../resources/testharnessreport.js"></script> | ||
<link rel='stylesheet' href='../../../resources/testharness.css'> | ||
</head> | ||
<body> | ||
<div id="log"></div> | ||
<script> | ||
|
||
class MyCustomElement extends HTMLElement { }; | ||
document.defineCustomElement('my-custom-element', MyCustomElement); | ||
|
||
document.write('<template><my-custom-element></my-custom-element></template>'); | ||
|
||
test(function () { | ||
var template = document.querySelector('template'); | ||
var instance = template.content.firstChild; | ||
|
||
assert_true(instance instanceof HTMLElement, | ||
'A custom element inside a template element must be an instance of HTMLElement'); | ||
assert_false(instance instanceof MyCustomElement, | ||
'A custom element must not be instantiated inside a template element using the registry of the template element\'s owner document'); | ||
assert_equals(instance.ownerDocument, template.content.ownerDocument, | ||
'Custom elements inside a template must use the appropriate template contents owner document as the owner document'); | ||
|
||
}, 'HTML parser must not instantiate custom elements inside template elements'); | ||
|
||
var iframe = document.createElement('iframe'); | ||
document.body.appendChild(iframe); | ||
iframe.contentDocument.body.innerHTML = '<my-custom-element></my-custom-element>'; | ||
|
||
test(function () { | ||
var instance = iframe.contentDocument.querySelector('my-custom-element'); | ||
|
||
assert_true(instance instanceof iframe.contentWindow.HTMLElement); | ||
assert_false(instance instanceof MyCustomElement); | ||
|
||
}, 'HTML parser must not use the registry of the owner element\'s document inside an iframe'); | ||
|
||
class ElementInIFrame extends iframe.contentWindow.HTMLElement { }; | ||
iframe.contentDocument.defineCustomElement('element-in-iframe', ElementInIFrame); | ||
iframe.contentDocument.body.innerHTML = '<element-in-iframe></element-in-iframe>'; | ||
|
||
test(function () { | ||
var instance = iframe.contentDocument.querySelector('element-in-iframe'); | ||
|
||
assert_true(instance instanceof iframe.contentWindow.HTMLElement, 'A custom element inside an iframe must be an instance of HTMLElement'); | ||
assert_true(instance instanceof ElementInIFrame, | ||
'A custom element must be instantiated inside an iframe using the registry of the content document'); | ||
assert_equals(instance.ownerDocument, iframe.contentDocument, | ||
'The owner document of custom elements inside an iframe must be the content document of the iframe'); | ||
|
||
}, 'HTML parser must use the registry of the content document inside an iframe'); | ||
|
||
document.write('<element-in-iframe></element-in-iframe>'); | ||
|
||
test(function () { | ||
var instance = document.querySelector('element-in-iframe'); | ||
|
||
assert_true(instance instanceof HTMLElement); | ||
assert_false(instance instanceof ElementInIFrame); | ||
|
||
}, 'HTML parser must not instantiate a custom element defined inside an frame in frame element\'s owner document'); | ||
|
||
document.body.removeChild(iframe); | ||
|
||
var windowlessDocument = document.implementation.createHTMLDocument(); | ||
windowlessDocument.open(); | ||
windowlessDocument.write('<my-custom-element></my-custom-element>'); | ||
windowlessDocument.close(); | ||
|
||
test(function () { | ||
var instance = windowlessDocument.querySelector('my-custom-element'); | ||
|
||
assert_true(instance instanceof HTMLElement); | ||
assert_false(instance instanceof MyCustomElement); | ||
|
||
}, 'HTML parser must use the registry of window.document in a document created by document.implementation.createHTMLDocument()'); | ||
|
||
windowlessDocument = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null); | ||
windowlessDocument.documentElement.innerHTML = '<my-custom-element></my-custom-element>'; | ||
|
||
test(function () { | ||
var instance = windowlessDocument.querySelector('my-custom-element'); | ||
|
||
assert_true(instance instanceof HTMLElement); | ||
assert_false(instance instanceof MyCustomElement); | ||
|
||
}, 'HTML parser must use the registry of window.document in a document created by document.implementation.createXHTMLDocument()'); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters