Skip to content
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

Clarify what Document constructor does? #137

Closed
Wes0617 opened this issue Dec 28, 2015 · 4 comments
Closed

Clarify what Document constructor does? #137

Wes0617 opened this issue Dec 28, 2015 · 4 comments

Comments

@Wes0617
Copy link
Contributor

Wes0617 commented Dec 28, 2015

Hi everyone and merry xmas!
What is supposed to do the Document constructor? (I'm likely failing at understanding)

The Document() constructor must return a new document whose origin is an alias to the origin of the global object’s associated document, and effective script origin is an alias to the effective script origin of the global object’s associated document. [HTML]
Unlike createDocument() this constructor does not return an XMLDocument object, but a document (Document object).

If it's not a XMLDocument, is it an HTML Document, then? Or is it an xml document which was just constructed differently? (XMLDocument doesn't add members to the interface)
basically, what are its "type" and "mode" properties set to, since the constructor doesn't have parameters?

The HTML spec adds functionality to Document but it contains members that are only suited to HTML Documents.
Also, in the HTML spec window.HTMLDocument is just an alias for window.Document, but all UAs have an actual HTMLDocument class (as in DOM2, with the exception of MSIE9, which only has Document. Newer MS browsers all have HTMLDocument : Document)

Thank you in advance.

@ArkadiuszMichalski
Copy link
Contributor

Now it's clear, constructor Document() return new Document object (it's still XML document so internal state is "xml", what is default value and we don't need to mention about this). Remember that document has default value for its internal state and if they are not change (when we construct this document) then DOM (or other spec) don't need mention about it every time (https://dom.spec.whatwg.org/#concept-document-base-url). Firefox supports this constructor in correct way: https://bugzilla.mozilla.org/show_bug.cgi?id=1017932

HTML spec (and some other spec) add next stuff for Document interface and they are available for all documents (HTML/XHTML/XML) but it doesn't mean you can use all of them in all documents without any problem. Please try analize document.write method (https://html.spec.whatwg.org/multipage/webappapis.html#dom-document-write) , when you invoke this method in XML document then you get error (step 1.), but this method still exist in Document object.

What actually interfaces are returned by the browsers when we using various constructing methods is known bug (still under consideration in which direction to go further with this):
https://www.w3.org/Bugs/Public/show_bug.cgi?id=22960 << W3C bug
https://www.w3.org/Bugs/Public/show_bug.cgi?id=22960#c5 << Chrome started to do something in this direction but it is still a long road to full compliance with the all specifications.
https://bugzilla.mozilla.org/show_bug.cgi?id=897815 << Gecko bug

@Wes0617
Copy link
Contributor Author

Wes0617 commented Dec 29, 2015

Thank you very much for the links. I didn't entirely understood the reasoning behind the change, though. Why was unifying the interfaces necessary?

@ArkadiuszMichalski
Copy link
Contributor

Because, due to HTM5, we can use SVG and MathML in X(HT)ML and vice versa, so therefore there is no need to maintain separate SVGDocument and MathMLDocument interface. We can leave only Document with some limitation for different commands (if necessary). In theory this should simplify the further development of specifications, but practice will show if browses will go in this direction. There are other concerns that need to be addressed:
https://lists.w3.org/Archives/Public/public-whatwg-archive/2013Mar/0031.html

XMLDocument still exist because compatibility reason, although in future it may disappear:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=14037
https://bugzilla.mozilla.org/show_bug.cgi?id=983090

@annevk
Copy link
Member

annevk commented Jan 1, 2016

As @ArkadiuszMichalski explained these are all the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants