Re: [webcomponents] Change registries to be per document and never shared between documents (#369)

I definitely don't want option 3.  Magical implicit relationships like that are hard to understand and will authors in edge cases; e.g. imagine script calling into a library which creates a window-less document and calls defineElement on it, and the caller 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:

<ol start=4>
 <li>Add an optional document argument to custom elements constructor and `HTMLElement` constructor. UA will always specify this argument when creating an element inside DOM APIs or in the parser, and verifies that the element returned by the constructor is indeed owned by the specified document.  `HTMLElement` constructor will fallback to use the document associated with the global object if document is not specified in the first arguemnt.</li>
</ol>

This will allow `new MyCustomElement` (without arguments) but effectively forces authors to pass in the arguments in the custom elements constructor.  If they forget, custom elements don't work in window-less documents but those authors probably won't call `defineElement` on those documents in the first place.

---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/369#issuecomment-191891637

Received on Thursday, 3 March 2016 18:12:48 UTC