-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change registries to be per document and never shared between documents #369
Comments
So in IRC @rniwa and I discovered this really doesn't work. You want basically one registry per window, not one registry per document, now that we have the constructor setup. The reason is basically that, when doing We could fix this in theory by mandating a That means either sharing the registry with the parent (per the current spec) or just saying that they have no registry (and disallowing defineElement in them too). Side note: we need to check how document.open() affects this since it creates a 1-document to many-windows mapping. |
Similarly, we can't make |
Upon sleeping on this I am amenable to a new alternative, which is a mandatory document parameter to all custom element constructors. So:
I am not OK with it defaulting to some specific document because it is ambiguous which document. We either:
WDYT? (1) or (2)? |
Note that we already have document defaulting in DOM, for Comment, Document, DocumentFragment, Text... |
And also for Image, Audio, others? |
Yeah, but you can't register custom text nodes in a variety of documents. It's always unambiguous when you do |
(Maybe a good way to implement (1) is to check that the passed constructor's realm's global object is equal to the context object's associated window. So |
I think I prefer 1. And we later figure out how you get custom elements to instantiate in documents not associated with a window object (if ever, obviously that's not a good idea for XMLHttpRequest's document, unless you can only do this action after you get a hold of the document). |
In IRC @jakearchibald mentioned a third alternative which has been floating around in my brain for a while:
|
I've yet to hit the multi-doc issue in practice because I've personally stayed in the proto definition/registration lane, but always wondered how one might deal with it. Glad to see it fleshed out in such thoughtful detail. Oh, and thank you for continually using "X-Tag" in your examples ;) |
I definitely don't want option 3. Magical implicit relationships like that are hard to understand and will bite authors in edge cases; e.g. imagine script calling into a library which creates a window-less document and calls defineElement on it, and then proceeds to construct an element in another document. Something like that WILL happen and it's not obvious at all as to why that didn't work as intended. I'm fine with either options 1 or 2. I'll add option 4:
This will allow |
Yeah, I was saying in #369 (comment) that I was not ok with (4). It should either be unambiguous or required. It sounds like we should go with (1). The remaining questions to me are:
The current spec shares the registry. If we want to continue with that, maybe we should move the registry to window instead of document... |
Yeah, I like making the registry per-realm, but we need to have something to enable its usage on a per-document level. |
Hmm, what do you mean by that? |
So |
So I guess putting on Window doesn't work actually if we want to share since createDocument() documents don't have any associated window. So let's keep it on document and create patches for createDocument() and createHTMLDocument() that hand out the registry to those. The current spec gives template a new empty registry but it seems like that's a bug per recent discussions and instead it should just have no registry so that defineElement() always fails there. (Same with XHR.) I will try to work on a PR for this today. It sounds like we have a rough plan which is best critiqued in concrete form. I might tackle #413 first since it's getting in the way. |
So it turns out that we can't share the registry in option 1 because |
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. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@197528 268f45cc-cd09-0410-ab3c-d52691b4dbfc
All documents (all platform objects, really) have an associated global object per IDL. Most don't have a browsing context, however, but nobody is proposing to put the registry there. @rniwa can you explain what the problem is with the initial node document being the document associated with the global object? |
@annevk : It would mean that custom element's constructor would see a wrong It's not a huge deal per se but it's yet another edge case author has to know / be aware of. We think it's better to disallow it altogether in the first place so that the behavior is consistent and easy to understand. |
@rniwa your custom element will have to be resilient against that anyway as I can easily imagine folks will construct it in A and insert it in B all the same. (It also matches what we do for |
@annevk what are use cases for custom elements in window-less document anyway? What do people use that for? Unless there are use cases for these documents, we would rather not support it. |
But maybe we are saying the same, since I think that by default, custom elements should only instantiate automatically in documents with a browsing context. And for v1 we should not go beyond that. The other thing I'm saying is that I don't see a reason not to associate the registry with a global and put the API there (although maybe it should be stored on that global's document due to window.open() and such). |
Please take a look at 58a2f7b which implements our consensus here, I believe. Output at the bottom of https://w3c.github.io/webcomponents/spec/custom/#concepts. |
I think I still favor a slightly different model:
That would also mean we keep the registry when you navigate an initial about:blank which I think is what we want. The I guess I can live with the current model, but this seems more logical. |
Sure, I was using window-less and "without a browsing context" synonymously ignoring those details. Your definition makes sense to me. |
@annevk one thing I prefer about the current model is that it's easy to define in DOM without having DOM define properties of the current realm or window, or knowing about browsing contexts. Instead DOM just says that a document has a registry, potentially null, and lets HTML set up a new registry when appropriate. Anything else seems to involve too much intertwingling.
I don't really agree. I think if you've added elements to the initial about:blank, for whatever reason, they should probably go away when you navigate. |
So you get to "define" all kinds of JavaScript objects there, but not elements? Note that the layering between DOM and HTML is already muddy. E.g., "get the parent" on documents returns the WindowProxy object. Mutation observers depend the "unit of related similar-origin browsing contexts", etc. It's hard to make concrete, but I think in the long run we'll find that we want the registry to be per realm since there's no way to scope these constructors to documents (other than if we made it a mandatory argument, which seems rather sad). I'm not a 100% on this though, it's a hunch. |
- Figured out where custom elements will go in HTML, and started writing as if they were there - Fleshed out and moved around examples and motivation to form an "introduction" section - Separated out and rearranged concepts a bit better (fixes #437) - Started the process of moving the registry to the browsing context instead of document (#369) - Moved to `window.customElements`, an instance of `CustomElementsRegistry`, with one `define` method currently (#431) Still to-do: - fix all broken links detected by respec; a few terms have changed - Look up registry on the browsing context instead of the document - Move custom element semantics into the "HTML+: Custom elements" section - Define a HTML+ patch that adds a `customElements` property to `Window`.
This should now be clearer: https://w3c.github.io/webcomponents/spec/custom/#custom-elements-api |
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
In particular, createDocument() and similar don't share registries with the parent.
The text was updated successfully, but these errors were encountered: